How does opengl Store the depth values?

I would like to know how the depth buffer precision varies depending on the
near/far ratio given a depth buffer of 24bits depth per pixel.
( Mathematical relation between the near/far, original co-ordinates and depth precision bits)
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

davebytesConnect With a Mentor Commented:
If using standard Z buffer, Near->Far Z values are normalized to 0.0-1.0, and stored as such.  However, since the standard transformation is logarithmic Z, the 'precision' drops off quickly as you get deeper into the scene -- that is, transformed Z isn't linear.

If using a W buffering approach, W >is< stored linear, so you get more consistant visuals across the entire scene depth -- however, at the loss of high precision (say, object intersections) for objects nearer to the camera.

Since Z values are translated from floating point into an integer representation, obviously the less bits of Z buffer, the less delta-Z that can be represented -- and again, since Z isn't linear, the less bits of Z, the more pixels may end up with EQUAL z values in 'z buffer space' even though their actual floating-point Z values may have been different.

Did that help?

(And, this isn't actually OpenGL, it's 3D cards in general -- though some 3D cards do tricky things with the Z buffer under the covers..)

gizmo_thunderAuthor Commented:
Hmm actually i know about this logarithmic thing and all but what i want to know is
exact relation ship between the bit representation and the depth value retrieved using
I found the following information useful.. just in case anybody else requires it..
just found it yesterday so.. :)
davidmaxwatermanConnect With a Mentor Commented:
The exact relationship is not defined by OpenGL. It is dependant on your graphics hardware. The way graphics hardware handles it varies considerably, even when from the same manufacturer.

However, if you're interested in the 'z' values, then you can translate each of the values using the glu function gluUnProject() :

This should take account of the specifc hardware involded.

Hope this helps.

All Courses

From novice to tech pro — start learning today.