Sign in to follow this  
mv348

Trouble reading from depth-texture

Recommended Posts

In my last post I stated that I was having trouble with rendering to a depth texture. But I believe the following has demonstrated that the render to texture is successful and the issue is I can't read from the texture after the rendering is complete. 

 

I used glReadPixels to check if my depth texture is being cleared. I used the following after calling glClear:
 
glBindFramebuffer(GL_READ_FRAMEBUFFER,  m_fbo);
 
float depth;
glReadPixels(0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth);
 
printf("depth value is %f",depth);
 
 
The print message outputs whatever clear depth I've set before calling glClear (with the fbo bound as the draw buffer), so I at least now know that the depth texture IS being written to. The problem is I just can't get my shaders to read from it! Here is where the texture is sampled:
 
 

float mapSample = (texture( gCascadedShadowMap, TexCoord).x);
 
FragColor =   vec4(mapSample,mapSample,mapSample,1);

 
 
I am well aware of the usual faintness of the depth-texture rendering, that's why I'm using glClear() with a depth value of around 0.5. I should be seeing a mid-gray screen when I render, but instead I just see blackness. If I set other textures to gCascadedShadowMap, however, it draws the texture to the screen correctly.
 
Any help or ideas would be greatly appreciated!
Edited by mv348

Share this post


Link to post
Share on other sites

Yep! I set 7 as the active texture unit, bind the texture,and then set 7 as the value of the gCascadedShadowMap texture uniform.

 

I was hoping someone might now what possible things could 'block' the texture from being read from? Are their constraints on the bind states of the frame buffer objects? I've tried binding and unbinding the relevant frame buffers in various places, but I'm sure I've not exhausted the possibilities.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this