From 5e7bb7ffbbb29cc2c92db5e7b03aebdfd055a0cc Mon Sep 17 00:00:00 2001 From: Trashtalk Date: Sat, 18 Oct 2025 19:39:16 +0200 Subject: [PATCH 1/9] split AmbientLight into two --- crates/bevy_light/src/ambient_light.rs | 52 +++++++++++++++---- crates/bevy_light/src/lib.rs | 8 +-- crates/bevy_pbr/src/lib.rs | 6 +-- crates/bevy_pbr/src/render/light.rs | 22 +++++--- examples/3d/auto_exposure.rs | 2 +- examples/3d/fog.rs | 2 +- examples/3d/fog_volumes.rs | 2 +- examples/3d/irradiance_volumes.rs | 4 +- examples/3d/lighting.rs | 4 +- examples/3d/lightmaps.rs | 2 +- examples/3d/mixed_lighting.rs | 2 +- examples/3d/motion_blur.rs | 2 +- examples/3d/skybox.rs | 2 +- examples/3d/specular_tint.rs | 2 +- examples/3d/spherical_area_lights.rs | 2 +- examples/3d/spotlight.rs | 2 +- examples/3d/ssao.rs | 2 +- examples/3d/transmission.rs | 2 +- examples/3d/volumetric_fog.rs | 2 +- examples/animation/animated_mesh.rs | 2 +- examples/animation/animated_mesh_control.rs | 2 +- examples/animation/animated_mesh_events.rs | 2 +- examples/animation/animated_transform.rs | 2 +- examples/animation/animation_graph.rs | 2 +- examples/animation/animation_masks.rs | 2 +- examples/animation/custom_skinned_mesh.rs | 2 +- examples/animation/morph_targets.rs | 2 +- examples/asset/multi_asset_sync.rs | 2 +- examples/gltf/custom_gltf_vertex_attribute.rs | 2 +- examples/gltf/gltf_skinned_mesh.rs | 2 +- examples/math/render_primitives.rs | 2 +- tests/3d/test_invalid_skinned_mesh.rs | 2 +- 32 files changed, 93 insertions(+), 55 deletions(-) diff --git a/crates/bevy_light/src/ambient_light.rs b/crates/bevy_light/src/ambient_light.rs index 92935e7e06d7a..c3aa0d0cd92aa 100644 --- a/crates/bevy_light/src/ambient_light.rs +++ b/crates/bevy_light/src/ambient_light.rs @@ -5,9 +5,42 @@ use bevy_reflect::prelude::*; /// An ambient light, which lights the entire scene equally. /// -/// This resource is inserted by the [`LightPlugin`] and by default it is set to a low ambient light. +/// It can be added to a camera to override the default `AmbientLightResource` ambient for that camera only. +#[derive(Component, Clone, Debug, Reflect)] +#[reflect(Component, Debug, Default, Clone)] +#[require(Camera)] +pub struct AmbientLightComponent { + pub color: Color, + + /// A direct scale factor multiplied with `color` before being passed to the shader. + /// + /// After applying this multiplier, the resulting value should be in units of [cd/m^2]. + /// + /// [cd/m^2]: https://en.wikipedia.org/wiki/Candela_per_square_metre + pub brightness: f32, + + /// Whether this ambient light has an effect on meshes with lightmaps. + /// + /// Set this to false if your lightmap baking tool bakes the ambient light + /// into the lightmaps, to avoid rendering that light twice. + /// + /// By default, this is set to true. + pub affects_lightmapped_meshes: bool, +} + +impl Default for AmbientLightComponent { + fn default() -> Self { + Self { + color: Color::WHITE, + brightness: 80.0, + affects_lightmapped_meshes: true, + } + } +} + +/// An ambient light, which lights the entire scene equally. /// -/// It can also be added to a camera to override the resource (or default) ambient for that camera only. +/// This resource is inserted by the [`LightPlugin`] and by default it is set to a low ambient light. /// /// # Examples /// @@ -16,16 +49,15 @@ use bevy_reflect::prelude::*; /// ``` /// # use bevy_ecs::system::ResMut; /// # use bevy_light::AmbientLight; -/// fn setup_ambient_light(mut ambient_light: ResMut) { +/// fn setup_ambient_light(mut ambient_light: ResMut) { /// ambient_light.brightness = 100.0; /// } /// ``` /// /// [`LightPlugin`]: crate::LightPlugin -#[derive(Resource, Component, Clone, Debug, Reflect)] -#[reflect(Resource, Component, Debug, Default, Clone)] -#[require(Camera)] -pub struct AmbientLight { +#[derive(Resource, Clone, Debug, Reflect)] +#[reflect(Resource, Debug, Default, Clone)] +pub struct AmbientLightResource { pub color: Color, /// A direct scale factor multiplied with `color` before being passed to the shader. @@ -44,7 +76,7 @@ pub struct AmbientLight { pub affects_lightmapped_meshes: bool, } -impl Default for AmbientLight { +impl Default for AmbientLightResource { fn default() -> Self { Self { color: Color::WHITE, @@ -54,8 +86,8 @@ impl Default for AmbientLight { } } -impl AmbientLight { - pub const NONE: AmbientLight = AmbientLight { +impl AmbientLightResource { + pub const NONE: AmbientLightResource = AmbientLightResource { color: Color::WHITE, brightness: 0.0, affects_lightmapped_meshes: true, diff --git a/crates/bevy_light/src/lib.rs b/crates/bevy_light/src/lib.rs index b4904d386ba87..064e4bba95987 100644 --- a/crates/bevy_light/src/lib.rs +++ b/crates/bevy_light/src/lib.rs @@ -25,7 +25,7 @@ use cluster::{ VisibleClusterableObjects, }; mod ambient_light; -pub use ambient_light::AmbientLight; +pub use ambient_light::{AmbientLightComponent, AmbientLightResource}; mod probe; pub use probe::{ AtmosphereEnvironmentMapLight, EnvironmentMapLight, GeneratedEnvironmentMapLight, @@ -57,8 +57,8 @@ pub use directional_light::{ pub mod prelude { #[doc(hidden)] pub use crate::{ - light_consts, AmbientLight, DirectionalLight, EnvironmentMapLight, - GeneratedEnvironmentMapLight, LightProbe, PointLight, SpotLight, + light_consts, AmbientLightComponent, AmbientLightResource, DirectionalLight, + EnvironmentMapLight, GeneratedEnvironmentMapLight, LightProbe, PointLight, SpotLight, }; } @@ -133,7 +133,7 @@ pub struct LightPlugin; impl Plugin for LightPlugin { fn build(&self, app: &mut App) { app.init_resource::() - .init_resource::() + .init_resource::() .init_resource::() .init_resource::() .configure_sets( diff --git a/crates/bevy_pbr/src/lib.rs b/crates/bevy_pbr/src/lib.rs index 6eaa1f99ddf30..38e9172b56f2a 100644 --- a/crates/bevy_pbr/src/lib.rs +++ b/crates/bevy_pbr/src/lib.rs @@ -49,8 +49,8 @@ use bevy_color::{Color, LinearRgba}; pub use atmosphere::*; use bevy_light::{ - AmbientLight, DirectionalLight, PointLight, ShadowFilteringMethod, SimulationLightSystems, - SpotLight, + AmbientLightComponent, DirectionalLight, PointLight, ShadowFilteringMethod, + SimulationLightSystems, SpotLight, }; use bevy_shader::{load_shader_library, ShaderRef}; pub use cluster::*; @@ -245,7 +245,7 @@ impl Plugin for PbrPlugin { SyncComponentPlugin::::default(), SyncComponentPlugin::::default(), SyncComponentPlugin::::default(), - SyncComponentPlugin::::default(), + SyncComponentPlugin::::default(), )) .add_plugins(AtmospherePlugin) .configure_sets( diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index 904be3164ec60..759f4dc5a2add 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -24,9 +24,10 @@ use bevy_light::cluster::assign::{calculate_cluster_factors, ClusterableObjectTy use bevy_light::cluster::GlobalVisibleClusterableObjects; use bevy_light::SunDisk; use bevy_light::{ - spot_light_clip_from_view, spot_light_world_from_view, AmbientLight, CascadeShadowConfig, - Cascades, DirectionalLight, DirectionalLightShadowMap, NotShadowCaster, PointLight, - PointLightShadowMap, ShadowFilteringMethod, SpotLight, VolumetricLight, + spot_light_clip_from_view, spot_light_world_from_view, AmbientLightComponent, + AmbientLightResource, CascadeShadowConfig, Cascades, DirectionalLight, + DirectionalLightShadowMap, NotShadowCaster, PointLight, PointLightShadowMap, + ShadowFilteringMethod, SpotLight, VolumetricLight, }; use bevy_math::{ops, Mat4, UVec4, Vec3, Vec3Swizzles, Vec4, Vec4Swizzles}; use bevy_platform::collections::{HashMap, HashSet}; @@ -248,8 +249,8 @@ pub fn extract_shadow_filtering_method( // foreign trait ExtractResource on foreign type AmbientLight pub fn extract_ambient_light_resource( mut commands: Commands, - main_resource: Extract>>, - target_resource: Option>, + main_resource: Extract>>, + target_resource: Option>, ) { if let Some(main_resource) = main_resource.as_ref() { if let Some(mut target_resource) = target_resource { @@ -267,7 +268,7 @@ pub fn extract_ambient_light_resource( pub fn extract_ambient_light( mut commands: Commands, mut previous_len: Local, - query: Extract>, + query: Extract>, ) { let mut values = Vec::with_capacity(*previous_len); for (entity, query_item) in &query { @@ -716,11 +717,11 @@ pub fn prepare_lights( &ExtractedClusterConfig, Option<&RenderLayers>, Has, - Option<&AmbientLight>, + Option<&AmbientLightComponent>, ), With, >, - ambient_light: Res, + ambient_light: Res, point_light_shadow_map: Res, directional_light_shadow_map: Res, mut shadow_render_phases: ResMut>, @@ -1150,6 +1151,11 @@ pub fn prepare_lights( ); let n_clusters = clusters.dimensions.x * clusters.dimensions.y * clusters.dimensions.z; + let ambient_light = AmbientLightComponent { + color: ambient_light.color, + brightness: ambient_light.brightness, + affects_lightmapped_meshes: ambient_light.affects_lightmapped_meshes, + }; let ambient_light = maybe_ambient_override.unwrap_or(&ambient_light); let mut gpu_directional_lights = [GpuDirectionalLight::default(); MAX_DIRECTIONAL_LIGHTS]; diff --git a/examples/3d/auto_exposure.rs b/examples/3d/auto_exposure.rs index 5d9e42c9310c8..4bc482c3a1fd5 100644 --- a/examples/3d/auto_exposure.rs +++ b/examples/3d/auto_exposure.rs @@ -97,7 +97,7 @@ fn setup( } } - commands.insert_resource(AmbientLight { + commands.insert_resource(AmbientLightResource { color: Color::WHITE, brightness: 0.0, ..default() diff --git a/examples/3d/fog.rs b/examples/3d/fog.rs index 9a5e1315b8575..960c331effe6a 100644 --- a/examples/3d/fog.rs +++ b/examples/3d/fog.rs @@ -29,7 +29,7 @@ use bevy::{ fn main() { App::new() - .insert_resource(AmbientLight::NONE) + .insert_resource(AmbientLightResource::NONE) .add_plugins(DefaultPlugins) .add_systems( Startup, diff --git a/examples/3d/fog_volumes.rs b/examples/3d/fog_volumes.rs index 2789644b2171a..251bd138b288d 100644 --- a/examples/3d/fog_volumes.rs +++ b/examples/3d/fog_volumes.rs @@ -22,7 +22,7 @@ fn main() { }), ..default() })) - .insert_resource(AmbientLight::NONE) + .insert_resource(AmbientLightResource::NONE) .add_systems(Startup, setup) .add_systems(Update, rotate_camera) .run(); diff --git a/examples/3d/irradiance_volumes.rs b/examples/3d/irradiance_volumes.rs index f7500c7e488a3..28f707d5fe110 100644 --- a/examples/3d/irradiance_volumes.rs +++ b/examples/3d/irradiance_volumes.rs @@ -157,7 +157,7 @@ fn main() { .add_plugins(MaterialPlugin::::default()) .init_resource::() .init_resource::() - .insert_resource(AmbientLight { + .insert_resource(AmbientLightResource { color: Color::WHITE, brightness: 0.0, ..default() @@ -414,7 +414,7 @@ fn toggle_irradiance_volumes( light_probe_query: Query>, mut app_status: ResMut, assets: Res, - mut ambient_light: ResMut, + mut ambient_light: ResMut, ) { if !keyboard.just_pressed(KeyCode::Space) { return; diff --git a/examples/3d/lighting.rs b/examples/3d/lighting.rs index a23a68885abb3..af049872fbe79 100644 --- a/examples/3d/lighting.rs +++ b/examples/3d/lighting.rs @@ -120,7 +120,7 @@ fn setup( // ambient light // ambient lights' brightnesses are measured in candela per meter square, calculable as (color * brightness) - commands.insert_resource(AmbientLight { + commands.insert_resource(AmbientLightResource { color: ORANGE_RED.into(), brightness: 200.0, ..default() @@ -290,7 +290,7 @@ fn update_exposure( fn toggle_ambient_light( key_input: Res>, - mut ambient_light: ResMut, + mut ambient_light: ResMut, text: Single>, mut writer: TextUiWriter, ) { diff --git a/examples/3d/lightmaps.rs b/examples/3d/lightmaps.rs index c994741150ad3..df9f9b15c221a 100644 --- a/examples/3d/lightmaps.rs +++ b/examples/3d/lightmaps.rs @@ -27,7 +27,7 @@ fn main() { let mut app = App::new(); app.add_plugins(DefaultPlugins) - .insert_resource(AmbientLight::NONE); + .insert_resource(AmbientLightResource::NONE); if args.deferred { app.insert_resource(DefaultOpaqueRendererMethod::deferred()); diff --git a/examples/3d/mixed_lighting.rs b/examples/3d/mixed_lighting.rs index 73ced56408eed..dfef30a7d6c6d 100644 --- a/examples/3d/mixed_lighting.rs +++ b/examples/3d/mixed_lighting.rs @@ -124,7 +124,7 @@ fn main() { ..default() })) .add_plugins(MeshPickingPlugin) - .insert_resource(AmbientLight { + .insert_resource(AmbientLightResource { color: ClearColor::default().0, brightness: 10000.0, affects_lightmapped_meshes: true, diff --git a/examples/3d/motion_blur.rs b/examples/3d/motion_blur.rs index 92c5d8cd72cb7..1a65dd100cf12 100644 --- a/examples/3d/motion_blur.rs +++ b/examples/3d/motion_blur.rs @@ -57,7 +57,7 @@ fn setup_scene( mut meshes: ResMut>, mut materials: ResMut>, ) { - commands.insert_resource(AmbientLight { + commands.insert_resource(AmbientLightResource { color: Color::WHITE, brightness: 300.0, ..default() diff --git a/examples/3d/skybox.rs b/examples/3d/skybox.rs index 31fdcc8872262..28c70dbe08297 100644 --- a/examples/3d/skybox.rs +++ b/examples/3d/skybox.rs @@ -85,7 +85,7 @@ fn setup(mut commands: Commands, asset_server: Res) { // ambient light // NOTE: The ambient light is used to scale how bright the environment map is so with a bright // environment map, use an appropriate color and brightness to match - commands.insert_resource(AmbientLight { + commands.insert_resource(AmbientLightResource { color: Color::srgb_u8(210, 220, 240), brightness: 1.0, ..default() diff --git a/examples/3d/specular_tint.rs b/examples/3d/specular_tint.rs index 154226713201f..57a8f137ba798 100644 --- a/examples/3d/specular_tint.rs +++ b/examples/3d/specular_tint.rs @@ -59,7 +59,7 @@ fn main() { })) .init_resource::() .init_resource::() - .insert_resource(AmbientLight { + .insert_resource(AmbientLightResource { color: Color::BLACK, brightness: 0.0, ..default() diff --git a/examples/3d/spherical_area_lights.rs b/examples/3d/spherical_area_lights.rs index c3e945a8f3492..f7d81e92b9cf3 100644 --- a/examples/3d/spherical_area_lights.rs +++ b/examples/3d/spherical_area_lights.rs @@ -4,7 +4,7 @@ use bevy::prelude::*; fn main() { App::new() - .insert_resource(AmbientLight { + .insert_resource(AmbientLightResource { brightness: 60.0, ..default() }) diff --git a/examples/3d/spotlight.rs b/examples/3d/spotlight.rs index efdb44680aee5..fe62f1a4bbe3b 100644 --- a/examples/3d/spotlight.rs +++ b/examples/3d/spotlight.rs @@ -21,7 +21,7 @@ Rotate Camera: Left and Right Arrows"; fn main() { App::new() - .insert_resource(AmbientLight { + .insert_resource(AmbientLightResource { brightness: 20.0, ..default() }) diff --git a/examples/3d/ssao.rs b/examples/3d/ssao.rs index 129979b0fbb3d..84da390c071af 100644 --- a/examples/3d/ssao.rs +++ b/examples/3d/ssao.rs @@ -11,7 +11,7 @@ use std::f32::consts::PI; fn main() { App::new() - .insert_resource(AmbientLight { + .insert_resource(AmbientLightResource { brightness: 1000., ..default() }) diff --git a/examples/3d/transmission.rs b/examples/3d/transmission.rs index 5db06e04edad2..1abf0a90e2c04 100644 --- a/examples/3d/transmission.rs +++ b/examples/3d/transmission.rs @@ -47,7 +47,7 @@ fn main() { .add_plugins(DefaultPlugins) .insert_resource(ClearColor(Color::BLACK)) .insert_resource(PointLightShadowMap { size: 2048 }) - .insert_resource(AmbientLight { + .insert_resource(AmbientLightResource { brightness: 0.0, ..default() }) diff --git a/examples/3d/volumetric_fog.rs b/examples/3d/volumetric_fog.rs index c8c47ef73338d..f549ada1ac59c 100644 --- a/examples/3d/volumetric_fog.rs +++ b/examples/3d/volumetric_fog.rs @@ -47,7 +47,7 @@ fn main() { blue: 0.02, alpha: 1.0, }))) - .insert_resource(AmbientLight::NONE) + .insert_resource(AmbientLightResource::NONE) .init_resource::() .add_systems(Startup, setup) .add_systems(Update, tweak_scene) diff --git a/examples/animation/animated_mesh.rs b/examples/animation/animated_mesh.rs index 466d53be2ff22..1b86730ea610f 100644 --- a/examples/animation/animated_mesh.rs +++ b/examples/animation/animated_mesh.rs @@ -9,7 +9,7 @@ const GLTF_PATH: &str = "models/animated/Fox.glb"; fn main() { App::new() - .insert_resource(AmbientLight { + .insert_resource(AmbientLightResource { color: Color::WHITE, brightness: 2000., ..default() diff --git a/examples/animation/animated_mesh_control.rs b/examples/animation/animated_mesh_control.rs index 3029722c1aa66..3080467285a4e 100644 --- a/examples/animation/animated_mesh_control.rs +++ b/examples/animation/animated_mesh_control.rs @@ -8,7 +8,7 @@ const FOX_PATH: &str = "models/animated/Fox.glb"; fn main() { App::new() - .insert_resource(AmbientLight { + .insert_resource(AmbientLightResource { color: Color::WHITE, brightness: 2000., ..default() diff --git a/examples/animation/animated_mesh_events.rs b/examples/animation/animated_mesh_events.rs index 5898807cf45a3..4c88f87054a2e 100644 --- a/examples/animation/animated_mesh_events.rs +++ b/examples/animation/animated_mesh_events.rs @@ -15,7 +15,7 @@ const FOX_PATH: &str = "models/animated/Fox.glb"; fn main() { App::new() - .insert_resource(AmbientLight { + .insert_resource(AmbientLightResource { color: Color::WHITE, brightness: 2000., ..default() diff --git a/examples/animation/animated_transform.rs b/examples/animation/animated_transform.rs index bd1b7b3c986e9..4373af75dd1bc 100644 --- a/examples/animation/animated_transform.rs +++ b/examples/animation/animated_transform.rs @@ -10,7 +10,7 @@ use bevy::{ fn main() { App::new() .add_plugins(DefaultPlugins) - .insert_resource(AmbientLight { + .insert_resource(AmbientLightResource { color: Color::WHITE, brightness: 150.0, ..default() diff --git a/examples/animation/animation_graph.rs b/examples/animation/animation_graph.rs index bc4b8b2bdf3a1..4eba44de2226a 100644 --- a/examples/animation/animation_graph.rs +++ b/examples/animation/animation_graph.rs @@ -88,7 +88,7 @@ fn main() { (handle_weight_drag, update_ui, sync_weights).chain(), ) .insert_resource(args) - .insert_resource(AmbientLight { + .insert_resource(AmbientLightResource { color: WHITE.into(), brightness: 100.0, ..default() diff --git a/examples/animation/animation_masks.rs b/examples/animation/animation_masks.rs index 4566d06034e33..8769c69c362c4 100644 --- a/examples/animation/animation_masks.rs +++ b/examples/animation/animation_masks.rs @@ -105,7 +105,7 @@ fn main() { .add_systems(Update, setup_animation_graph_once_loaded) .add_systems(Update, handle_button_toggles) .add_systems(Update, update_ui) - .insert_resource(AmbientLight { + .insert_resource(AmbientLightResource { color: WHITE.into(), brightness: 100.0, ..default() diff --git a/examples/animation/custom_skinned_mesh.rs b/examples/animation/custom_skinned_mesh.rs index c706e07be9b64..6956eb2cbfd32 100644 --- a/examples/animation/custom_skinned_mesh.rs +++ b/examples/animation/custom_skinned_mesh.rs @@ -18,7 +18,7 @@ use rand_chacha::ChaCha8Rng; fn main() { App::new() .add_plugins(DefaultPlugins) - .insert_resource(AmbientLight { + .insert_resource(AmbientLightResource { brightness: 3000.0, ..default() }) diff --git a/examples/animation/morph_targets.rs b/examples/animation/morph_targets.rs index 27ae52e030ef8..2c53d442240e5 100644 --- a/examples/animation/morph_targets.rs +++ b/examples/animation/morph_targets.rs @@ -10,7 +10,7 @@ const GLTF_PATH: &str = "models/animated/MorphStressTest.gltf"; fn main() { App::new() .add_plugins(DefaultPlugins) - .insert_resource(AmbientLight { + .insert_resource(AmbientLightResource { brightness: 150.0, ..default() }) diff --git a/examples/asset/multi_asset_sync.rs b/examples/asset/multi_asset_sync.rs index ef91c29144615..6966049aadb5d 100644 --- a/examples/asset/multi_asset_sync.rs +++ b/examples/asset/multi_asset_sync.rs @@ -17,7 +17,7 @@ fn main() { App::new() .add_plugins(DefaultPlugins) .init_state::() - .insert_resource(AmbientLight { + .insert_resource(AmbientLightResource { color: Color::WHITE, brightness: 2000., ..default() diff --git a/examples/gltf/custom_gltf_vertex_attribute.rs b/examples/gltf/custom_gltf_vertex_attribute.rs index cba292f7a1e5a..39880a63d27bb 100644 --- a/examples/gltf/custom_gltf_vertex_attribute.rs +++ b/examples/gltf/custom_gltf_vertex_attribute.rs @@ -23,7 +23,7 @@ const ATTRIBUTE_BARYCENTRIC: MeshVertexAttribute = fn main() { App::new() - .insert_resource(AmbientLight { + .insert_resource(AmbientLightResource { color: Color::WHITE, brightness: 1.0 / 5.0f32, ..default() diff --git a/examples/gltf/gltf_skinned_mesh.rs b/examples/gltf/gltf_skinned_mesh.rs index aa88728df938a..070b131543081 100644 --- a/examples/gltf/gltf_skinned_mesh.rs +++ b/examples/gltf/gltf_skinned_mesh.rs @@ -8,7 +8,7 @@ use bevy::{math::ops, mesh::skinning::SkinnedMesh, prelude::*}; fn main() { App::new() .add_plugins(DefaultPlugins) - .insert_resource(AmbientLight { + .insert_resource(AmbientLightResource { brightness: 750.0, ..default() }) diff --git a/examples/math/render_primitives.rs b/examples/math/render_primitives.rs index b33700ea18157..7bb14ef306d74 100644 --- a/examples/math/render_primitives.rs +++ b/examples/math/render_primitives.rs @@ -281,7 +281,7 @@ fn setup_cameras(mut commands: Commands) { )); } -fn setup_ambient_light(mut ambient_light: ResMut) { +fn setup_ambient_light(mut ambient_light: ResMut) { ambient_light.brightness = 50.0; } diff --git a/tests/3d/test_invalid_skinned_mesh.rs b/tests/3d/test_invalid_skinned_mesh.rs index a5e5b25feef2e..122e46654bf54 100644 --- a/tests/3d/test_invalid_skinned_mesh.rs +++ b/tests/3d/test_invalid_skinned_mesh.rs @@ -16,7 +16,7 @@ use core::f32::consts::TAU; fn main() { App::new() .add_plugins(DefaultPlugins) - .insert_resource(AmbientLight { + .insert_resource(AmbientLightResource { brightness: 20_000.0, ..default() }) From 9bff50fec104d6781fa99fbe00ecd574afc4138f Mon Sep 17 00:00:00 2001 From: Trashtalk Date: Sat, 18 Oct 2025 23:03:29 +0200 Subject: [PATCH 2/9] better names --- crates/bevy_light/src/ambient_light.rs | 12 ++++++------ crates/bevy_light/src/lib.rs | 6 +++--- crates/bevy_pbr/src/lib.rs | 4 ++-- crates/bevy_pbr/src/render/light.rs | 19 +++++++++---------- examples/3d/auto_exposure.rs | 2 +- examples/3d/fog.rs | 2 +- examples/3d/fog_volumes.rs | 2 +- examples/3d/irradiance_volumes.rs | 4 ++-- examples/3d/lighting.rs | 4 ++-- examples/3d/lightmaps.rs | 2 +- examples/3d/mixed_lighting.rs | 2 +- examples/3d/motion_blur.rs | 2 +- examples/3d/skybox.rs | 2 +- examples/3d/specular_tint.rs | 2 +- examples/3d/spherical_area_lights.rs | 2 +- examples/3d/spotlight.rs | 2 +- examples/3d/ssao.rs | 2 +- examples/3d/transmission.rs | 2 +- examples/3d/volumetric_fog.rs | 2 +- examples/animation/animated_mesh.rs | 2 +- examples/animation/animated_mesh_control.rs | 2 +- examples/animation/animated_mesh_events.rs | 2 +- examples/animation/animated_transform.rs | 2 +- examples/animation/animation_graph.rs | 2 +- examples/animation/animation_masks.rs | 2 +- examples/animation/custom_skinned_mesh.rs | 2 +- examples/animation/morph_targets.rs | 2 +- examples/asset/multi_asset_sync.rs | 2 +- examples/gltf/custom_gltf_vertex_attribute.rs | 2 +- examples/gltf/gltf_skinned_mesh.rs | 2 +- examples/math/render_primitives.rs | 2 +- tests/3d/test_invalid_skinned_mesh.rs | 2 +- 32 files changed, 50 insertions(+), 51 deletions(-) diff --git a/crates/bevy_light/src/ambient_light.rs b/crates/bevy_light/src/ambient_light.rs index c3aa0d0cd92aa..f59d670d32d64 100644 --- a/crates/bevy_light/src/ambient_light.rs +++ b/crates/bevy_light/src/ambient_light.rs @@ -9,7 +9,7 @@ use bevy_reflect::prelude::*; #[derive(Component, Clone, Debug, Reflect)] #[reflect(Component, Debug, Default, Clone)] #[require(Camera)] -pub struct AmbientLightComponent { +pub struct AmbientLightOverride { pub color: Color, /// A direct scale factor multiplied with `color` before being passed to the shader. @@ -28,7 +28,7 @@ pub struct AmbientLightComponent { pub affects_lightmapped_meshes: bool, } -impl Default for AmbientLightComponent { +impl Default for AmbientLightOverride { fn default() -> Self { Self { color: Color::WHITE, @@ -57,7 +57,7 @@ impl Default for AmbientLightComponent { /// [`LightPlugin`]: crate::LightPlugin #[derive(Resource, Clone, Debug, Reflect)] #[reflect(Resource, Debug, Default, Clone)] -pub struct AmbientLightResource { +pub struct AmbientLight { pub color: Color, /// A direct scale factor multiplied with `color` before being passed to the shader. @@ -76,7 +76,7 @@ pub struct AmbientLightResource { pub affects_lightmapped_meshes: bool, } -impl Default for AmbientLightResource { +impl Default for AmbientLight { fn default() -> Self { Self { color: Color::WHITE, @@ -86,8 +86,8 @@ impl Default for AmbientLightResource { } } -impl AmbientLightResource { - pub const NONE: AmbientLightResource = AmbientLightResource { +impl AmbientLight { + pub const NONE: AmbientLight = AmbientLight { color: Color::WHITE, brightness: 0.0, affects_lightmapped_meshes: true, diff --git a/crates/bevy_light/src/lib.rs b/crates/bevy_light/src/lib.rs index 064e4bba95987..32f98cd1b036b 100644 --- a/crates/bevy_light/src/lib.rs +++ b/crates/bevy_light/src/lib.rs @@ -25,7 +25,7 @@ use cluster::{ VisibleClusterableObjects, }; mod ambient_light; -pub use ambient_light::{AmbientLightComponent, AmbientLightResource}; +pub use ambient_light::{AmbientLightOverride, AmbientLight}; mod probe; pub use probe::{ AtmosphereEnvironmentMapLight, EnvironmentMapLight, GeneratedEnvironmentMapLight, @@ -57,7 +57,7 @@ pub use directional_light::{ pub mod prelude { #[doc(hidden)] pub use crate::{ - light_consts, AmbientLightComponent, AmbientLightResource, DirectionalLight, + light_consts, AmbientLightOverride, AmbientLight, DirectionalLight, EnvironmentMapLight, GeneratedEnvironmentMapLight, LightProbe, PointLight, SpotLight, }; } @@ -133,7 +133,7 @@ pub struct LightPlugin; impl Plugin for LightPlugin { fn build(&self, app: &mut App) { app.init_resource::() - .init_resource::() + .init_resource::() .init_resource::() .init_resource::() .configure_sets( diff --git a/crates/bevy_pbr/src/lib.rs b/crates/bevy_pbr/src/lib.rs index 38e9172b56f2a..4244d64a240f2 100644 --- a/crates/bevy_pbr/src/lib.rs +++ b/crates/bevy_pbr/src/lib.rs @@ -49,7 +49,7 @@ use bevy_color::{Color, LinearRgba}; pub use atmosphere::*; use bevy_light::{ - AmbientLightComponent, DirectionalLight, PointLight, ShadowFilteringMethod, + AmbientLightOverride, DirectionalLight, PointLight, ShadowFilteringMethod, SimulationLightSystems, SpotLight, }; use bevy_shader::{load_shader_library, ShaderRef}; @@ -245,7 +245,7 @@ impl Plugin for PbrPlugin { SyncComponentPlugin::::default(), SyncComponentPlugin::::default(), SyncComponentPlugin::::default(), - SyncComponentPlugin::::default(), + SyncComponentPlugin::::default(), )) .add_plugins(AtmospherePlugin) .configure_sets( diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index 759f4dc5a2add..40e56a181cfc5 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -24,10 +24,9 @@ use bevy_light::cluster::assign::{calculate_cluster_factors, ClusterableObjectTy use bevy_light::cluster::GlobalVisibleClusterableObjects; use bevy_light::SunDisk; use bevy_light::{ - spot_light_clip_from_view, spot_light_world_from_view, AmbientLightComponent, - AmbientLightResource, CascadeShadowConfig, Cascades, DirectionalLight, - DirectionalLightShadowMap, NotShadowCaster, PointLight, PointLightShadowMap, - ShadowFilteringMethod, SpotLight, VolumetricLight, + spot_light_clip_from_view, spot_light_world_from_view, AmbientLight, AmbientLightOverride, + CascadeShadowConfig, Cascades, DirectionalLight, DirectionalLightShadowMap, NotShadowCaster, + PointLight, PointLightShadowMap, ShadowFilteringMethod, SpotLight, VolumetricLight, }; use bevy_math::{ops, Mat4, UVec4, Vec3, Vec3Swizzles, Vec4, Vec4Swizzles}; use bevy_platform::collections::{HashMap, HashSet}; @@ -249,8 +248,8 @@ pub fn extract_shadow_filtering_method( // foreign trait ExtractResource on foreign type AmbientLight pub fn extract_ambient_light_resource( mut commands: Commands, - main_resource: Extract>>, - target_resource: Option>, + main_resource: Extract>>, + target_resource: Option>, ) { if let Some(main_resource) = main_resource.as_ref() { if let Some(mut target_resource) = target_resource { @@ -268,7 +267,7 @@ pub fn extract_ambient_light_resource( pub fn extract_ambient_light( mut commands: Commands, mut previous_len: Local, - query: Extract>, + query: Extract>, ) { let mut values = Vec::with_capacity(*previous_len); for (entity, query_item) in &query { @@ -717,11 +716,11 @@ pub fn prepare_lights( &ExtractedClusterConfig, Option<&RenderLayers>, Has, - Option<&AmbientLightComponent>, + Option<&AmbientLightOverride>, ), With, >, - ambient_light: Res, + ambient_light: Res, point_light_shadow_map: Res, directional_light_shadow_map: Res, mut shadow_render_phases: ResMut>, @@ -1151,7 +1150,7 @@ pub fn prepare_lights( ); let n_clusters = clusters.dimensions.x * clusters.dimensions.y * clusters.dimensions.z; - let ambient_light = AmbientLightComponent { + let ambient_light = AmbientLightOverride { color: ambient_light.color, brightness: ambient_light.brightness, affects_lightmapped_meshes: ambient_light.affects_lightmapped_meshes, diff --git a/examples/3d/auto_exposure.rs b/examples/3d/auto_exposure.rs index 4bc482c3a1fd5..5d9e42c9310c8 100644 --- a/examples/3d/auto_exposure.rs +++ b/examples/3d/auto_exposure.rs @@ -97,7 +97,7 @@ fn setup( } } - commands.insert_resource(AmbientLightResource { + commands.insert_resource(AmbientLight { color: Color::WHITE, brightness: 0.0, ..default() diff --git a/examples/3d/fog.rs b/examples/3d/fog.rs index 960c331effe6a..9a5e1315b8575 100644 --- a/examples/3d/fog.rs +++ b/examples/3d/fog.rs @@ -29,7 +29,7 @@ use bevy::{ fn main() { App::new() - .insert_resource(AmbientLightResource::NONE) + .insert_resource(AmbientLight::NONE) .add_plugins(DefaultPlugins) .add_systems( Startup, diff --git a/examples/3d/fog_volumes.rs b/examples/3d/fog_volumes.rs index 251bd138b288d..2789644b2171a 100644 --- a/examples/3d/fog_volumes.rs +++ b/examples/3d/fog_volumes.rs @@ -22,7 +22,7 @@ fn main() { }), ..default() })) - .insert_resource(AmbientLightResource::NONE) + .insert_resource(AmbientLight::NONE) .add_systems(Startup, setup) .add_systems(Update, rotate_camera) .run(); diff --git a/examples/3d/irradiance_volumes.rs b/examples/3d/irradiance_volumes.rs index 28f707d5fe110..f7500c7e488a3 100644 --- a/examples/3d/irradiance_volumes.rs +++ b/examples/3d/irradiance_volumes.rs @@ -157,7 +157,7 @@ fn main() { .add_plugins(MaterialPlugin::::default()) .init_resource::() .init_resource::() - .insert_resource(AmbientLightResource { + .insert_resource(AmbientLight { color: Color::WHITE, brightness: 0.0, ..default() @@ -414,7 +414,7 @@ fn toggle_irradiance_volumes( light_probe_query: Query>, mut app_status: ResMut, assets: Res, - mut ambient_light: ResMut, + mut ambient_light: ResMut, ) { if !keyboard.just_pressed(KeyCode::Space) { return; diff --git a/examples/3d/lighting.rs b/examples/3d/lighting.rs index af049872fbe79..a23a68885abb3 100644 --- a/examples/3d/lighting.rs +++ b/examples/3d/lighting.rs @@ -120,7 +120,7 @@ fn setup( // ambient light // ambient lights' brightnesses are measured in candela per meter square, calculable as (color * brightness) - commands.insert_resource(AmbientLightResource { + commands.insert_resource(AmbientLight { color: ORANGE_RED.into(), brightness: 200.0, ..default() @@ -290,7 +290,7 @@ fn update_exposure( fn toggle_ambient_light( key_input: Res>, - mut ambient_light: ResMut, + mut ambient_light: ResMut, text: Single>, mut writer: TextUiWriter, ) { diff --git a/examples/3d/lightmaps.rs b/examples/3d/lightmaps.rs index df9f9b15c221a..c994741150ad3 100644 --- a/examples/3d/lightmaps.rs +++ b/examples/3d/lightmaps.rs @@ -27,7 +27,7 @@ fn main() { let mut app = App::new(); app.add_plugins(DefaultPlugins) - .insert_resource(AmbientLightResource::NONE); + .insert_resource(AmbientLight::NONE); if args.deferred { app.insert_resource(DefaultOpaqueRendererMethod::deferred()); diff --git a/examples/3d/mixed_lighting.rs b/examples/3d/mixed_lighting.rs index dfef30a7d6c6d..73ced56408eed 100644 --- a/examples/3d/mixed_lighting.rs +++ b/examples/3d/mixed_lighting.rs @@ -124,7 +124,7 @@ fn main() { ..default() })) .add_plugins(MeshPickingPlugin) - .insert_resource(AmbientLightResource { + .insert_resource(AmbientLight { color: ClearColor::default().0, brightness: 10000.0, affects_lightmapped_meshes: true, diff --git a/examples/3d/motion_blur.rs b/examples/3d/motion_blur.rs index 1a65dd100cf12..92c5d8cd72cb7 100644 --- a/examples/3d/motion_blur.rs +++ b/examples/3d/motion_blur.rs @@ -57,7 +57,7 @@ fn setup_scene( mut meshes: ResMut>, mut materials: ResMut>, ) { - commands.insert_resource(AmbientLightResource { + commands.insert_resource(AmbientLight { color: Color::WHITE, brightness: 300.0, ..default() diff --git a/examples/3d/skybox.rs b/examples/3d/skybox.rs index 28c70dbe08297..31fdcc8872262 100644 --- a/examples/3d/skybox.rs +++ b/examples/3d/skybox.rs @@ -85,7 +85,7 @@ fn setup(mut commands: Commands, asset_server: Res) { // ambient light // NOTE: The ambient light is used to scale how bright the environment map is so with a bright // environment map, use an appropriate color and brightness to match - commands.insert_resource(AmbientLightResource { + commands.insert_resource(AmbientLight { color: Color::srgb_u8(210, 220, 240), brightness: 1.0, ..default() diff --git a/examples/3d/specular_tint.rs b/examples/3d/specular_tint.rs index 57a8f137ba798..154226713201f 100644 --- a/examples/3d/specular_tint.rs +++ b/examples/3d/specular_tint.rs @@ -59,7 +59,7 @@ fn main() { })) .init_resource::() .init_resource::() - .insert_resource(AmbientLightResource { + .insert_resource(AmbientLight { color: Color::BLACK, brightness: 0.0, ..default() diff --git a/examples/3d/spherical_area_lights.rs b/examples/3d/spherical_area_lights.rs index f7d81e92b9cf3..c3e945a8f3492 100644 --- a/examples/3d/spherical_area_lights.rs +++ b/examples/3d/spherical_area_lights.rs @@ -4,7 +4,7 @@ use bevy::prelude::*; fn main() { App::new() - .insert_resource(AmbientLightResource { + .insert_resource(AmbientLight { brightness: 60.0, ..default() }) diff --git a/examples/3d/spotlight.rs b/examples/3d/spotlight.rs index fe62f1a4bbe3b..efdb44680aee5 100644 --- a/examples/3d/spotlight.rs +++ b/examples/3d/spotlight.rs @@ -21,7 +21,7 @@ Rotate Camera: Left and Right Arrows"; fn main() { App::new() - .insert_resource(AmbientLightResource { + .insert_resource(AmbientLight { brightness: 20.0, ..default() }) diff --git a/examples/3d/ssao.rs b/examples/3d/ssao.rs index 84da390c071af..129979b0fbb3d 100644 --- a/examples/3d/ssao.rs +++ b/examples/3d/ssao.rs @@ -11,7 +11,7 @@ use std::f32::consts::PI; fn main() { App::new() - .insert_resource(AmbientLightResource { + .insert_resource(AmbientLight { brightness: 1000., ..default() }) diff --git a/examples/3d/transmission.rs b/examples/3d/transmission.rs index 1abf0a90e2c04..5db06e04edad2 100644 --- a/examples/3d/transmission.rs +++ b/examples/3d/transmission.rs @@ -47,7 +47,7 @@ fn main() { .add_plugins(DefaultPlugins) .insert_resource(ClearColor(Color::BLACK)) .insert_resource(PointLightShadowMap { size: 2048 }) - .insert_resource(AmbientLightResource { + .insert_resource(AmbientLight { brightness: 0.0, ..default() }) diff --git a/examples/3d/volumetric_fog.rs b/examples/3d/volumetric_fog.rs index f549ada1ac59c..c8c47ef73338d 100644 --- a/examples/3d/volumetric_fog.rs +++ b/examples/3d/volumetric_fog.rs @@ -47,7 +47,7 @@ fn main() { blue: 0.02, alpha: 1.0, }))) - .insert_resource(AmbientLightResource::NONE) + .insert_resource(AmbientLight::NONE) .init_resource::() .add_systems(Startup, setup) .add_systems(Update, tweak_scene) diff --git a/examples/animation/animated_mesh.rs b/examples/animation/animated_mesh.rs index 1b86730ea610f..466d53be2ff22 100644 --- a/examples/animation/animated_mesh.rs +++ b/examples/animation/animated_mesh.rs @@ -9,7 +9,7 @@ const GLTF_PATH: &str = "models/animated/Fox.glb"; fn main() { App::new() - .insert_resource(AmbientLightResource { + .insert_resource(AmbientLight { color: Color::WHITE, brightness: 2000., ..default() diff --git a/examples/animation/animated_mesh_control.rs b/examples/animation/animated_mesh_control.rs index 3080467285a4e..3029722c1aa66 100644 --- a/examples/animation/animated_mesh_control.rs +++ b/examples/animation/animated_mesh_control.rs @@ -8,7 +8,7 @@ const FOX_PATH: &str = "models/animated/Fox.glb"; fn main() { App::new() - .insert_resource(AmbientLightResource { + .insert_resource(AmbientLight { color: Color::WHITE, brightness: 2000., ..default() diff --git a/examples/animation/animated_mesh_events.rs b/examples/animation/animated_mesh_events.rs index 4c88f87054a2e..5898807cf45a3 100644 --- a/examples/animation/animated_mesh_events.rs +++ b/examples/animation/animated_mesh_events.rs @@ -15,7 +15,7 @@ const FOX_PATH: &str = "models/animated/Fox.glb"; fn main() { App::new() - .insert_resource(AmbientLightResource { + .insert_resource(AmbientLight { color: Color::WHITE, brightness: 2000., ..default() diff --git a/examples/animation/animated_transform.rs b/examples/animation/animated_transform.rs index 4373af75dd1bc..bd1b7b3c986e9 100644 --- a/examples/animation/animated_transform.rs +++ b/examples/animation/animated_transform.rs @@ -10,7 +10,7 @@ use bevy::{ fn main() { App::new() .add_plugins(DefaultPlugins) - .insert_resource(AmbientLightResource { + .insert_resource(AmbientLight { color: Color::WHITE, brightness: 150.0, ..default() diff --git a/examples/animation/animation_graph.rs b/examples/animation/animation_graph.rs index 4eba44de2226a..bc4b8b2bdf3a1 100644 --- a/examples/animation/animation_graph.rs +++ b/examples/animation/animation_graph.rs @@ -88,7 +88,7 @@ fn main() { (handle_weight_drag, update_ui, sync_weights).chain(), ) .insert_resource(args) - .insert_resource(AmbientLightResource { + .insert_resource(AmbientLight { color: WHITE.into(), brightness: 100.0, ..default() diff --git a/examples/animation/animation_masks.rs b/examples/animation/animation_masks.rs index 8769c69c362c4..4566d06034e33 100644 --- a/examples/animation/animation_masks.rs +++ b/examples/animation/animation_masks.rs @@ -105,7 +105,7 @@ fn main() { .add_systems(Update, setup_animation_graph_once_loaded) .add_systems(Update, handle_button_toggles) .add_systems(Update, update_ui) - .insert_resource(AmbientLightResource { + .insert_resource(AmbientLight { color: WHITE.into(), brightness: 100.0, ..default() diff --git a/examples/animation/custom_skinned_mesh.rs b/examples/animation/custom_skinned_mesh.rs index 6956eb2cbfd32..c706e07be9b64 100644 --- a/examples/animation/custom_skinned_mesh.rs +++ b/examples/animation/custom_skinned_mesh.rs @@ -18,7 +18,7 @@ use rand_chacha::ChaCha8Rng; fn main() { App::new() .add_plugins(DefaultPlugins) - .insert_resource(AmbientLightResource { + .insert_resource(AmbientLight { brightness: 3000.0, ..default() }) diff --git a/examples/animation/morph_targets.rs b/examples/animation/morph_targets.rs index 2c53d442240e5..27ae52e030ef8 100644 --- a/examples/animation/morph_targets.rs +++ b/examples/animation/morph_targets.rs @@ -10,7 +10,7 @@ const GLTF_PATH: &str = "models/animated/MorphStressTest.gltf"; fn main() { App::new() .add_plugins(DefaultPlugins) - .insert_resource(AmbientLightResource { + .insert_resource(AmbientLight { brightness: 150.0, ..default() }) diff --git a/examples/asset/multi_asset_sync.rs b/examples/asset/multi_asset_sync.rs index 6966049aadb5d..ef91c29144615 100644 --- a/examples/asset/multi_asset_sync.rs +++ b/examples/asset/multi_asset_sync.rs @@ -17,7 +17,7 @@ fn main() { App::new() .add_plugins(DefaultPlugins) .init_state::() - .insert_resource(AmbientLightResource { + .insert_resource(AmbientLight { color: Color::WHITE, brightness: 2000., ..default() diff --git a/examples/gltf/custom_gltf_vertex_attribute.rs b/examples/gltf/custom_gltf_vertex_attribute.rs index 39880a63d27bb..cba292f7a1e5a 100644 --- a/examples/gltf/custom_gltf_vertex_attribute.rs +++ b/examples/gltf/custom_gltf_vertex_attribute.rs @@ -23,7 +23,7 @@ const ATTRIBUTE_BARYCENTRIC: MeshVertexAttribute = fn main() { App::new() - .insert_resource(AmbientLightResource { + .insert_resource(AmbientLight { color: Color::WHITE, brightness: 1.0 / 5.0f32, ..default() diff --git a/examples/gltf/gltf_skinned_mesh.rs b/examples/gltf/gltf_skinned_mesh.rs index 070b131543081..aa88728df938a 100644 --- a/examples/gltf/gltf_skinned_mesh.rs +++ b/examples/gltf/gltf_skinned_mesh.rs @@ -8,7 +8,7 @@ use bevy::{math::ops, mesh::skinning::SkinnedMesh, prelude::*}; fn main() { App::new() .add_plugins(DefaultPlugins) - .insert_resource(AmbientLightResource { + .insert_resource(AmbientLight { brightness: 750.0, ..default() }) diff --git a/examples/math/render_primitives.rs b/examples/math/render_primitives.rs index 7bb14ef306d74..b33700ea18157 100644 --- a/examples/math/render_primitives.rs +++ b/examples/math/render_primitives.rs @@ -281,7 +281,7 @@ fn setup_cameras(mut commands: Commands) { )); } -fn setup_ambient_light(mut ambient_light: ResMut) { +fn setup_ambient_light(mut ambient_light: ResMut) { ambient_light.brightness = 50.0; } diff --git a/tests/3d/test_invalid_skinned_mesh.rs b/tests/3d/test_invalid_skinned_mesh.rs index 122e46654bf54..a5e5b25feef2e 100644 --- a/tests/3d/test_invalid_skinned_mesh.rs +++ b/tests/3d/test_invalid_skinned_mesh.rs @@ -16,7 +16,7 @@ use core::f32::consts::TAU; fn main() { App::new() .add_plugins(DefaultPlugins) - .insert_resource(AmbientLightResource { + .insert_resource(AmbientLight { brightness: 20_000.0, ..default() }) From 3a4f97f3c1edaeea6f0c76949e4d61f4278e04a9 Mon Sep 17 00:00:00 2001 From: Trashtalk Date: Sat, 18 Oct 2025 23:13:21 +0200 Subject: [PATCH 3/9] cargo fmt --- crates/bevy_light/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/bevy_light/src/lib.rs b/crates/bevy_light/src/lib.rs index 32f98cd1b036b..5c0a570ee54f3 100644 --- a/crates/bevy_light/src/lib.rs +++ b/crates/bevy_light/src/lib.rs @@ -25,7 +25,7 @@ use cluster::{ VisibleClusterableObjects, }; mod ambient_light; -pub use ambient_light::{AmbientLightOverride, AmbientLight}; +pub use ambient_light::{AmbientLight, AmbientLightOverride}; mod probe; pub use probe::{ AtmosphereEnvironmentMapLight, EnvironmentMapLight, GeneratedEnvironmentMapLight, @@ -57,8 +57,8 @@ pub use directional_light::{ pub mod prelude { #[doc(hidden)] pub use crate::{ - light_consts, AmbientLightOverride, AmbientLight, DirectionalLight, - EnvironmentMapLight, GeneratedEnvironmentMapLight, LightProbe, PointLight, SpotLight, + light_consts, AmbientLight, AmbientLightOverride, DirectionalLight, EnvironmentMapLight, + GeneratedEnvironmentMapLight, LightProbe, PointLight, SpotLight, }; } From bcf2f5a6cafc912f75f8e96cd33ea49405c893c8 Mon Sep 17 00:00:00 2001 From: Trashtalk Date: Sat, 18 Oct 2025 23:22:28 +0200 Subject: [PATCH 4/9] fixed docs --- crates/bevy_light/src/ambient_light.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_light/src/ambient_light.rs b/crates/bevy_light/src/ambient_light.rs index f59d670d32d64..34e736cd08db1 100644 --- a/crates/bevy_light/src/ambient_light.rs +++ b/crates/bevy_light/src/ambient_light.rs @@ -5,7 +5,7 @@ use bevy_reflect::prelude::*; /// An ambient light, which lights the entire scene equally. /// -/// It can be added to a camera to override the default `AmbientLightResource` ambient for that camera only. +/// It can be added to a camera to override the default [`AmbientLight`] ambient for that camera only. #[derive(Component, Clone, Debug, Reflect)] #[reflect(Component, Debug, Default, Clone)] #[require(Camera)] @@ -49,7 +49,7 @@ impl Default for AmbientLightOverride { /// ``` /// # use bevy_ecs::system::ResMut; /// # use bevy_light::AmbientLight; -/// fn setup_ambient_light(mut ambient_light: ResMut) { +/// fn setup_ambient_light(mut ambient_light: ResMut) { /// ambient_light.brightness = 100.0; /// } /// ``` From 7824f619a8cf1ab78d05883610ca1a9e483124f9 Mon Sep 17 00:00:00 2001 From: Trashtalk Date: Tue, 21 Oct 2025 21:12:02 +0200 Subject: [PATCH 5/9] docs, rename, fmt --- crates/bevy_light/src/ambient_light.rs | 17 +++++++++-------- crates/bevy_light/src/lib.rs | 8 ++++---- crates/bevy_pbr/src/lib.rs | 6 +++--- crates/bevy_pbr/src/render/light.rs | 16 ++++++++-------- examples/3d/auto_exposure.rs | 2 +- examples/3d/fog.rs | 2 +- examples/3d/fog_volumes.rs | 2 +- examples/3d/irradiance_volumes.rs | 4 ++-- examples/3d/lighting.rs | 4 ++-- examples/3d/lightmaps.rs | 2 +- examples/3d/mixed_lighting.rs | 2 +- examples/3d/motion_blur.rs | 2 +- examples/3d/skybox.rs | 2 +- examples/3d/specular_tint.rs | 2 +- examples/3d/spherical_area_lights.rs | 2 +- examples/3d/spotlight.rs | 2 +- examples/3d/ssao.rs | 2 +- examples/3d/transmission.rs | 2 +- examples/3d/volumetric_fog.rs | 2 +- examples/animation/animated_mesh.rs | 2 +- examples/animation/animated_mesh_control.rs | 2 +- examples/animation/animated_mesh_events.rs | 2 +- examples/animation/animated_transform.rs | 2 +- examples/animation/animation_graph.rs | 2 +- examples/animation/animation_masks.rs | 2 +- examples/animation/custom_skinned_mesh.rs | 2 +- examples/animation/morph_targets.rs | 2 +- examples/asset/multi_asset_sync.rs | 2 +- examples/gltf/custom_gltf_vertex_attribute.rs | 2 +- examples/gltf/gltf_skinned_mesh.rs | 2 +- examples/math/render_primitives.rs | 2 +- tests/3d/test_invalid_skinned_mesh.rs | 2 +- 32 files changed, 54 insertions(+), 53 deletions(-) diff --git a/crates/bevy_light/src/ambient_light.rs b/crates/bevy_light/src/ambient_light.rs index 34e736cd08db1..6b68b0aa99fd5 100644 --- a/crates/bevy_light/src/ambient_light.rs +++ b/crates/bevy_light/src/ambient_light.rs @@ -5,11 +5,11 @@ use bevy_reflect::prelude::*; /// An ambient light, which lights the entire scene equally. /// -/// It can be added to a camera to override the default [`AmbientLight`] ambient for that camera only. +/// It can be added to a camera to override [`GlobalAmbientLight`], which is the default that is otherwise used. #[derive(Component, Clone, Debug, Reflect)] #[reflect(Component, Debug, Default, Clone)] #[require(Camera)] -pub struct AmbientLightOverride { +pub struct AmbientLight { pub color: Color, /// A direct scale factor multiplied with `color` before being passed to the shader. @@ -28,7 +28,7 @@ pub struct AmbientLightOverride { pub affects_lightmapped_meshes: bool, } -impl Default for AmbientLightOverride { +impl Default for AmbientLight { fn default() -> Self { Self { color: Color::WHITE, @@ -38,9 +38,10 @@ impl Default for AmbientLightOverride { } } -/// An ambient light, which lights the entire scene equally. +/// The global ambient light, which lights the entire scene equally. /// /// This resource is inserted by the [`LightPlugin`] and by default it is set to a low ambient light. +/// Inserting an [`AmbientLight`] on a camera will override this default. /// /// # Examples /// @@ -57,7 +58,7 @@ impl Default for AmbientLightOverride { /// [`LightPlugin`]: crate::LightPlugin #[derive(Resource, Clone, Debug, Reflect)] #[reflect(Resource, Debug, Default, Clone)] -pub struct AmbientLight { +pub struct GlobalAmbientLight { pub color: Color, /// A direct scale factor multiplied with `color` before being passed to the shader. @@ -76,7 +77,7 @@ pub struct AmbientLight { pub affects_lightmapped_meshes: bool, } -impl Default for AmbientLight { +impl Default for GlobalAmbientLight { fn default() -> Self { Self { color: Color::WHITE, @@ -86,8 +87,8 @@ impl Default for AmbientLight { } } -impl AmbientLight { - pub const NONE: AmbientLight = AmbientLight { +impl GlobalAmbientLight { + pub const NONE: GlobalAmbientLight = GlobalAmbientLight { color: Color::WHITE, brightness: 0.0, affects_lightmapped_meshes: true, diff --git a/crates/bevy_light/src/lib.rs b/crates/bevy_light/src/lib.rs index 5c0a570ee54f3..416a5565169e2 100644 --- a/crates/bevy_light/src/lib.rs +++ b/crates/bevy_light/src/lib.rs @@ -25,7 +25,7 @@ use cluster::{ VisibleClusterableObjects, }; mod ambient_light; -pub use ambient_light::{AmbientLight, AmbientLightOverride}; +pub use ambient_light::{AmbientLight, GlobalAmbientLight}; mod probe; pub use probe::{ AtmosphereEnvironmentMapLight, EnvironmentMapLight, GeneratedEnvironmentMapLight, @@ -57,8 +57,8 @@ pub use directional_light::{ pub mod prelude { #[doc(hidden)] pub use crate::{ - light_consts, AmbientLight, AmbientLightOverride, DirectionalLight, EnvironmentMapLight, - GeneratedEnvironmentMapLight, LightProbe, PointLight, SpotLight, + light_consts, AmbientLight, DirectionalLight, EnvironmentMapLight, + GeneratedEnvironmentMapLight, GlobalAmbientLight, LightProbe, PointLight, SpotLight, }; } @@ -133,7 +133,7 @@ pub struct LightPlugin; impl Plugin for LightPlugin { fn build(&self, app: &mut App) { app.init_resource::() - .init_resource::() + .init_resource::() .init_resource::() .init_resource::() .configure_sets( diff --git a/crates/bevy_pbr/src/lib.rs b/crates/bevy_pbr/src/lib.rs index 4244d64a240f2..6eaa1f99ddf30 100644 --- a/crates/bevy_pbr/src/lib.rs +++ b/crates/bevy_pbr/src/lib.rs @@ -49,8 +49,8 @@ use bevy_color::{Color, LinearRgba}; pub use atmosphere::*; use bevy_light::{ - AmbientLightOverride, DirectionalLight, PointLight, ShadowFilteringMethod, - SimulationLightSystems, SpotLight, + AmbientLight, DirectionalLight, PointLight, ShadowFilteringMethod, SimulationLightSystems, + SpotLight, }; use bevy_shader::{load_shader_library, ShaderRef}; pub use cluster::*; @@ -245,7 +245,7 @@ impl Plugin for PbrPlugin { SyncComponentPlugin::::default(), SyncComponentPlugin::::default(), SyncComponentPlugin::::default(), - SyncComponentPlugin::::default(), + SyncComponentPlugin::::default(), )) .add_plugins(AtmospherePlugin) .configure_sets( diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index 40e56a181cfc5..236a18124629d 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -24,8 +24,8 @@ use bevy_light::cluster::assign::{calculate_cluster_factors, ClusterableObjectTy use bevy_light::cluster::GlobalVisibleClusterableObjects; use bevy_light::SunDisk; use bevy_light::{ - spot_light_clip_from_view, spot_light_world_from_view, AmbientLight, AmbientLightOverride, - CascadeShadowConfig, Cascades, DirectionalLight, DirectionalLightShadowMap, NotShadowCaster, + spot_light_clip_from_view, spot_light_world_from_view, AmbientLight, CascadeShadowConfig, + Cascades, DirectionalLight, DirectionalLightShadowMap, GlobalAmbientLight, NotShadowCaster, PointLight, PointLightShadowMap, ShadowFilteringMethod, SpotLight, VolumetricLight, }; use bevy_math::{ops, Mat4, UVec4, Vec3, Vec3Swizzles, Vec4, Vec4Swizzles}; @@ -248,8 +248,8 @@ pub fn extract_shadow_filtering_method( // foreign trait ExtractResource on foreign type AmbientLight pub fn extract_ambient_light_resource( mut commands: Commands, - main_resource: Extract>>, - target_resource: Option>, + main_resource: Extract>>, + target_resource: Option>, ) { if let Some(main_resource) = main_resource.as_ref() { if let Some(mut target_resource) = target_resource { @@ -267,7 +267,7 @@ pub fn extract_ambient_light_resource( pub fn extract_ambient_light( mut commands: Commands, mut previous_len: Local, - query: Extract>, + query: Extract>, ) { let mut values = Vec::with_capacity(*previous_len); for (entity, query_item) in &query { @@ -716,11 +716,11 @@ pub fn prepare_lights( &ExtractedClusterConfig, Option<&RenderLayers>, Has, - Option<&AmbientLightOverride>, + Option<&AmbientLight>, ), With, >, - ambient_light: Res, + ambient_light: Res, point_light_shadow_map: Res, directional_light_shadow_map: Res, mut shadow_render_phases: ResMut>, @@ -1150,7 +1150,7 @@ pub fn prepare_lights( ); let n_clusters = clusters.dimensions.x * clusters.dimensions.y * clusters.dimensions.z; - let ambient_light = AmbientLightOverride { + let ambient_light = AmbientLight { color: ambient_light.color, brightness: ambient_light.brightness, affects_lightmapped_meshes: ambient_light.affects_lightmapped_meshes, diff --git a/examples/3d/auto_exposure.rs b/examples/3d/auto_exposure.rs index 5d9e42c9310c8..c5e0bf783262f 100644 --- a/examples/3d/auto_exposure.rs +++ b/examples/3d/auto_exposure.rs @@ -97,7 +97,7 @@ fn setup( } } - commands.insert_resource(AmbientLight { + commands.insert_resource(GlobalAmbientLight { color: Color::WHITE, brightness: 0.0, ..default() diff --git a/examples/3d/fog.rs b/examples/3d/fog.rs index 9a5e1315b8575..8d23035b738c2 100644 --- a/examples/3d/fog.rs +++ b/examples/3d/fog.rs @@ -29,7 +29,7 @@ use bevy::{ fn main() { App::new() - .insert_resource(AmbientLight::NONE) + .insert_resource(GlobalAmbientLight::NONE) .add_plugins(DefaultPlugins) .add_systems( Startup, diff --git a/examples/3d/fog_volumes.rs b/examples/3d/fog_volumes.rs index 2789644b2171a..9d52903e4e94a 100644 --- a/examples/3d/fog_volumes.rs +++ b/examples/3d/fog_volumes.rs @@ -22,7 +22,7 @@ fn main() { }), ..default() })) - .insert_resource(AmbientLight::NONE) + .insert_resource(GlobalAmbientLight::NONE) .add_systems(Startup, setup) .add_systems(Update, rotate_camera) .run(); diff --git a/examples/3d/irradiance_volumes.rs b/examples/3d/irradiance_volumes.rs index f7500c7e488a3..257cfb7354648 100644 --- a/examples/3d/irradiance_volumes.rs +++ b/examples/3d/irradiance_volumes.rs @@ -157,7 +157,7 @@ fn main() { .add_plugins(MaterialPlugin::::default()) .init_resource::() .init_resource::() - .insert_resource(AmbientLight { + .insert_resource(GlobalAmbientLight { color: Color::WHITE, brightness: 0.0, ..default() @@ -414,7 +414,7 @@ fn toggle_irradiance_volumes( light_probe_query: Query>, mut app_status: ResMut, assets: Res, - mut ambient_light: ResMut, + mut ambient_light: ResMut, ) { if !keyboard.just_pressed(KeyCode::Space) { return; diff --git a/examples/3d/lighting.rs b/examples/3d/lighting.rs index a23a68885abb3..71bc4a00c049e 100644 --- a/examples/3d/lighting.rs +++ b/examples/3d/lighting.rs @@ -120,7 +120,7 @@ fn setup( // ambient light // ambient lights' brightnesses are measured in candela per meter square, calculable as (color * brightness) - commands.insert_resource(AmbientLight { + commands.insert_resource(GlobalAmbientLight { color: ORANGE_RED.into(), brightness: 200.0, ..default() @@ -290,7 +290,7 @@ fn update_exposure( fn toggle_ambient_light( key_input: Res>, - mut ambient_light: ResMut, + mut ambient_light: ResMut, text: Single>, mut writer: TextUiWriter, ) { diff --git a/examples/3d/lightmaps.rs b/examples/3d/lightmaps.rs index c994741150ad3..862fe11c76500 100644 --- a/examples/3d/lightmaps.rs +++ b/examples/3d/lightmaps.rs @@ -27,7 +27,7 @@ fn main() { let mut app = App::new(); app.add_plugins(DefaultPlugins) - .insert_resource(AmbientLight::NONE); + .insert_resource(GlobalAmbientLight::NONE); if args.deferred { app.insert_resource(DefaultOpaqueRendererMethod::deferred()); diff --git a/examples/3d/mixed_lighting.rs b/examples/3d/mixed_lighting.rs index 73ced56408eed..58594ad14e1c1 100644 --- a/examples/3d/mixed_lighting.rs +++ b/examples/3d/mixed_lighting.rs @@ -124,7 +124,7 @@ fn main() { ..default() })) .add_plugins(MeshPickingPlugin) - .insert_resource(AmbientLight { + .insert_resource(GlobalAmbientLight { color: ClearColor::default().0, brightness: 10000.0, affects_lightmapped_meshes: true, diff --git a/examples/3d/motion_blur.rs b/examples/3d/motion_blur.rs index 92c5d8cd72cb7..ef9349ee7b19d 100644 --- a/examples/3d/motion_blur.rs +++ b/examples/3d/motion_blur.rs @@ -57,7 +57,7 @@ fn setup_scene( mut meshes: ResMut>, mut materials: ResMut>, ) { - commands.insert_resource(AmbientLight { + commands.insert_resource(GlobalAmbientLight { color: Color::WHITE, brightness: 300.0, ..default() diff --git a/examples/3d/skybox.rs b/examples/3d/skybox.rs index 31fdcc8872262..aceef74cb11d3 100644 --- a/examples/3d/skybox.rs +++ b/examples/3d/skybox.rs @@ -85,7 +85,7 @@ fn setup(mut commands: Commands, asset_server: Res) { // ambient light // NOTE: The ambient light is used to scale how bright the environment map is so with a bright // environment map, use an appropriate color and brightness to match - commands.insert_resource(AmbientLight { + commands.insert_resource(GlobalAmbientLight { color: Color::srgb_u8(210, 220, 240), brightness: 1.0, ..default() diff --git a/examples/3d/specular_tint.rs b/examples/3d/specular_tint.rs index 154226713201f..9712500081752 100644 --- a/examples/3d/specular_tint.rs +++ b/examples/3d/specular_tint.rs @@ -59,7 +59,7 @@ fn main() { })) .init_resource::() .init_resource::() - .insert_resource(AmbientLight { + .insert_resource(GlobalAmbientLight { color: Color::BLACK, brightness: 0.0, ..default() diff --git a/examples/3d/spherical_area_lights.rs b/examples/3d/spherical_area_lights.rs index c3e945a8f3492..f4b244debf0cc 100644 --- a/examples/3d/spherical_area_lights.rs +++ b/examples/3d/spherical_area_lights.rs @@ -4,7 +4,7 @@ use bevy::prelude::*; fn main() { App::new() - .insert_resource(AmbientLight { + .insert_resource(GlobalAmbientLight { brightness: 60.0, ..default() }) diff --git a/examples/3d/spotlight.rs b/examples/3d/spotlight.rs index efdb44680aee5..f3270fdefbfdb 100644 --- a/examples/3d/spotlight.rs +++ b/examples/3d/spotlight.rs @@ -21,7 +21,7 @@ Rotate Camera: Left and Right Arrows"; fn main() { App::new() - .insert_resource(AmbientLight { + .insert_resource(GlobalAmbientLight { brightness: 20.0, ..default() }) diff --git a/examples/3d/ssao.rs b/examples/3d/ssao.rs index 129979b0fbb3d..d9f59aa4cce5a 100644 --- a/examples/3d/ssao.rs +++ b/examples/3d/ssao.rs @@ -11,7 +11,7 @@ use std::f32::consts::PI; fn main() { App::new() - .insert_resource(AmbientLight { + .insert_resource(GlobalAmbientLight { brightness: 1000., ..default() }) diff --git a/examples/3d/transmission.rs b/examples/3d/transmission.rs index 5db06e04edad2..cd9754b70e3b3 100644 --- a/examples/3d/transmission.rs +++ b/examples/3d/transmission.rs @@ -47,7 +47,7 @@ fn main() { .add_plugins(DefaultPlugins) .insert_resource(ClearColor(Color::BLACK)) .insert_resource(PointLightShadowMap { size: 2048 }) - .insert_resource(AmbientLight { + .insert_resource(GlobalAmbientLight { brightness: 0.0, ..default() }) diff --git a/examples/3d/volumetric_fog.rs b/examples/3d/volumetric_fog.rs index c8c47ef73338d..53e99313e8489 100644 --- a/examples/3d/volumetric_fog.rs +++ b/examples/3d/volumetric_fog.rs @@ -47,7 +47,7 @@ fn main() { blue: 0.02, alpha: 1.0, }))) - .insert_resource(AmbientLight::NONE) + .insert_resource(GlobalAmbientLight::NONE) .init_resource::() .add_systems(Startup, setup) .add_systems(Update, tweak_scene) diff --git a/examples/animation/animated_mesh.rs b/examples/animation/animated_mesh.rs index 466d53be2ff22..d23910352175e 100644 --- a/examples/animation/animated_mesh.rs +++ b/examples/animation/animated_mesh.rs @@ -9,7 +9,7 @@ const GLTF_PATH: &str = "models/animated/Fox.glb"; fn main() { App::new() - .insert_resource(AmbientLight { + .insert_resource(GlobalAmbientLight { color: Color::WHITE, brightness: 2000., ..default() diff --git a/examples/animation/animated_mesh_control.rs b/examples/animation/animated_mesh_control.rs index 3029722c1aa66..0feaa2759c03a 100644 --- a/examples/animation/animated_mesh_control.rs +++ b/examples/animation/animated_mesh_control.rs @@ -8,7 +8,7 @@ const FOX_PATH: &str = "models/animated/Fox.glb"; fn main() { App::new() - .insert_resource(AmbientLight { + .insert_resource(GlobalAmbientLight { color: Color::WHITE, brightness: 2000., ..default() diff --git a/examples/animation/animated_mesh_events.rs b/examples/animation/animated_mesh_events.rs index 5898807cf45a3..8de2d9c336665 100644 --- a/examples/animation/animated_mesh_events.rs +++ b/examples/animation/animated_mesh_events.rs @@ -15,7 +15,7 @@ const FOX_PATH: &str = "models/animated/Fox.glb"; fn main() { App::new() - .insert_resource(AmbientLight { + .insert_resource(GlobalAmbientLight { color: Color::WHITE, brightness: 2000., ..default() diff --git a/examples/animation/animated_transform.rs b/examples/animation/animated_transform.rs index bd1b7b3c986e9..e46c9c525061c 100644 --- a/examples/animation/animated_transform.rs +++ b/examples/animation/animated_transform.rs @@ -10,7 +10,7 @@ use bevy::{ fn main() { App::new() .add_plugins(DefaultPlugins) - .insert_resource(AmbientLight { + .insert_resource(GlobalAmbientLight { color: Color::WHITE, brightness: 150.0, ..default() diff --git a/examples/animation/animation_graph.rs b/examples/animation/animation_graph.rs index bc4b8b2bdf3a1..7393105058283 100644 --- a/examples/animation/animation_graph.rs +++ b/examples/animation/animation_graph.rs @@ -88,7 +88,7 @@ fn main() { (handle_weight_drag, update_ui, sync_weights).chain(), ) .insert_resource(args) - .insert_resource(AmbientLight { + .insert_resource(GlobalAmbientLight { color: WHITE.into(), brightness: 100.0, ..default() diff --git a/examples/animation/animation_masks.rs b/examples/animation/animation_masks.rs index 4566d06034e33..f0f0818d6a222 100644 --- a/examples/animation/animation_masks.rs +++ b/examples/animation/animation_masks.rs @@ -105,7 +105,7 @@ fn main() { .add_systems(Update, setup_animation_graph_once_loaded) .add_systems(Update, handle_button_toggles) .add_systems(Update, update_ui) - .insert_resource(AmbientLight { + .insert_resource(GlobalAmbientLight { color: WHITE.into(), brightness: 100.0, ..default() diff --git a/examples/animation/custom_skinned_mesh.rs b/examples/animation/custom_skinned_mesh.rs index c706e07be9b64..e45d21bbc2282 100644 --- a/examples/animation/custom_skinned_mesh.rs +++ b/examples/animation/custom_skinned_mesh.rs @@ -18,7 +18,7 @@ use rand_chacha::ChaCha8Rng; fn main() { App::new() .add_plugins(DefaultPlugins) - .insert_resource(AmbientLight { + .insert_resource(GlobalAmbientLight { brightness: 3000.0, ..default() }) diff --git a/examples/animation/morph_targets.rs b/examples/animation/morph_targets.rs index 27ae52e030ef8..ffb468f26592c 100644 --- a/examples/animation/morph_targets.rs +++ b/examples/animation/morph_targets.rs @@ -10,7 +10,7 @@ const GLTF_PATH: &str = "models/animated/MorphStressTest.gltf"; fn main() { App::new() .add_plugins(DefaultPlugins) - .insert_resource(AmbientLight { + .insert_resource(GlobalAmbientLight { brightness: 150.0, ..default() }) diff --git a/examples/asset/multi_asset_sync.rs b/examples/asset/multi_asset_sync.rs index ef91c29144615..8330be603a2a3 100644 --- a/examples/asset/multi_asset_sync.rs +++ b/examples/asset/multi_asset_sync.rs @@ -17,7 +17,7 @@ fn main() { App::new() .add_plugins(DefaultPlugins) .init_state::() - .insert_resource(AmbientLight { + .insert_resource(GlobalAmbientLight { color: Color::WHITE, brightness: 2000., ..default() diff --git a/examples/gltf/custom_gltf_vertex_attribute.rs b/examples/gltf/custom_gltf_vertex_attribute.rs index cba292f7a1e5a..f523ae2cdf71b 100644 --- a/examples/gltf/custom_gltf_vertex_attribute.rs +++ b/examples/gltf/custom_gltf_vertex_attribute.rs @@ -23,7 +23,7 @@ const ATTRIBUTE_BARYCENTRIC: MeshVertexAttribute = fn main() { App::new() - .insert_resource(AmbientLight { + .insert_resource(GlobalAmbientLight { color: Color::WHITE, brightness: 1.0 / 5.0f32, ..default() diff --git a/examples/gltf/gltf_skinned_mesh.rs b/examples/gltf/gltf_skinned_mesh.rs index aa88728df938a..48690dd2d329e 100644 --- a/examples/gltf/gltf_skinned_mesh.rs +++ b/examples/gltf/gltf_skinned_mesh.rs @@ -8,7 +8,7 @@ use bevy::{math::ops, mesh::skinning::SkinnedMesh, prelude::*}; fn main() { App::new() .add_plugins(DefaultPlugins) - .insert_resource(AmbientLight { + .insert_resource(GlobalAmbientLight { brightness: 750.0, ..default() }) diff --git a/examples/math/render_primitives.rs b/examples/math/render_primitives.rs index b33700ea18157..726ef278cfbc3 100644 --- a/examples/math/render_primitives.rs +++ b/examples/math/render_primitives.rs @@ -281,7 +281,7 @@ fn setup_cameras(mut commands: Commands) { )); } -fn setup_ambient_light(mut ambient_light: ResMut) { +fn setup_ambient_light(mut ambient_light: ResMut) { ambient_light.brightness = 50.0; } diff --git a/tests/3d/test_invalid_skinned_mesh.rs b/tests/3d/test_invalid_skinned_mesh.rs index a5e5b25feef2e..f371a06b7130e 100644 --- a/tests/3d/test_invalid_skinned_mesh.rs +++ b/tests/3d/test_invalid_skinned_mesh.rs @@ -16,7 +16,7 @@ use core::f32::consts::TAU; fn main() { App::new() .add_plugins(DefaultPlugins) - .insert_resource(AmbientLight { + .insert_resource(GlobalAmbientLight { brightness: 20_000.0, ..default() }) From 39a3c1a5595d54fa075f8d9f59be259f70b6c596 Mon Sep 17 00:00:00 2001 From: Trashtalk Date: Tue, 21 Oct 2025 21:22:24 +0200 Subject: [PATCH 6/9] migration guide --- .../migration-guides/ambient_light_split.md | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 release-content/migration-guides/ambient_light_split.md diff --git a/release-content/migration-guides/ambient_light_split.md b/release-content/migration-guides/ambient_light_split.md new file mode 100644 index 0000000000000..e91625445ddaa --- /dev/null +++ b/release-content/migration-guides/ambient_light_split.md @@ -0,0 +1,28 @@ +--- +title: "`AmbientLight` split into a component and a resource" +pull_requests: [21585] +--- + +The `AmbientLight` used to be both a component *and* a resource. +In 0.18, we've split this in two separate structs: `AmbientLight` and `GlobalAmbientLight`. +The resource `GlobalAmbientLight` is the default ambient light for the entire world and automatically added by `LightPlugin`. +Meanwhile, `AmbientLight` is a component that can be added to a `Camera` in order to override the default `GlobalAmbientLight`. +When appropriate, rename `AmbientLight` to `GlobalAmbientLight`. + +Before: + +```rust +app.insert_resource(AmbientLight { + color: Color::WHITE, + brightness: 2000., + ..default() +``` + +After: + +```rust +app.insert_resource(GlobalAmbientLight { + color: Color::WHITE, + brightness: 2000., + ..default() +``` From 6f388024666019b29782a90806a9d74a2cbeb601 Mon Sep 17 00:00:00 2001 From: Trashtalk Date: Tue, 21 Oct 2025 21:34:36 +0200 Subject: [PATCH 7/9] docs mistake --- crates/bevy_light/src/ambient_light.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_light/src/ambient_light.rs b/crates/bevy_light/src/ambient_light.rs index 6b68b0aa99fd5..e8455b7321dab 100644 --- a/crates/bevy_light/src/ambient_light.rs +++ b/crates/bevy_light/src/ambient_light.rs @@ -50,7 +50,7 @@ impl Default for AmbientLight { /// ``` /// # use bevy_ecs::system::ResMut; /// # use bevy_light::AmbientLight; -/// fn setup_ambient_light(mut ambient_light: ResMut) { +/// fn setup_ambient_light(mut ambient_light: ResMut) { /// ambient_light.brightness = 100.0; /// } /// ``` From 3e2ae32cf0dc774ef2448232614738d5c415dfc2 Mon Sep 17 00:00:00 2001 From: Trashtalk Date: Tue, 21 Oct 2025 21:41:12 +0200 Subject: [PATCH 8/9] docs mistake --- crates/bevy_light/src/ambient_light.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_light/src/ambient_light.rs b/crates/bevy_light/src/ambient_light.rs index e8455b7321dab..d3c110efe3088 100644 --- a/crates/bevy_light/src/ambient_light.rs +++ b/crates/bevy_light/src/ambient_light.rs @@ -49,7 +49,7 @@ impl Default for AmbientLight { /// /// ``` /// # use bevy_ecs::system::ResMut; -/// # use bevy_light::AmbientLight; +/// # use bevy_light::GlobalAmbientLight; /// fn setup_ambient_light(mut ambient_light: ResMut) { /// ambient_light.brightness = 100.0; /// } From 36a1bdad7c74f935e416522636e04fbb6e5c0254 Mon Sep 17 00:00:00 2001 From: Trashtalk217 Date: Tue, 21 Oct 2025 23:41:04 +0200 Subject: [PATCH 9/9] Apply suggestions from code review Co-authored-by: atlv --- release-content/migration-guides/ambient_light_split.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/release-content/migration-guides/ambient_light_split.md b/release-content/migration-guides/ambient_light_split.md index e91625445ddaa..ae974e835ea64 100644 --- a/release-content/migration-guides/ambient_light_split.md +++ b/release-content/migration-guides/ambient_light_split.md @@ -16,6 +16,7 @@ app.insert_resource(AmbientLight { color: Color::WHITE, brightness: 2000., ..default() +}); ``` After: @@ -25,4 +26,5 @@ app.insert_resource(GlobalAmbientLight { color: Color::WHITE, brightness: 2000., ..default() +}); ```