This is a simple question.

I know that in OpenGL or other graphics API, the values stored in the depth buffer are automatically clamped to (0,1).

I just want to know why people do this instead of just keeping the actual depth values as float. Is that just because of the non-linear depth equation which makes the closer depth values more precise and the further depth values less precies?

Thank you!


(Just converting comment into an answer) It seems you might be asking one of two possible questions.

If you meant "Why doesn't the Depth buffer contain camera space Z"
then it's perhaps worth reading Why do GPUs divide clip space Z by W, for position?

If, OTOH, you just meant "why is it restricted to [0,1)?", then that's probably because old systems represented the Z-buffer depth with fixed point numbers, hence a natural [0,1) range.

Of course, later hardware arrived that could use floating-point depths; IIRC Dreamcast's depth representation was an arbitrary positive float representing $\frac{1}{w}$.

  • 1
    $\begingroup$ Thanks! I just mean "why is it restricted to [0,1)?". I came up with this question when I was implementing shadow mapping. When using shadow maps, if the depth values stored in the shadow map are all between [0,1), we have to clamp the depth value of the pixel to [0,1) first and then do the comparison. If the shadow map stores the actual depth values as floats, we can just compare them directly. $\endgroup$ – Yuchen Sep 18 '18 at 17:52

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.