How does depth bias work in DX10 ?

Started by
1 comment, last by jerrycao_1985 10 years, 7 months ago

Hi all

I'm kind of confused by this article.

http://msdn.microsoft.com/en-us/library/windows/desktop/cc308048(v=vs.85).aspx

There is a formula in it :

Bias = (float)DepthBias * 2**(exponent(max z in primitive) - r) + SlopeScaledDepthBias * MaxDepthSlope;

First , what's ** after the number "2" ? Is it a typo ?

Second , about this part , exponent(max z in primitive) - r , could someone give me a more clear explanation ? It doesn't make any sense to me.

Thanks in advance.

Advertisement

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.

It's weird.

1. The vertex with the maximum depth value in a primitive may be far away from the pixel to be shaded. It may be even outside the render target.

2. r is a integer , 23 , 10 or 52 , whatever. How does it relate to the maximum depth value in a primitive ?

This topic is closed to new replies.

Advertisement