aboutsummaryrefslogtreecommitdiff
path: root/apps/fparkan-game/src/scene_point_lights.rs
diff options
context:
space:
mode:
Diffstat (limited to 'apps/fparkan-game/src/scene_point_lights.rs')
-rw-r--r--apps/fparkan-game/src/scene_point_lights.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/apps/fparkan-game/src/scene_point_lights.rs b/apps/fparkan-game/src/scene_point_lights.rs
new file mode 100644
index 00000000..995879c3
--- /dev/null
+++ b/apps/fparkan-game/src/scene_point_lights.rs
@@ -0,0 +1,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,
+ }
+}