Take the 2-minute tour ×
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
4  
This question appears to be off-topic because it is about debugging your code for you. –  Anko Dec 16 '13 at 16:11
show 4 more comments

closed as off-topic by Anko, bummzack, Sean Middleditch, John McDonald, Seth Battin Dec 19 '13 at 4:53

  • This question does not appear to be about game development within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.