Click or drag to resize
DigitalRuneShadow Acne
Shadow acne

Shadow acne is another problem caused by the limited resolution of the shadow map.

First, a scene with no shadow acne:

Shadow-Acne-Reference
Figure: Reference scene, no shadow acne

When shadows are rendered naively – simply comparing a depth value with the value in the shadow map – the following happens: Faces are likely to be self-shadowed. This erroneous self-shadowing is called shadow acne.

Shadow-Acne
Figure: Shadow Acne

Note that increasing the resolution of the shadow map does not prevent shadow acne…

Shadow-Acne-Increased-Resolution
Figure: Shadow acne with increased shadow map resolution.

… nor does shadow map filtering. A large filter radius can make the problem even worse.

Shadow-Acne-Filtering
Figure: Shadow filtering does not remove shadow acne.
Shadow biasing

To avoid shadow acne, the pixels in the scene need to be moved closer to the light source during the shadow test. This is called biasing. Different biasing methods exist:

  • Depth Bias: The pixel is moved in the direction of the light.
  • Slope-Scaled Depth Bias: Like the depth bias, but the offset depends on the slope of the surface because shadow acne is bigger on slopes which are nearly parallel to the light.
  • Normal Offset [1]: The pixels are moved in the direction of the surface normal. The offset can be proportional to the slope.
  • View Direction Offset [2]: Like the normal offset but instead of moving into the normal direction, the pixel is moved in the view direction. This is cheaper but not as good as the normal offset.
  • Receiver Plane Depth Bias [3][4]: The receiver plane is calculated to analytically find the ideal bias.

A bias can be applied to the depth values when rendering the shadow map or when reading the shadow map: The depth bias and the slope-scaled depth bias are usually applied when the shadow map is created using the depth bias features of the graphics hardware. The other bias types are applied when the shadow map is read.

We have tested these methods and found a combination of depth bias and slope-scaled normal offset to be the most robust. Both are applied when the shadow map is read. The bias values are controlled with the shadow properties DepthBias and NormalOffset.

Note Note

The depth bias and the normal offset are applied by the ShadowMaskRenderer (see Shadow Masks). If you use forward rendering, you have to implement shadow biasing in the forward rendering shader and you are free to implement any biasing method you prefer.

Depth bias

Increasing the DepthBias moves lit pixels closer to the light (the pixels are only moved during the shadow test, not in the real scene). The depth bias removes shadow acne from surfaces facing the light source.

Shadow-Depth-Bias
Normal offset

As shown in the image above, faces parallel to the light direction may still show shadow acne. To clean these faces the NormalOffset needs to be increased. The normal offset virtually pushes pixels into the light by moving them in the direction of the surface normal.

Shadow-Normal-Offset
Bias units

Depth bias and normal offset values are specified in shadow map texels. For example, depth bias = 3 means that the pixels is moved the length of 3 shadows map texels closer to the light.

This unit choice makes bias settings easier to understand and to configure: When shadow filtering is disabled, the size of the shadow map texels is easy to spot in the stair pattern of the shadow edges.

This unit ensures that the bias automatically scales with the shadow map resolution. The same bias settings work regardless of the shadow map resolution.

The bias also scales for lights with perspective projections such as spotlights: Objects near a spotlight (good shadow map resolution) only need a small bias, objects in the distance (poor shadow map resolution) need a large bias. By keeping the bias proportional to the projected shadow map texels, the same settings work at all distances.

Peter panning

If shadow filtering uses a large filter radius, you need larger depth bias and normal offset values. However, using large values can introduce a new problem called Peter Panning, where the shadow becomes disconnected from the shadow caster.

Shadow-Peter-Panning
Figure: Correct shadow bias (left) vs. large shadow bias (right)

Therefore, make the depth bias and normal offset only as large as necessary to remove shadow acne.

References