PDA

View Full Version : Depth buffer resolution



uto
01-10-2005, 06:15 PM
Hi,
I would like to compute the depth precision according to the actual depth in [0,1], the near and the far planes distances. More precisely, I would like to be able to determine the depth value next to an arbitrary one.
If someone have a solution he is welcome.

Thanks,
-uto-

I have one but i'm not sure that the fastest. (I convert the depth in [0,1] to the int representation add 1 convert it back ...

zeckensack
01-11-2005, 04:56 AM
The depth buffer itself is linear.

Any nonlinearity is due to the perspective divide. This is more likely what you're looking for. You can compute post-divide z by multiplying an eye space vector with the projection matrix (i.e. transform to clip space), and dividing the resulting z by the resulting w.

In-depth buffer z can then be computed by a quantization step to the linear depth buffer resolution: each step is worth 1.0/(2^n-1), where n is the number of bits in the depth buffer.

If your projection matrix is a "regular" untranslated symmetric frustum, only eye space z has an influence on clip space z and w, the other entries in the third and fourth rows of the projection matrix are zero. This simplifies the computation of clip space z/w, and it also simplifies reversing the operation.