Sign in to follow this  
ogl5

depth buffer

Recommended Posts

I was reading this doc on glFrustum: http://msdn2.microsoft.com/en-us/library/ms537094.aspx It says: "Depth-buffer precision is affected by the values specified for znear and zfar. The greater the ratio of zfar to znear is, the less effective the depth buffer will be at distinguishing between surfaces that are near each other. " So, it sounds like it is using a transformed version of z for depth buffer comparisons. Why not just use the original z?

Share this post


Link to post
Share on other sites
Two answers, actually.

First, the graphics hardware likely does not actually store your depth buffer with the same precision [say, 16 bits, instead of 32 or 64] as you use in your regular code. Secondly, the graphics hardware has always sacrificed accuracy for speed, and because some number should mathematically be every-so-slightly-less-than some other number, it may very well come up as equal [or even slightly greater than] when the graphics hardware examines it.

In all honesty though, you'll likely only have to concern yourself with this problem if you're:

A: using HUGE z-far values with TINY z-near values
B: Rendering things that need to be quite precise [like, for example, shadow volumes, which are rather notorious for this exact problem]

The actual problem is called Z-buffer fighting, and can be seen in these screen shots :

A Correct image

An Incorrect image, featuring Z-buffer fighting [due to shadow volumes]

Helps to know what the problem looks like. You'll encounter a similar tearing-look if you render polygons very close together with very large z-far and very small z-near values. In all practicality, unless you're dealing with extreme cases, you'll likely never run into this problem. The notes from MSDN are to explain odd effects that could easily be gotten by, say, setting z-far to 100000000 and z-near to 0.0000001. Just don't set your clip planes to silly values.

[Edited by - Drigovas on August 15, 2007 5:15:02 AM]

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