Depth test in fragment always return 1.0

Started by
4 comments, last by Eraser85 16 years, 4 months ago
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?
Advertisement
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..
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.
If I do as you suggest it gives me GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT :/ Maybe I can't attach a depth texture with depth mode set as GL_ALPHA to an FBO..
Forgot to say I'm using an nVidia 8800 GTS with 169.04 drivers
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 :)

This topic is closed to new replies.

Advertisement