Jittery shadows on DirectionalLight3D x rotation when character moves in z direction

Godot Version

4.2.2.stable

Question

I have a simple scene containing basic cubes and a DirectionalLight3D that rotates on the x-axis. When my character moves along the z-axis, either towards or away from the light, the shadows start to jitter. This jittering becomes more pronounced the further the character moves away from the global center.

I tried uploading a video, but am a new user and can’t. So here is my discord post with a referential video, Discord, that starts at the global center and shows how the shadow jitter increases as the character moves farther away from the center. Additionally, here is the script attached to the scene, which includes simple time-tracking logic:

extends Node

const DAY_SECONDS: int = 86400

var time: float = 0
var timeSpeed: int = 30

@onready var sun = $Sun

func _process(delta):
    time += delta * timeSpeed
    var percent = fmod(time, DAY_SECONDS) / DAY_SECONDS
    sun.rotation_degrees.x = -percent * 360

I’ve tried adjusting the different settings in the “3D lights and shadows” documentation, 3D lights and shadows — Godot Engine (stable) documentation in English, but I haven’t been able to fix the jitter. If you have any suggestions on how to reduce or eliminate the jitter, I’d be very grateful.

sun.rotation_degrees.x = lerp_angle(sun.rotation_degrees.x,  -percent * 360, 0.01)

Although to do interpolation correct you need to set up a target and update it many more times overall.

You rotate about 0.002 degrees every frame. How far is your sun from its rotation point?

Also there is a procedural sky that I think can do this.