Sign in to follow this  

Depth test in fragment always return 1.0

This topic is 3671 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, this might seem a stupid question (maybe it's the case and I hope so) but I'm hammering my head for a couple of days to find a logic reason why my depth test fails. First off, the source code: I define the depth texture with those parameters:
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,           GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,           GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,       GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,       GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB,   GL_LUMINANCE);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);

glTexImage2D (GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, textSize, textSize, 0, 
              GL_DEPTH_COMPONENT, GL_FLOAT, 0);
The depth texture works great, I've saved it as an image just before passing it to the shader and I can clearly see depth values. In the shader, after some calculations, I simply do:
vec4 depthTest = shadow2DProj(dTexture, P);
if (depthTest.r > 0.5)
   R.r = max(dot(normalize(N).xyz, normalize(viewDirection)), 0.0);
Where P is the current vertex in clip space mapped in viewport space. I used a vec4 so I can debug the shader in GLSLdevil. Here's the problem: depthTest.xyzw is ALWAYS equal to vec4(1.0). I can't understand why. Any suggestion?

Share this post


Link to post
Share on other sites
Little update: If I manually copy the depth texture data in a new RGBA texture it works like a charm.. there's something wrong with reading from a GL_LUMINANCE depth texture in shaders..

Share this post


Link to post
Share on other sites
If it works fine as an RGBA texture, why not try just storing it as an Alpha texture? GL_ALPHA8 for internal, and GL_ALPHA instead of GL_LUMINANCE. I have no tried it, just a quick idea might be a simple fix.

Share this post


Link to post
Share on other sites
Yes, it was a stupid question.

You can't use the same FBO for reading and writing (even though if you do it on different targets - reading from the depth and writing to the color..)

Just used two FBOs and is all ok :)

Share this post


Link to post
Share on other sites

This topic is 3671 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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