Sign in to follow this  
bluntman

Weird depth rendering.

Recommended Posts

I am trying to implement shadow mapping, and my rendered depth buffer looks like this:
[img]http://i.imgur.com/I2Jdb.png[/img]

Normally the depth bits that haven't been written should be white (1.0), and you can see the ones around where actual depth writing has occurred have been set to 1. But it looks like the buffer started off without them set to 1. I am calling glClear(GL_DEPTH_BUFFER_BIT) to clear the depth buffer to 1.0 right before rendering. I have tried calling glClearDepth(0.5) to set the cleared values to 0.5 instead of 1, and that stops depth values greater than 0.5 from being rendered as one would expect, but the entire background of the depth buffer is still black!
The "steps" around the edge of the sphere rendered seems to indicate that the fragment shader is writing values in blocks (as one would expect) and this is allowing the correct background depth value to some how show through.
I can't work out what problem would cause this result, so any help would be appreciated!

Share this post


Link to post
Share on other sites
[quote name='karwosts' timestamp='1305824070' post='4813064']
Maybe its a problem with your rendering of the buffer rather than the depth buffer itself? How do you display the depth buffer?
[/quote]

I am using GDebugger, and it works fine for my other depth buffers (the backgrounds are white).

Share this post


Link to post
Share on other sites
Can you try to display it using some other method than gdebugger to confirm this? I've used gdebugger in the past and on occasion its not always exactly correct with textures, sometimes claiming that they're black when I can retrieve their data just fine from opengl.

I'd be more inclined to expect that's a bug in gDebugger than anything to do with opengl. Its very handy software, but its not always perfect.

Share this post


Link to post
Share on other sites
A knowledgeable colleague of mine has told me that it is standard practice on modern graphics cards to do lazy depth clearing. i.e. all my glClear(GL_DEPTH_BUFFER_BIT) did was tell the graphics card that the buffer should be clear, but doesn't actually clear it. Instead, when a block of pixels is processed it is cleared if it has not yet been written to. This would exactly explain the results I am seeing. His suggestion (wish I had thought of it!) is just to draw a rectangle at infinity after I have rendered everything else.
As my other depth buffers display correctly in gDebugger (and they are exactly the same format) I am pretty sure its not gDebuggers fault.

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