Skip to main content
GameDev.net gamedev.net
🔒 Locked

Debugging the depth buffer of a FBO.

Started by Enalis Sep 14, 2008 at 2:33 PM 3 replies 3.4k views
Original Post
Enalis
Enalis
I'm currently using a shader to output offscreen buffers (deferred buffers, light accumulation buffers, etc...). But now I'm having a problem with my shadow mapping and would like to view my depth maps, which are currently just stored as GL_DEPTH_COMPONENT (previously GL_DEPTH_COMPONENT24). The problem is that the output is either all white or all black. In my "debugging shader" I've been using the glsl mod command and also trying to scale the output to set different results, I can mask the output to a certain color, but if I call mod on it with any value, it always comes out black. I would like to see a nice gradient of gray-scale as I commonly see in various tutorials, however I have not been able to achieve this. On a side now, I had shadow mapping working before, but the output of the depth buffer has never been "pretty" and it certainly needs work anyway. And I figured this would be a good way of debugging all depth maps. Thoughts?... thanks in advance! As an extra note, when I output the depth buffer from the deferred prepass, it is also all white, however it definitely uses the depth buffer, because the depth test works (objects don't show through each other, but I bet you knew what I meant).
Douglas Eugene Reisinger II
Projects/Profile Site
silvermace
silvermace
the depth component is not stored in a linear way, and hence is more aligned with (visually) annoying logarithmic scale. To display a depth map for user inspection, your display shader should "unproject" the Z value and normalise the result between 0 and 1.

After a good read of this article and it should be pretty obvious how to get the linear value in your display shader.
Enalis
Enalis
for storing my shadow map I am currently using a simple shader calculation:

float z = 1.0 - (gl_FragCoord.z / gl_FragCoord.w) / far;
gl_FragColor = vec4(z, z, z, z);

Shouldn't that make it "pre-linearized"? However I see what you're saying about "unprojecting" the value via that matrix. I'll also give that a try!

Also, I should mention I'm using opengl and linux... Thanks again for the help!
Douglas Eugene Reisinger II
Projects/Profile Site
Enalis
Enalis
Fortunately I got my shadow maps working again, however I still can't quite view the depth buffer, I'll continue working and update on my progress. Thanks for your help as always!
Douglas Eugene Reisinger II
Projects/Profile Site
silvermace
silvermace
Quote:
Original post by Enalis
for storing my shadow map I am currently using a simple shader calculation:

float z = 1.0 - (gl_FragCoord.z / gl_FragCoord.w) / far;
gl_FragColor = vec4(z, z, z, z);

Shouldn't that make it "pre-linearized"? However I see what you're saying about "unprojecting" the value via that matrix. I'll also give that a try!

Also, I should mention I'm using opengl and linux... Thanks again for the help!
this is interesting. You say you are using a GL_DEPTH_COMPONENT texture, however you are writing to the colour buffer when specifying gl_FragColor = vec4(z). The Depth buffer write (the projected gl_FragCoord.z) is pretty much automatic, and by having a DEPTH_COMPONENT texture, that is the value which will actually be written to the texture. When you read this texture back, the value you saved via gl_fragcolor is not present, instead the "automatic" non-linear Z value is what was stored.

a texture which is DEPTH_COMPONENT is most easily renderered by using a basic passthrough vertex/geom/frag shaders with glColorMask used to disable colour buffer writes. (I just disable all shaders and use the fixed function pipeline - but I believe this is deprecated behaviour as of OpenGL 3.0)

If you simply want a texture which contains a "custom" Z value, create a GL_LUMINANCE16F/32F + GL_FLOAT format and then you can output whatever value you want to the colour buffer and that will be stored in the texture. [EDIT: also, if you do this, remember to attach a depth-component renderbuffer to the texture's FBO]

[Edited by - silvermace on September 15, 2008 5:36:41 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.