Cascading Shadow Map Artifacts

Every now and then using Receive Shadow = true on a plane… I get these wavy line artifacts. I have tried tweaking the bias and normal bias but i dont really now the rhyme or reason behind the values to be used for shadow maps. 1.0 vs 0.1 for example… I just play with them till it looks good enough.

Here is a shot using 4 cascade shadow map

If i disable receive shadow there are no artifacts

cc @Evgeni_Popov

I think it’s shadow acne (not easy to be sure with just a screenshot), in which case it’s the bias / normal bias that needs to be set indeed. The right values to use depend on the scene, and it’s not possible to define values that will work in all cases, unfortunately.

1 Like

Some more questions (just to throw out there, for anyone with some info)

Does the bias have anything to do light angle or something ?

How would I know what range it should in… Is it always between 0 and 1 or can it b 0 to 100… For example ?

Is there a default value to start with ?

Any docs explaining that bias and normal bias ?

I am just trying to get a handle on how it effects the shadow and what should I default the values to for exportation.

Fixed it… Man that ChatGPT o1 Preview is a Mutha Fxxxxxx.

In Babylon.js, Cascade Shadow Maps (CSM) are used to improve shadow quality over large areas, especially in outdoor scenes. The idea is to divide the view frustum into several “cascades” and render a shadow map for each, providing higher resolution shadows closer to the camera.

Two important properties that help reduce shadow artifacts in Babylon.js’s CascadeShadowMap (CSM) class are bias and normal bias. These values are important for controlling shadow mapping precision, which can suffer from artifacts like shadow acne and peter-panning.

1. Bias

Bias is a small offset applied to the depth values of the shadow map during the shadow comparison. This helps avoid artifacts such as shadow acne, where shadows incorrectly appear on the surface of objects, caused by precision issues between the light’s depth map and the camera’s depth map.

  • What does it do? The bias shifts the depth of the surface in the shadow map slightly farther away from the light source.
  • Effect on artifacts:
    • Too low: If the bias is set too low, you might see shadow acne. This occurs when the shadow map’s precision is not enough to differentiate between surfaces at similar distances, causing the object to self-shadow incorrectly.
    • Too high: If the bias is too high, you may see an artifact called peter-panning, where shadows appear detached from the object (as if floating), because the shadow starts too far away from the object’s surface.

The bias is usually in the range of very small numbers, like 0.001 to 0.005, and adjusting it is a balance between reducing shadow acne and avoiding peter-panning.

2. Normal Bias

Normal bias takes into account the direction of the surface normals when calculating the shadow depth comparison. Instead of shifting the depth linearly (as bias does), normal bias shifts the depth based on the angle between the light source and the surface normal.

  • What does it do? The normal bias effectively scales the bias based on the angle of the surface. On surfaces facing the light, it applies a smaller offset, and on surfaces angled away from the light, it applies a larger offset.
  • Effect on artifacts:
    • Too low: If the normal bias is too low, shadow acne can appear on steep surfaces or areas with sharp angles, where depth comparisons are more prone to error.
    • Too high: If the normal bias is too high, you can get shadow detachment or peter-panning, particularly on steep surfaces. The shadow might appear to float away from the surface due to the larger depth offset.

Practical Considerations

  • Light Type: These biases are especially important for directional lights (common with CSM), as they project shadows across large distances. The angle and distance of the light to the surface can exacerbate depth precision issues, making bias tweaking more important.
  • Cascade Settings: In Cascade Shadow Maps, you may need to adjust the bias and normal bias per cascade to balance quality across distances (closer cascades need higher precision).
  • Scene Scale: Large-scale scenes may require different bias values because of how far the light and camera are from objects.

Summary of Influence:

  • Bias directly affects how much the depth of the shadow is offset. It mainly addresses shadow acne but can cause peter-panning if set too high.
  • Normal bias uses surface orientation to determine how much bias to apply. It can handle issues on steep surfaces better but needs careful tuning to avoid detaching shadows.

Fine-tuning these parameters is a balancing act that depends on your scene’s lighting, geometry, and scale. You’ll often have to tweak both bias and normal bias to reduce artifacts without causing new ones.

Same scene, with no shadow acne using default values. You can still tweak them in the editor, but much better understanding of what is what after a lengthy talk with Skynet

Was able to workout good default values :slight_smile: