问题描述:

What is the depth-buffer content in OpenGL related to?

Are they the Z-values or the actual depth values from the eye (i.e sqrt(X2+Y2+Z2))?

网友答案:

The depth buffer in OpenGL stores the window-space z value for each pixel.

Window-space depth is very different from eye-space depth. To get from eye-space to window-space you have to apply projection, perspective division and viewport transformation.

The last detail is probably the most important. After projection and perspective division, the visible range of depths in your viewing volume is [-1.0, 1.0]. The default depth range biases and scales those coordinates to the range [0.0, 1.0] and that is what the depth buffer stores.


What you described as "the actual depth values" is the Euclidean distance in 3D space. That is not usually what people are discussing when they talk about depth. Depth is a measure of distance along the Z-axis.

相关阅读:
Top