Ambient component (#17343)
# Objective allow setting ambient light via component on cameras. arguably fixes #7193 note i chose to use a component rather than an entity since it was not clear to me how to manage multiple ambient sources for a single renderlayer, and it makes for a very small changeset. ## Solution - make ambient light a component as well as a resource - extract it - use the component if present on a camera, fallback to the resource ## Testing i added ```rs if index == 1 { commands.entity(camera).insert(AmbientLight{ color: Color::linear_rgba(1.0, 0.0, 0.0, 1.0), brightness: 1000.0, ..Default::default() }); } ``` at line 84 of the split_screen example --------- Co-authored-by: François Mockers <mockersf@gmail.com>
This commit is contained in:
parent
d34803f5f4
commit
47d25c13d7
@ -341,6 +341,7 @@ impl Plugin for PbrPlugin {
|
|||||||
SyncComponentPlugin::<DirectionalLight>::default(),
|
SyncComponentPlugin::<DirectionalLight>::default(),
|
||||||
SyncComponentPlugin::<PointLight>::default(),
|
SyncComponentPlugin::<PointLight>::default(),
|
||||||
SyncComponentPlugin::<SpotLight>::default(),
|
SyncComponentPlugin::<SpotLight>::default(),
|
||||||
|
ExtractComponentPlugin::<AmbientLight>::default(),
|
||||||
))
|
))
|
||||||
.configure_sets(
|
.configure_sets(
|
||||||
PostUpdate,
|
PostUpdate,
|
||||||
|
@ -4,6 +4,8 @@ use super::*;
|
|||||||
///
|
///
|
||||||
/// This resource is inserted by the [`PbrPlugin`] and by default it is set to a low ambient light.
|
/// 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
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// Make ambient light slightly brighter:
|
/// Make ambient light slightly brighter:
|
||||||
@ -15,8 +17,9 @@ use super::*;
|
|||||||
/// ambient_light.brightness = 100.0;
|
/// ambient_light.brightness = 100.0;
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Resource, Clone, Debug, ExtractResource, Reflect)]
|
#[derive(Resource, Component, Clone, Debug, ExtractResource, ExtractComponent, Reflect)]
|
||||||
#[reflect(Resource, Debug, Default)]
|
#[reflect(Resource, Component, Debug, Default)]
|
||||||
|
#[require(Camera)]
|
||||||
pub struct AmbientLight {
|
pub struct AmbientLight {
|
||||||
pub color: Color,
|
pub color: Color,
|
||||||
|
|
||||||
|
@ -705,6 +705,7 @@ pub fn prepare_lights(
|
|||||||
&ExtractedClusterConfig,
|
&ExtractedClusterConfig,
|
||||||
Option<&RenderLayers>,
|
Option<&RenderLayers>,
|
||||||
Has<NoIndirectDrawing>,
|
Has<NoIndirectDrawing>,
|
||||||
|
Option<&AmbientLight>,
|
||||||
),
|
),
|
||||||
With<Camera3d>,
|
With<Camera3d>,
|
||||||
>,
|
>,
|
||||||
@ -1115,7 +1116,14 @@ pub fn prepare_lights(
|
|||||||
let mut live_views = EntityHashSet::with_capacity(views_count);
|
let mut live_views = EntityHashSet::with_capacity(views_count);
|
||||||
|
|
||||||
// set up light data for each view
|
// 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
|
.0
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|sorted_camera| views.get(sorted_camera.entity).ok())
|
.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 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 {
|
let mut gpu_lights = GpuLights {
|
||||||
directional_lights: gpu_directional_lights,
|
directional_lights: gpu_directional_lights,
|
||||||
ambient_color: Vec4::from_slice(&LinearRgba::from(ambient_light.color).to_f32_array())
|
ambient_color: Vec4::from_slice(&LinearRgba::from(ambient_light.color).to_f32_array())
|
||||||
|
Loading…
Reference in New Issue
Block a user