garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

.. /docs/notes/directional-lights-share-one-cascade-config.md

raw


topic: directional-lights triggers: [systems/map/sky.rs, setup_sky, spawn_sun_light, spawn_moon_light, manage_lights, apply_day_night_cycle, shadow_cascades, num_cascades, shadow_maps_enabled, CascadeShadowConfigBuilder, DirectionalLight, "index out of bounds", "moon shadow"] updated: 2026-10-17

The sun and the moon must agree on their shadow cascades

An external constraint in bevy_light, found on Bevy 0.19 and not re-tested on 0.20: with two DirectionalLights in the scene it panics with index out of bounds in its cascade visibility if

Neither is a configuration error a test would notice; both are a crash the first time the moon rises over a scene whose lights were set up differently, or the first time somebody flips the shadow checkbox.

How the client stays on the right side of it

The moon light exists only while it contributes (moon up at night): manage_lights spawns and despawns it rather than leaving a zero-illuminance light in the scene, because bevy still computes its cascade frusta and walks it in every fragment's light loop.

A comment in apply_day_night_cycle still says "Moon shadows stay enabled", which has not been true since 2026-09-11; the rule beside it — do not toggle the flag at runtime — still holds.

If this is ever re-tested on a newer Bevy, the test is a scene with a sun and a moon at different cascade counts, and a run that flips shadow_maps_enabled on a spawned light. Until then, treat both as panics.