diff --git a/crates/bevy_pbr/src/lib.rs b/crates/bevy_pbr/src/lib.rs index e3eb0f43ff..4bd5c76f33 100644 --- a/crates/bevy_pbr/src/lib.rs +++ b/crates/bevy_pbr/src/lib.rs @@ -341,6 +341,7 @@ impl Plugin for PbrPlugin { SyncComponentPlugin::::default(), SyncComponentPlugin::::default(), SyncComponentPlugin::::default(), + ExtractComponentPlugin::::default(), )) .configure_sets( PostUpdate, diff --git a/crates/bevy_pbr/src/light/ambient_light.rs b/crates/bevy_pbr/src/light/ambient_light.rs index 068e445f3b..f09bab51f6 100644 --- a/crates/bevy_pbr/src/light/ambient_light.rs +++ b/crates/bevy_pbr/src/light/ambient_light.rs @@ -4,6 +4,8 @@ use super::*; /// /// This resource is inserted by the [`PbrPlugin`] and by default it is set to a low ambient light. /// +/// It can also be added to a camera to override the resource (or default) ambient for that camera only. +/// /// # Examples /// /// Make ambient light slightly brighter: @@ -15,8 +17,9 @@ use super::*; /// ambient_light.brightness = 100.0; /// } /// ``` -#[derive(Resource, Clone, Debug, ExtractResource, Reflect)] -#[reflect(Resource, Debug, Default)] +#[derive(Resource, Component, Clone, Debug, ExtractResource, ExtractComponent, Reflect)] +#[reflect(Resource, Component, Debug, Default)] +#[require(Camera)] pub struct AmbientLight { pub color: Color, diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index 873d2eede4..90614772e3 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -705,6 +705,7 @@ pub fn prepare_lights( &ExtractedClusterConfig, Option<&RenderLayers>, Has, + Option<&AmbientLight>, ), With, >, @@ -1115,7 +1116,14 @@ pub fn prepare_lights( let mut live_views = EntityHashSet::with_capacity(views_count); // set up light data for each view - for (entity, extracted_view, clusters, maybe_layers, no_indirect_drawing) in sorted_cameras + for ( + entity, + extracted_view, + clusters, + maybe_layers, + no_indirect_drawing, + maybe_ambient_override, + ) in sorted_cameras .0 .iter() .filter_map(|sorted_camera| views.get(sorted_camera.entity).ok()) @@ -1138,6 +1146,7 @@ pub fn prepare_lights( ); let n_clusters = clusters.dimensions.x * clusters.dimensions.y * clusters.dimensions.z; + let ambient_light = maybe_ambient_override.unwrap_or(&ambient_light); let mut gpu_lights = GpuLights { directional_lights: gpu_directional_lights, ambient_color: Vec4::from_slice(&LinearRgba::from(ambient_light.color).to_f32_array())