aboutsummaryrefslogtreecommitdiff
path: root/apps/fparkan-game/src/scene_point_lights.rs
blob: 995879c36b2beec1f123f6149912b685bee732d2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use fparkan_fx::environment::{EnvironmentFrame, PointLightFrame};
use fparkan_render_vulkan::{VulkanPointLight, VulkanSmokeRenderer, VulkanSmokeRendererError};

pub(super) fn upload(
    renderer: &mut VulkanSmokeRenderer,
    enabled: bool,
    environment: Option<&EnvironmentFrame>,
    control_lights: &[VulkanPointLight],
) -> Result<(), VulkanSmokeRendererError> {
    if !enabled {
        return renderer.set_point_lights(&[]);
    }
    let Some(environment) = environment else {
        return renderer.set_point_lights(control_lights);
    };
    let lights = environment
        .point_lights
        .iter()
        .filter(|light| light.active)
        .map(environment_record)
        .chain(control_lights.iter().copied())
        .collect::<Vec<_>>();
    renderer.set_point_lights(&lights)
}

pub(super) fn environment_record(light: &PointLightFrame) -> VulkanPointLight {
    VulkanPointLight {
        owner_scope: 0,
        position: light.position,
        rgb: [light.color[0], light.color[1], light.color[2]],
        range: light.range,
        coefficients: light.attenuation,
        active: light.active,
    }
}