• Advertisement
Sign in to follow this  

Interpreting depth buffer values

This topic is 4737 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

Can someone step through the exact steps needed to convert the 0-1 float values that you read from the depth buffer back into their actual world space depths?

Share this post


Link to post
Share on other sites
Advertisement
Well, the transformation from eye space Z to depth buffer Z involves first a multiplication by the projection matrix followed by a perspective division where the Z gets the range [-1, 1], and then that range is transformed into [0, 1] for storage into the depth buffer. What you need to do is to perform the inverse transform of these tree steps.

The first step is trivial, to expand the depth buffer value to the range [-1, 1], but the second step may be a bit difficult. The inverse of the projection matrix can be found in the Red Book, and you need to contruct a "dummy"-vertex and multiply it by this inverse matrix.

As it's not that trivial, I just dump some code from my depth buffer simulator I wrote for MATLAB once to see how the depth buffer really behaves under certain conditions.

a = -(far - near) / (2 * far * near);
b = (far + near) / (2 * far * near);

fbZ = (2 * fbZ) - 1;
wZ = 1 ./ (fbZ * a + b);

near and far are the values of the near and far clip planes, and fb is the value in the depth buffer. The corresponding eye space Z is wZ.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement