This funny looking quantity:

2**(exponent(max z in primitive) - r

doesn't contain a typo. As far as I know the double star should be interpreted like so:

pow(2, (exponent(max z in primitive) - r)

The 'exponent' can also be rewritten more explicitly:

pow(2, (pow(e, max z in primitive) - r)

Where 'e' is the natural number 2.71828...

Personally, I think that formula should have been written like this:

2^(e^(MaxDepthInPrim) - r)

MaxDepthInPrim is the maximum depth value (in projection space so values on [0, 1]) of the current primitive being rendered. If you are drawing a triangle with three vertices that have a depth value of 0.5, 0.75 and 0.25 the MaxDepthInPrim will be equal to 0.75.

The constant 'r' is the number of mantissa bits used by the floating point representation of your depth buffer. If you are using a float32 format then r = 23, if you are using a float16 format then r = 10 and if you are using a float64 format then r = 52.

I'm not entirely clear on the utility behind this formula. If you play around with it a bit you can tell it's related (but not equal to) the distance between adjacent floating point values in your depth buffer. The e^(MaxDepthInPrim) is just a way of doing a non linear interpolation across the deltas between adjacent values at different points in the depth buffer.

[EDIT] typed clip-space when I should have typed projection-space.

**Edited by nonoptimalrobot, 26 August 2013 - 02:46 PM.**