concinnity-device 0.19.119

GPU backends (Metal, Vulkan, DirectX) behind a device facade for Concinnity
//! Runtime replacement of the directional-light set. The lights are packed into
//! `LightUniforms` at init and pushed to the fragment shader every frame, so a
//! new sun is a field rewrite rather than a buffer rebuild. What init derived
//! from the first light and cached -- the cascade shadow direction -- is
//! re-derived here, since nothing else refreshes it.

use concinnity_core::components::DirectionalLight;
use concinnity_core::render::lights;

use super::context::MtlContext;

impl MtlContext {
    // Replace the live directional lights. The main pass, fog, raymarch, and RT
    // reflection params all read `light_uniforms` afresh each draw, so they need
    // nothing beyond the rewrite; `shadow.light_dir` is the one init-time cache.
    pub(crate) fn update_directional_lights(&mut self, lights: &[DirectionalLight]) {
        let (directional, num_directional) = lights::directional_light_data(lights);
        if self.light_uniforms.directional == directional
            && self.light_uniforms.num_directional == num_directional
        {
            return;
        }
        self.light_uniforms.directional = directional;
        self.light_uniforms.num_directional = num_directional;
        self.shadow.light_dir = lights::sun_direction(&self.light_uniforms);
    }
}