Current normalized direction pointing toward the sun.
Add the light AND its target to a scene (the target must be in the graph for the light to track it).
Point the sun. dirTowardSun points from the scene toward the sun (day/night hook).
Toggle shadow casting. Materials recompile automatically on change.
Re-fit the shadow frustum to the camera's view of the ground plane. Call once per frame after camera controls update, before rendering.
Free the shadow map texture.
A directional sun light with a shadow frustum that re-fits itself to the camera's ground footprint every frame — the counterpart to chunk streaming, where a static world-sized frustum would either waste the whole shadow map on unloaded chunks or miss the view entirely.
Per update the visible ground area (frustum corners projected onto the ground plane, clamped to
maxDistance) is wrapped in a bounding sphere and the ortho shadow camera is fitted to it. The fitted window is snapped to whole shadow-map texels in light space so panning the camera doesn't make shadow edges shimmer.The sun direction is mutable via setDirection so a day/night cycle can drive it; keep the terrain material's
uLightDirin sync (HexWorld'ssetSunDirectiondoes both).Example