OpenGL: Reset depth buffer using polygons

Started by
16 comments, last by ChicXulub 18 years, 11 months ago
This is just an update, in case other need to use this as well...

do NOT use glDepthRange(1.0,1.0) !! I did so, and it worked fine on my stationary computer (Radeon 9000), but on my laptop (Mobility radeon 9000), all hell broke loose!
What i eventually found out is that glDepthRange(1.0,1.0) probably makes some divide-by-zero in SOME graphics drivers. to avoid this entirelly, use glDepthRange(0.9999999,1.0) instead. You will not reset the depth buffer entirelly, but at least it doesn't try to divide by zero.

Anyway, thanks for the quick responces!
--Electron"The truth can be changed simply by the way you accept it.""'General failure trying to read from file' - who is General Failure, and why is he reading my file??"
Advertisement
Why do you want to do it this way instead of using glClear()? The graphics hardware has special clearing circuitry that is much faster than drawing a full-screen polygon with the maximum depth value. Also, if you don't use glClear(), there's a good chance that you'll lose hierarchical Z optimizations that both Nvidia and ATI implement. You're really asking for a performance penalty here.
This sounds like you're abusing the depth buffer rather than having proper geometry but if you're really set on doing this I'd suggest that the stencil buffer is designed for exactly this kind of operation. You can stencil in your door, clear all the depth buffer and render the rest of the geometry without a hitch.
Eric, The problem is that i do not want to remove ALL depth buffer data, only reset it in the door.


And Orangytang:
This is not doable either. It is true that i must use the stencil buffer to only write in the doorway, but i still want the room behind the doorway to have proper depth culling. This is not doable unless i reset the depth buffer in the doorway to ZFar. And i cannot clear the ENTIRE depth buffer either, since i need the depth information of the whole scene in order to render it correct.
--Electron"The truth can be changed simply by the way you accept it.""'General failure trying to read from file' - who is General Failure, and why is he reading my file??"
Quote:Original post by Electron
This is not doable unless i reset the depth buffer in the doorway to ZFar. And i cannot clear the ENTIRE depth buffer either, since i need the depth information of the whole scene in order to render it correct.


No, you clear the entire depth buffer to avoid the nasty hacks you're doing now. Then you use the stencil test to render only though the doorway, and the (now clean) depth buffer to make sure your second room renders correctly.

Incidentally, this sounds like you'd have a much cleaner implementation if you used a proper portal rendering method (essencially the same, but less hacky and special case).
But say that i have TWO portals in one room? I need the depth buffer to figure out whenever the portal is visible or not (behind another object, for instance). If i clear the depth buffer in order to render the first portal, i am unable to tell anything about the visibility of the other portal.

One way would be of course to set a stencil bit for each portal in the room, clear the depth buffer and THEN enter each portal and render it.
But then other problems occur. One problem is that i will take up most of the stencil buffer capacity (currently i use only 1 bit), which i would like to save for other uses. Other problem is that the portal rendering is recursive, which requires the data in the stencil buffer to be very structurally strict.

For example: The current room has two portals, and in one of them, there is another portal. In order to render this third room, i must have a stencil mask saying: "render where this and this portal is open, but NOT in the other portals". I find this problem pretty difficult to achieve. Basically, i would need one bit per portal, which leaves me with only 8 portals per scene (= not good).

So instead i use this method:

function renderSceneInPortal
BEGIN

*Render the portal mesh, set the stencil bit to OPEN. (depth test ON, for culling)
*Render the portal mesh again, disabling depth test and using glDepthFunc(1.0,1.0)
*Render current room and it's interiors
*Close the portal (set the stencil bit to CLOSED)

*for each portal in the room:
*Transform the modelview matrix.
*call renderScene with current room.
END


Altough very simplified, this method works very well, as you can see in these screenshots. Notice how the portal in the middle of the room shows something entirelly different than is shown behind the portal.
Image 1
Image 2



And i really don't see how i can change this to use glClear instead. This runs in 50 FPS without any heavy optimizations on a 1GHz computer with Radeon 9000.



Why is GameDev doing this to me?!

Well, the upper post was, naturally, from me.. And here is the missing links
Image 1
Image 2


--Electron"The truth can be changed simply by the way you accept it.""'General failure trying to read from file' - who is General Failure, and why is he reading my file??"
Having a 8-bit stencil buffer gives you 2^8 values to play around with, not 8.
And given that you don't have "overlapping rooms" you can have a virtually unlimited amount of rooms visible, and rooms showing in other rooms up to 255 levels deep.

Or am i wrong?

This topic is closed to new replies.

Advertisement