在AMD GPU上测试程序时遇到问题。在Nvidia和Intel HD Graphics上进行测试时,一切正常。在AMD上,正是在尝试绑定纹理时才发生此问题。由于这个问题,着色器没有阴影贴图,只有黑屏可见。 ID纹理和其他参数已成功加载。以下是代码段:
c ++:
void render() {
for (GLuint i = 0; i < count; i++) {
// start id = 10
glUniform1i(samplersLocations[i], startId + i);
glActiveTexture(GL_TEXTURE0 + startId + i);
glBindTexture(GL_TEXTURE_CUBE_MAP, texturesIds[i]);
}
...
}
glsl:
#version 400 core
...
uniform samplerCube shadowMaps[MAX_LAMPS_COUNT];
在编译着色器时没有错误。据我了解,纹理由于某种原因未绑定。深度图本身已正确绘制。
编辑:我按以下方式访问数组的元素:
for (int i = 0; i < count; i++) {
...
depth = texture(shadowMaps[i], fragToLight).r;
...
}
编辑:发现当samplerCube
数组大于绑定纹理时,出现黑屏。例如MAX_LAMPS_COUNT = 2
且count = 1,然后
uniform samplerCube shadowMaps[2];
glUniform1i(samplersLocations[0], startId + 0);
glActiveTexture(GL_TEXTURE0 + startId + 0);
glBindTexture(GL_TEXTURE_CUBE_MAP, texturesIds[0]);
在这种情况下,将出现黑屏。
但是如果MAX_LAMPS_COUNT = 1
(uniform samplerCube shadowMaps[1]
)会出现阴影,但是还会出现一个新问题:
不要注意所有东西都是绿色的,这是由于视频卡的颜色校正设置不正确。
有什么想法吗?
编辑:这是渲染代码的完整问题区域:
#define cfgtex(texture, internalformat, format, width, height) glBindTexture(GL_TEXTURE_2D, texture); \
glTexImage2D(GL_TEXTURE_2D, 0, internalformat, width, height, 0, format, GL_FLOAT, NULL);
void render() {
for (GLuint i = 0; i < count; i++) {
// start id = 10
glUniform1i(samplersLocations[i], startId + i);
glActiveTexture(GL_TEXTURE0 + startId + i);
glBindTexture(GL_TEXTURE_CUBE_MAP, texturesIds[i]);
}
renderer.mainPass(displayFB, rbo);
cfgtex(colorTex, GL_RGBA16F, GL_RGBA, params.scrW, params.scrH);
cfgtex(dofTex, GL_R16F, GL_RED, params.scrW, params.scrH);
cfgtex(normalTex, GL_RGB16F, GL_RGB, params.scrW, params.scrH);
cfgtex(ssrValues, GL_RG16F, GL_RG, params.scrW, params.scrH);
cfgtex(positionTex, GL_RGB16F, GL_RGB, params.scrW, params.scrH);
glClear(GL_COLOR_BUFFER_BIT);
glClearBufferfv(GL_COLOR, 1, ALGINE_RED); // dof buffer
// view port to window size
glViewport(0, 0, WIN_W, WIN_H);
// updating view matrix (because camera position was changed)
createViewMatrix();
// sending lamps parameters to fragment shader
sendLampsData();
glEnableVertexAttribArray(cs.inPosition);
glEnableVertexAttribArray(cs.inNormal);
glEnableVertexAttribArray(cs.inTexCoord);
// drawing
//glUniform1f(ALGINE_CS_SWITCH_NORMAL_MAPPING, 1); // with mapping
glEnableVertexAttribArray(cs.inTangent);
glEnableVertexAttribArray(cs.inBitangent);
for (size_t i = 0; i < MODELS_COUNT; i++) drawModel(models[i]);
for (size_t i = 0; i < LAMPS_COUNT; i++) drawModel(lamps[i]);
glDisableVertexAttribArray(cs.inPosition);
glDisableVertexAttribArray(cs.inNormal);
glDisableVertexAttribArray(cs.inTexCoord);
glDisableVertexAttribArray(cs.inTangent);
glDisableVertexAttribArray(cs.inBitangent);
...
}
renderer.mainPass
代码:
void mainPass(GLuint displayFBO, GLuint rboBuffer) {
glBindFramebuffer(GL_FRAMEBUFFER, displayFBO);
glBindRenderbuffer(GL_RENDERBUFFER, rboBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, params->scrW, params->scrH);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rboBuffer);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
编辑:发现确实整个samplerCube数组都必须填充一些东西,否则将出现黑屏。因此,为了避免黑屏,所有未使用的插槽都必须填充ID为0的纹理(这是因为使用了开源驱动程序吗?)。但是随后出现了另一个问题-奇怪的亮点。确定它们与随附的PCF(软阴影)一起出现。这是着色器代码的问题区域:
const vec3 sampleOffsetDirections[20] = vec3[] (
vec3(1, 1, 1), vec3(1, -1, 1), vec3(-1, -1, 1), vec3(-1, 1, 1),
vec3(1, 1, -1), vec3(1, -1, -1), vec3(-1, -1, -1), vec3(-1, 1, -1),
vec3(1, 1, 0), vec3(1, -1, 0), vec3(-1, -1, 0), vec3(-1, 1, 0),
vec3(1, 0, 1), vec3(-1, 0, 1), vec3(1, 0, -1), vec3(-1, 0, -1),
vec3(0, 1, 1), vec3(0, -1, 1), vec3(0, -1, -1), vec3(0, 1, -1)
);
...
// get vector between fragment position and light position
vec3 fragToLight = fragWorldPos - lamps[index].lampPos;
// now get current linear depth as the length between the fragment and light position
float currentDepth = length(fragToLight);
// use the light to fragment vector to sample from the depth map
float closestDepth;
// PCF
float viewDistance = length(viewPos - fragWorldPos);
float diskRadius = (1.0 + (viewDistance / lamps[index].far)) * diskRadius_k + diskRadius_min;
for (int i = 0; i < 20; i++) {
closestDepth = texture(shadowMaps[index], fragToLight + sampleOffsetDirections[i] * diskRadius).r;
^^^^^^^^^^^^^problem here^^^^^^^^^^^^^^
closestDepth *= lamps[index].far; // Undo mapping [0;1]
// now test for shadows
if(currentDepth - shadow_bias > closestDepth) shadow += 1.0;
}
return shadow /= 20;
有什么想法吗?注意:在Intel HD Graphics和Nvidia上一切正常
答案 0 :(得分:1)
问题解决了。
package android.hardware.usb;
public class UsbPortStatus implements android.os.Parcelable {
/** @hide */
public UsbPortStatus(int currentMode, int currentPowerRole, int currentDataRole,
int supportedRoleCombinations) {
throw new RuntimeException( "Stub!" );
}
/**
* Returns true if there is anything connected to the port.
*
*/
public boolean isConnected() {
throw new RuntimeException( "Stub!" );
}
/**
* Gets the current mode of the port.
*
*/
public int getCurrentMode() {
throw new RuntimeException( "Stub!" );
}
/**
* Gets the current power role of the port.
*
*/
public int getCurrentPowerRole() {
throw new RuntimeException( "Stub!" );
}
/**
* Gets the current data role of the port.
*
*/
public int getCurrentDataRole() {
throw new RuntimeException( "Stub!" );
}
/**
* Returns true if the specified power and data role combination is supported
* given what is currently connected to the port.
*
*/
public boolean isRoleCombinationSupported(int powerRole, int dataRole) {
throw new RuntimeException( "Stub!" );
}
/** @hide */
public int getSupportedRoleCombinations() {
throw new RuntimeException( "Stub!" );
}
@Override
public String toString() {
throw new RuntimeException( "Stub!" );
}
@Override
public int describeContents() {
throw new RuntimeException( "Stub!" );
}
@Override
public void writeToParcel(android.os.Parcel dest, int flags) {
throw new RuntimeException( "Stub!" );
}
public static final android.os.Parcelable.Creator<UsbPortStatus> CREATOR =
new android.os.Parcelable.Creator<UsbPortStatus>() {
@Override
public UsbPortStatus createFromParcel(android.os.Parcel in) {
throw new RuntimeException( "Stub!" );
}
@Override
public UsbPortStatus[] newArray(int size) {
throw new RuntimeException( "Stub!" );
}
};
}
数组填充为
零。否则,将出现黑屏。答案 1 :(得分:1)
一两年前,我在级联阴影贴图上也遇到了类似的问题,在英特尔和Nvidia上它运行得很好,但是在AMD上我只有第一个级联。
显然,如果您有简单的采样器数组(例如sampler2D tex[5]
),则需要在AMD上设置每个元素,而Nvidia和Intel假定它在内存中是连续的,并且如果绑定第一个纹理,则会自动绑定所有纹理。
我的解决方案是使用在每个GPU上都能正常工作的采样器数组(例如sampler2DArray
)。