From 83dbde9bc0ae69b1b97d41004b503f6cf67415a9 Mon Sep 17 00:00:00 2001 From: Nova Date: Fri, 29 Aug 2025 16:20:01 -0700 Subject: [PATCH] refactor(sky): add/remove ambient light dynamically --- src/nodes/drawable/sky.rs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/nodes/drawable/sky.rs b/src/nodes/drawable/sky.rs index df255c3..7a9fa05 100644 --- a/src/nodes/drawable/sky.rs +++ b/src/nodes/drawable/sky.rs @@ -1,12 +1,13 @@ use bevy::{ app::{Plugin, Update}, + color::Color, core_pipeline::{Skybox, core_3d::Camera3d}, ecs::{ entity::Entity, query::With, system::{Commands, Query, ResMut}, }, - pbr::environment_map::EnvironmentMapLight, + pbr::{AmbientLight, environment_map::EnvironmentMapLight}, }; use bevy_equirect::EquirectManager; use glam::Quat; @@ -45,18 +46,26 @@ fn apply_sky( if let Some(path) = light { let image_handle = equirect.load_equirect_as_cubemap(path, 1024); for cam in cameras { - cmds.entity(cam).insert(EnvironmentMapLight { - diffuse_map: image_handle.clone(), - // we might want to use the SkyTex for this? - specular_map: image_handle.clone(), - intensity: 1000.0, - rotation: Quat::IDENTITY, - affects_lightmapped_mesh_diffuse: false, - }); + cmds.entity(cam) + .insert(EnvironmentMapLight { + diffuse_map: image_handle.clone(), + // we might want to use the SkyTex for this? + specular_map: image_handle.clone(), + intensity: 1000.0, + rotation: Quat::IDENTITY, + affects_lightmapped_mesh_diffuse: false, + }) + .remove::(); } } else { for cam in cameras { - cmds.entity(cam).remove::(); + cmds.entity(cam) + .insert(AmbientLight { + color: Color::WHITE, + brightness: 1000.0, + affects_lightmapped_meshes: true, + }) + .remove::(); } } }