Public Group

# depth buffer

This topic is 4055 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites

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]

1. 1
2. 2
Rutin
21
3. 3
4. 4
frob
17
5. 5

• 9
• 12
• 9
• 33
• 13
• ### Forum Statistics

• Total Topics
632591
• Total Posts
3007250

×