Adjusts the depth values from fragment functions by a scaling factor and a scaling bias, clamping the bias to a maximum amount.
- iOS 8.0+
- macOS 10.11+
- tvOS 9.0+
A constant bias applied to all fragments.
A bias that scales with the depth gradient of the primitive.
The maximum bias value to apply to the fragment.
A slope-scaled bias is used to improve and fine-tune shadow maps, avoid shadow acne (unintentional self-shadowing), and avoid other depth artifacts that are caused by coplanar polygons. The bias is applied to the rasterized depth and affects both depth testing and the depth value written to the depth render target. If you don't explicitly call this method, the pipeline won't apply a scale or a bias to the calculated depth value.
The bias value is calculated as follows, depending on the data type of the depth pixel format (see
MTLPixel for more information):
bias = depth
Bias * r + slope Scale * max Slope
bias = depth
Bias * 2^(exp(max abs(z) in primitive) - r) + slope Scale * max Slope
r is the smallest positive representable value in the depth render target, and
max is the largest slope of the depth value at the pixel.
The value of
clamp is applied as a
min or a
max operation, depending on its sign. If
>0, then bias
<0, then bias
=0, a clamp is not applied.
slope is nonzero, add the final calculated value of bias to the depth value.
Depth bias only influences triangle primitives; it is not applied to points or lines.