Directional light shadow behavior

Godot Version

3.6

Question

See the attached video. Why does the directional light shadow (orthogonal mode, depth range optimized) behave like this?

As the camera moves closer, shadows first fade in (as is expected) but then they disappear (fade out) . Other scene geometry or light/shadow properties does not change during this. And when the camera moves just a little bit closer or further as the player walks around, the shadows blinks on and off.

I’m guessing this is caused by the shadow map depth range getting adjusted under the hood but I don’t understand why it causes so drastic change with such a small change in camera position (and no other changes in the scene).

What is happening here and how can I fix it?

Changing to “stable” depth range fixes the blinking issue but results in very bad shadow quality. As far as I understand the “optimized” depth range should work better in a scene like this.

Is this much shadow quality degradation normal when switching from “optimized” to “stable” shadow depth range? The shadow map resolution and the scene is identical.

I managed to find a workaround: A dummy shadow caster plane right below the terrain:

Now I get sharp shadows without flickering!

I’ve been digging through Godot source code for hours and think I mostly understand how the shadow map rendering works. I still couldn’t figure out what exactly goes wrong in depth range optimization code but somehow it optimizes the range too much. It only considers shadow casters and my terrain is not self-shadowing (setting terrain to cast shadows would fix the problem). The dummy caster below the terrain keeps the depth range long enough.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.