Bias
- Last UpdatedJan 24, 2023
- 2 minute read
Surface acne (or z-fighting) occurs to the surface shadowing itself due to minor differences between the depth computation in a shader, and the depth of the same surface in the shadow buffer.
-
In order to alleviate this artifact, the test between the Scene pixel to be shadowed and the Shadow map requires some tolerance threshold.
-
There is no rule to the amount of threshold to apply, so it is necessary to carefully tweak the values on a case-by-case basis.
-
Applying too much threshold may lead to Peter Panning effect where the object and its shadow do not connect anymore.

Applying Bias
You need to decide how much bias to apply.
The parameters to control the bias are:
-
Depth Bias
-
Slope Scaled Depth Bias
-
Depth Bias Clamp
Depth Bias
The parameter csm/bias/depthBias offsets the value in the Shadow map by a certain amount to prevent z-fighting.
Slope Scaled Depth Bias
The Slope Scaled Depth is an additional offset that is based on the slope of the shadow casting polygon as seen from the Light's point of view.
It is useful because the greater the polygon's slope (as seen from the Light), the more Bias that may be required.
The parameter csm/bias/slopeScaleDepthBias multiplied by the sample's depth slope, is added to the Shadow map value (usually goes from 0 to 1).
Using the Slop Scaled Depth Bias, as shown by the green bar, the bias increases with the increase of the surface's slope.

Depth Bias Clamp
The sum of the Bias (Depth + SlopeScaledDepth) can introduce new rendering problems when a polygon viewed at an extremely sharp angle causes the bias equation to generate a very large z value.
One way to alleviate this problem is to use the parameter csm/bias/depthBiasClamp, which provides an upper bound (positive or negative) on the magnitude of the z bias calculated. When this parameter is Zero, no upper bound is used.
The Depth Bias Clamp parameter directly clamps the Shadow map value (usually goes from 0 to 1).