Hi all.
I have set up a frame buffer object for deferred rendering like so:
glBindTexture(GL_TEXTURE_2D, gNormal);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, wWidth, wHeight, 0, GL_RGB, GL_FLOAT, NULL);
glBindTexture(GL_TEXTURE_2D, gAlbedo);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, wWidth, wHeight, 0, GL_RGBA, GL_FLOAT, NULL);
glBindTexture(GL_TEXTURE_2D, gMaterial);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, wWidth, wHeight, 0, GL_RGBA, GL_FLOAT, NULL);
glBindTexture(GL_TEXTURE_2D, gDepth);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH32F_STENCIL8, wWidth, wHeight, 0, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, NULL);
glBindTexture(GL_TEXTURE_2D, cRadiance);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, wWidth, wHeight, 0, GL_RGBA, GL_FLOAT, NULL);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, gBuffer);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gNormal, 0);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, gAlbedo, 0);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, gMaterial, 0);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, gDepth, 0);
Just recently I switched from GL_DEPTH24_STENCIL8 due to inaccuracy issues. In my fragment shader I calculate the eye space position of a surface using the following code:
float x = (texCoords.x * 2.0f) - 1.0f;
float y = (texCoords.y * 2.0f) - 1.0f;
float z = (texture(gDepth, texCoords).s * 2.0) - 1.0f;
vec4 buff = invProj * vec4(x, y, z, 1.0f);
sPos = buff.xyz / buff.w;
Prior to changing from GL_DEPTH24_STENCIL8 this would work perfectly. However, ever since the change to GL_DEPTH32F_STENCIL8, the look up texture(gDepth, texCoords).s spews out garbage.
What should I be doing instead of texture(gDepth, texCoords).s?
Did I specify the wrong type or internal format for the attatched depth texture?
Any help will be greatly appreciated.