Black Sun rising at certain rotation angles

Godot 4.7.2

I started exploring skies and day-night cycles, and been trying out a setup I found that’s simple enough and works quite nice. If the DirectionalLight3D that represents the sun starts in the Rotation position 0.0/90.0/0.0°. This makes the scene always dark in the editor, so I wanted to have the sun default position be at noon, so 0/-90/0. And here the weirdest thing happens:

As the sun touches the horizon, it turns black for the night. But when it comes up over the horizon again, it just stays black and doesn’t turn back to emitting light as it normally does.

I barely have touched any code before this and I don’t really understand most of it, but this seems like really odd behavior and I would like to understand what’s causing it.

Here’s the script I am using:

xtends Node

@export var sun_light:DirectionalLight3D
@export var world_environment:WorldEnvironment
@export var day_duration:float = 10.0

@export var time_of_day:float = 0.0

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	sun_light.rotation_degrees.x = time_of_day


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	time_of_day += delta / day_duration
	if time_of_day >= 1.0:
		time_of_day -= 1.0
		
	sun_light.rotation_degrees.x = time_of_day * 360.0
	_update_environment()
	
func _update_environment() -> void:
	var deg_x:float = sun_light.rotation_degrees.x
	
	if is_daytime(deg_x):
		var intensity = _sun_intensity(deg_x)
		sun_light.light_energy = intensity
		
func is_daytime(deg_x:float) -> bool:
	return deg_x > 90.0 and deg_x < 270.0
	
func is_nighttime(deg_x:float) -> bool:
	return not is_daytime(deg_x)
	
func _sun_intensity(deg_x:float) -> float:
	var normalized = (deg_x - 90.0) / 180.0
	return sin(normalized * PI)