Jump to content
  • Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!