Skip to main content

Module lights

Module lights 

Source
Expand description

Converts drained DirectionalLight, PointLight, SpotLight, and RectAreaLight asset components into the GPU data the renderer consumes: the fixed LightUniforms uniform (directional lights, ambient, and the legacy point array the raymarch / fog / probe paths read), the GpuLight storage buffer the clustered forward pass iterates, the per-slice spot shadow projections, and the rect area-light extents.

Structs§

DirectionalLightSet
A frame’s directional lights, held inline at the shader’s capacity so a frame can carry them without allocating. Extras past MAX_DIRECTIONAL_LIGHTS are dropped, exactly as directional_light_data drops them.
LightData
The per-scene GPU light data: the storage buffer the clustered forward pass iterates, plus the side tables it indexes into. Kept together because GpuLight.shadow_index indexes spot_shadows and GpuLight.data_index indexes area_lights – invariants that would be easy to break if the three were built independently.

Functions§

build_light_data
Packs point, spot, and rect area lights into the GpuLight storage buffer and assigns their side-table slots. All three share the MAX_LOCAL_LIGHTS budget (not the 8-entry LightUniforms array); extras past the cap are dropped with a warning. Unused fields stay at their neutral GpuLight::ZERO values, so a point light carries no cone, shadow, or area data.
build_light_uniforms
local_lights is the buffer build_light_data produced; its length is the authoritative num_local_lights the forward pass iterates.
directional_light_data
The LightUniforms directional slots and their count for lights, padded with zeroed entries. Shared by the init-time build below and the live crate::render::backend::RenderBackend::update_directional_lights seam, so a sun edited at runtime packs exactly as a relaunch would pack it.
glint_sun
The sun_dir / sun_color lanes the transparent pass carries for its specular glint: the unit direction toward the first directional light and that light’s intensity-weighted colour. Both lanes are zero when the world declares no directional light, or when the one it declares has no direction, so the glint disappears rather than falling back to the neutral sun sun_color hands the fog.
sun_color
The intensity-weighted colour of the sun sun_direction names, white when the world declares no directional light.
sun_direction
The direction the cascade shadow projection and the fog ray-march follow: the first declared directional light, or the neutral sun a world with none falls back to. Backends cache this at init and re-derive it when the light set changes.