Shadow acne is the striped pattern that appears when a model’s faces shadow themselves in Three.js, usually under a low-angle sun light. Fix it by setting normalBias on the shadow-casting light to a value above the default 0.0, for example sunLight.shadow.normalBias = 0.2. Keep the value below 0.5, or shadows start to look detached from the model.

In this guide, we will examine the root causes of shadow acne and apply effective solutions to ensure realistic shadow rendering.

What is the shadow acne?

You may have noticed the ugly shadow stripes on the model’s surface in Three.js. The scene looks unattractive despite the high resolution setting for the shadow map and using soft shadows configured with THREE.PCFSoftShadowMap. Only certain angles of the sun’s rays generate jagged shadows making it sometimes hard to spot during testing.

This problem may appear as in the screenshots below: Shadow acne on the model Shadow acne on the model closeup

3D model faces are self-shadowed, which leads to unpleasant results.

Fix ugly shadows in Three.js

The solution is simple: configure the normal bias parameter for shadow casting lights. Usually only the sun is the source of issue because of its distance and low angles. Add normalBias parameter and set it to value larger than default 0.0:

sunLight.shadow.normalBias = 0.2;

Shadows are correct now: Fixed shadow acne Fixed shadow acne closeup

By adjusting the normal bias, the distance between the shadow caster and the surface is increased, thus reducing the occurrence of shadow acne. However, if the normal bias is set too high, it can lead to the shadow being disconnected from the object, making 3d models appear as if they were floating over the ground. Therefore, it is important to find the right balance between normal bias and shadow accuracy to achieve realism in Three.js.

Play around with value to find the sweet spot that best suits your scene. Remember to keep the bias below 0.5, otherwise the shadows may appear distorted.

If you want to learn more why shadow acne occurs and the mathematics behind it, check out the following thread in Godot engine repository. Three.js documentation about the normal bias setting: click here.

Frequently asked questions

Three.js shadow acne

What is shadow acne in Three.js?

Shadow acne is a pattern of stripes or jagged shadows on the surface of a 3D model. It happens because the model's faces shadow themselves. It can appear even with a high resolution shadow map and soft shadows set to THREE.PCFSoftShadowMap.

How do I fix shadow acne in Three.js?

Set the normalBias parameter on the shadow-casting light to a value larger than the default 0.0, for example sunLight.shadow.normalBias = 0.2. This increases the distance between the shadow caster and the surface, which removes the self-shadowing stripes.

Why do shadow stripes only appear at certain sun angles?

The sun light is usually the source of shadow acne because of its distance and low angles. Only certain angles of the sun's rays produce the jagged shadows, which makes the problem easy to miss during testing.

What is a good normalBias value in Three.js?

Start around 0.2 and adjust until the stripes disappear in your scene. Keep the value below 0.5, because a higher bias can distort shadows or detach them from the object so models look like they float above the ground.

Share