refactor(sky): add/remove ambient light dynamically

This commit is contained in:
Nova
2025-08-29 16:20:01 -07:00
parent c69b2652c8
commit 83dbde9bc0

View File

@@ -1,12 +1,13 @@
use bevy::{ use bevy::{
app::{Plugin, Update}, app::{Plugin, Update},
color::Color,
core_pipeline::{Skybox, core_3d::Camera3d}, core_pipeline::{Skybox, core_3d::Camera3d},
ecs::{ ecs::{
entity::Entity, entity::Entity,
query::With, query::With,
system::{Commands, Query, ResMut}, system::{Commands, Query, ResMut},
}, },
pbr::environment_map::EnvironmentMapLight, pbr::{AmbientLight, environment_map::EnvironmentMapLight},
}; };
use bevy_equirect::EquirectManager; use bevy_equirect::EquirectManager;
use glam::Quat; use glam::Quat;
@@ -45,18 +46,26 @@ fn apply_sky(
if let Some(path) = light { if let Some(path) = light {
let image_handle = equirect.load_equirect_as_cubemap(path, 1024); let image_handle = equirect.load_equirect_as_cubemap(path, 1024);
for cam in cameras { for cam in cameras {
cmds.entity(cam).insert(EnvironmentMapLight { cmds.entity(cam)
diffuse_map: image_handle.clone(), .insert(EnvironmentMapLight {
// we might want to use the SkyTex for this? diffuse_map: image_handle.clone(),
specular_map: image_handle.clone(), // we might want to use the SkyTex for this?
intensity: 1000.0, specular_map: image_handle.clone(),
rotation: Quat::IDENTITY, intensity: 1000.0,
affects_lightmapped_mesh_diffuse: false, rotation: Quat::IDENTITY,
}); affects_lightmapped_mesh_diffuse: false,
})
.remove::<AmbientLight>();
} }
} else { } else {
for cam in cameras { for cam in cameras {
cmds.entity(cam).remove::<EnvironmentMapLight>(); cmds.entity(cam)
.insert(AmbientLight {
color: Color::WHITE,
brightness: 1000.0,
affects_lightmapped_meshes: true,
})
.remove::<EnvironmentMapLight>();
} }
} }
} }