Weird depth rendering.

Started by
3 comments, last by bluntman 12 years, 11 months ago
I am trying to implement shadow mapping, and my rendered depth buffer looks like this:
I2Jdb.png

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!
Advertisement
Maybe its a problem with your rendering of the buffer rather than the depth buffer itself? How do you display the depth buffer?
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game

Maybe its a problem with your rendering of the buffer rather than the depth buffer itself? How do you display the depth buffer?


I am using GDebugger, and it works fine for my other depth buffers (the backgrounds are white).
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.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
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.

This topic is closed to new replies.

Advertisement