Sign in to follow this  
w4Yp0iNt

Failing to perform depth test of depth texture inside fragment shader

Recommended Posts

w4Yp0iNt    108

My first render pass creates a depth texture from rendering a sphere. Depth test is activated. The shaders do not change the fragment's depth. I'm pretty sure that the depth texture is generated properly. The texture is configured as follows:

  • GL_TEXTURE_COMPARE_MODE set to GL_COMPARE_R_TO_TEXTURE
  • GL_DEPTH_TEXTURE_MODE set to GL_INTENSITY
  • GL_TEXTURE_COMPARE_FUNC set to GL_LEQUAL

Now I switch to a different framebuffer, so I can access the depth texture that was rendered so far. I render the further geometry using a shader that needs to perform depth tests while running. I have simplified the shader code as far as I could:

 

uniform sampler2DShadow m_DepthMap;
uniform vec2 g_ResolutionInverse;

void main()
{
    float depthTest = texture(m_DepthMap, vec3(gl_FragCoord.xy * g_ResolutionInverse, gl_FragCoord.z));
    gl_FragColor = vec4(1, 1, 1, depthTest);
}

I want the fragments with depth value larger than the value in the depth texture to be invisible. Instead I see all of them, even those that are behind the geometry that was rendered to create the depth texture previously.

 

I hope I provided all necessary information.

Any idea what I might be doing wrong?

Edited by w4Yp0iNt

Share this post


Link to post
Share on other sites
dpadam450    2357

I don't see any if() statement suggesting that you are cutting off values at a certain point. Your depth buffer probably contains values all between .9 and 1.0  or .95 to 1.0

 

You can use gDebugger to see that your depth texture is created properly.

Share this post


Link to post
Share on other sites
w4Yp0iNt    108

I don't see any if() statement suggesting that you are cutting off values at a certain point. Your depth buffer probably contains values all between .9 and 1.0  or .95 to 1.0

 
I don't use any if-statements because the texture statement does the testing for me, at least according to the docs. It's return value should be 1 if the test is successful, 0 if it fails and values in between when the result is a result of interpolation. In my case the value seems to be 1 always.
 

You can use gDebugger to see that your depth texture is created properly.


My application is written in Java. I'm trying to get it running with gDEBugger, but it still produces lots of errors.

Nevertheless, I'm still pretty sure that the depth texture is created properly, since I'm also rendering some other objects (with some other shaders, that compute the test-locations for depth-tests differently) that produce promosing results.

EDIT: Although I had double-checked everything before posting this... I found the error, it was the depth texture was not given to the shader. Edited by w4Yp0iNt

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