Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm currently having issues with depth textures. When I sample from a depth texture it causes my other samplers to fail. For example, when I set gl_FragColor manually the depth buffer is correct. I can also sample from my Albedo and Lighting textures and composite an image but I then have to set gl_FragDepth manually. Could this be a hardware issue?

I'm creating my FBOs like this:

glGenFramebuffers(1, &m_glFBO);
glBindFramebuffer(GL_FRAMEBUFFER_EXT, m_glFBO);

glGenTextures(1, &m_glDepth);
glBindTexture(GL_TEXTURE_2D, m_glDepth);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, Width, Height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glBindTexture(GL_TEXTURE_2D, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, m_glDepth, 0);

glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_Texture.m_glID, 0);
glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);

I then bind to them and draw scene. Their individual depth buffers are correct (and linear).

#version 120

uniform sampler2D Albedo;
uniform sampler2D Lights;
uniform sampler2D Depth;

void main()
{
    vec4 AlbedoColor, LightsColor;
    AlbedoColor = texture2D(Albedo, gl_TexCoord[0].st);
    LightsColor = texture2D(Lights, gl_TexCoord[0].st);

    // Just by sampling from the depth texture my shader screws up (nothing shows up)
    // float d = texture2D(Depth, gl_TexCoord[0].st).r;

    gl_FragColor = AlbedoColor * vec4(LightsColor.rgb + LightsColor.rgb * LightsColor.a, 1.0);
}

I then composite my final image in the backbuffer.

The desired result but w/ depth information

I should be getting this but with depth information.

Thanks ahead of time!

share|improve this question
Make sure you do something with the float your sampling, an unused variable can cause a shader to not compile correctly. – Daniel Aug 1 '11 at 5:19
Doesn't matter :( – Jason Dietrich Aug 1 '11 at 5:29
3  
A common case of strange and undefined behaviour is if you forget to rebind the original depth buffer, as reading from a bound target is UB. – Lars Viklund Aug 1 '11 at 10:38
I'm just calling glBindFramebuffer w/ 0. – Jason Dietrich Aug 1 '11 at 16:31
Try definining your float d BEFORE calling any other function call. Some shader compilers/platforms don't allow variable definition after calling methods (like in standard C). – r2d2rigo Sep 28 '11 at 10:10
show 3 more comments

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.