From 0778d9cce958ade7221aafeff5bbc883f1ba19e1 Mon Sep 17 00:00:00 2001 From: Shaye Garg <64652557+SparkyPotato@users.noreply.github.com> Date: Sun, 9 Mar 2025 16:26:22 +0000 Subject: [PATCH 01/18] =?UTF-8?q?Revert=20"Revert=20"Replace=20Ambient=20L?= =?UTF-8?q?ights=20with=20Environment=20Map=20Lights=20(#17482)"=20?= =?UTF-8?q?=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 54701a844e247cf1bd705c77cce177616ffb2229. --- crates/bevy_pbr/src/lib.rs | 22 +++-- crates/bevy_pbr/src/light/ambient_light.rs | 5 ++ crates/bevy_pbr/src/light/mod.rs | 59 ++++++++++++- .../src/light_probe/environment_map.rs | 85 ++++++++++++++++++- crates/bevy_pbr/src/render/light.rs | 26 ++---- .../bevy_pbr/src/render/mesh_view_types.wgsl | 1 - crates/bevy_pbr/src/render/pbr_ambient.wgsl | 29 ------- crates/bevy_pbr/src/render/pbr_functions.wgsl | 15 ---- examples/2d/custom_gltf_vertex_attribute.rs | 14 +-- examples/3d/auto_exposure.rs | 10 +-- examples/3d/fog.rs | 4 + examples/3d/fog_volumes.rs | 4 + examples/3d/irradiance_volumes.rs | 34 +++++--- examples/3d/lighting.rs | 12 ++- examples/3d/lightmaps.rs | 4 + examples/3d/mixed_lighting.rs | 27 +++--- examples/3d/motion_blur.rs | 11 ++- examples/3d/skybox.rs | 22 ++--- examples/3d/specular_tint.rs | 10 +-- examples/3d/spherical_area_lights.rs | 9 +- examples/3d/spotlight.rs | 9 +- examples/3d/ssao.rs | 9 +- examples/3d/transmission.rs | 9 +- examples/3d/volumetric_fog.rs | 4 + examples/animation/animated_mesh.rs | 10 +-- examples/animation/animated_mesh_control.rs | 10 +-- examples/animation/animated_mesh_events.rs | 10 +-- examples/animation/animated_transform.rs | 10 +-- examples/animation/animation_graph.rs | 10 +-- examples/animation/animation_masks.rs | 12 +-- examples/animation/custom_skinned_mesh.rs | 9 +- examples/animation/gltf_skinned_mesh.rs | 14 +-- examples/animation/morph_targets.rs | 14 +-- examples/asset/multi_asset_sync.rs | 10 +-- examples/math/render_primitives.rs | 17 ++-- 35 files changed, 348 insertions(+), 212 deletions(-) delete mode 100644 crates/bevy_pbr/src/render/pbr_ambient.wgsl diff --git a/crates/bevy_pbr/src/lib.rs b/crates/bevy_pbr/src/lib.rs index 543a4665fc54d..75f04581472b4 100644 --- a/crates/bevy_pbr/src/lib.rs +++ b/crates/bevy_pbr/src/lib.rs @@ -71,10 +71,16 @@ pub use volumetric_fog::{FogVolume, VolumetricFog, VolumetricFogPlugin, Volumetr /// /// This includes the most common types in this crate, re-exported for your convenience. pub mod prelude { + #[expect( + deprecated, + reason = "AmbientLight has been replaced by EnvironmentMapLight" + )] + #[doc(hidden)] + pub use crate::light::AmbientLight; #[doc(hidden)] pub use crate::{ fog::{DistanceFog, FogFalloff}, - light::{light_consts, AmbientLight, DirectionalLight, PointLight, SpotLight}, + light::{light_consts, DirectionalLight, PointLight, SpotLight}, light_probe::{environment_map::EnvironmentMapLight, LightProbe}, material::{Material, MaterialPlugin}, mesh_material::MeshMaterial3d, @@ -165,7 +171,6 @@ pub const PBR_PREPASS_SHADER_HANDLE: Handle = weak_handle!("9afeaeab-7c45-43ce-b322-4b97799eaeb9"); pub const PBR_FUNCTIONS_HANDLE: Handle = weak_handle!("815b8618-f557-4a96-91a5-a2fb7e249fb0"); -pub const PBR_AMBIENT_HANDLE: Handle = weak_handle!("4a90b95b-112a-4a10-9145-7590d6f14260"); pub const PARALLAX_MAPPING_SHADER_HANDLE: Handle = weak_handle!("6cf57d9f-222a-429a-bba4-55ba9586e1d4"); pub const VIEW_TRANSFORMATIONS_SHADER_HANDLE: Handle = @@ -280,12 +285,6 @@ impl Plugin for PbrPlugin { "render/rgb9e5.wgsl", Shader::from_wgsl ); - load_internal_asset!( - app, - PBR_AMBIENT_HANDLE, - "render/pbr_ambient.wgsl", - Shader::from_wgsl - ); load_internal_asset!( app, PBR_FRAGMENT_HANDLE, @@ -325,6 +324,10 @@ impl Plugin for PbrPlugin { Shader::from_wgsl ); + #[expect( + deprecated, + reason = "AmbientLight has been replaced by EnvironmentMapLight" + )] app.register_asset_reflect::() .register_type::() .register_type::() @@ -401,6 +404,9 @@ impl Plugin for PbrPlugin { .add_systems( PostUpdate, ( + map_ambient_lights + .in_set(SimulationLightSystems::MapAmbientLights) + .after(CameraUpdateSystem), add_clusters .in_set(SimulationLightSystems::AddClusters) .after(CameraUpdateSystem), diff --git a/crates/bevy_pbr/src/light/ambient_light.rs b/crates/bevy_pbr/src/light/ambient_light.rs index f09bab51f69ed..14ab9a8b1f808 100644 --- a/crates/bevy_pbr/src/light/ambient_light.rs +++ b/crates/bevy_pbr/src/light/ambient_light.rs @@ -1,3 +1,8 @@ +#![deprecated( + since = "0.16.0", + note = "Use `EnvironmentMapLight::solid_color` instead" +)] + use super::*; /// An ambient light, which lights the entire scene equally. diff --git a/crates/bevy_pbr/src/light/mod.rs b/crates/bevy_pbr/src/light/mod.rs index 1c9dc61374a1e..68d01ea6568cb 100644 --- a/crates/bevy_pbr/src/light/mod.rs +++ b/crates/bevy_pbr/src/light/mod.rs @@ -20,9 +20,13 @@ use bevy_render::{ use bevy_transform::components::{GlobalTransform, Transform}; use bevy_utils::Parallel; -use crate::*; +use crate::{prelude::EnvironmentMapLight, *}; mod ambient_light; +#[expect( + deprecated, + reason = "AmbientLight has been replaced by EnvironmentMapLight" +)] pub use ambient_light::AmbientLight; mod point_light; @@ -509,6 +513,7 @@ pub struct LightVisibilityClass; /// System sets used to run light-related systems. #[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)] pub enum SimulationLightSystems { + MapAmbientLights, AddClusters, AssignLightsToClusters, /// System order ambiguities between systems in this set are ignored: @@ -522,6 +527,58 @@ pub enum SimulationLightSystems { CheckLightVisibility, } +#[derive(Component)] +pub struct EnvironmentMapLightFromAmbientLight; + +#[expect( + deprecated, + reason = "AmbientLight has been replaced by EnvironmentMapLight" +)] +pub fn map_ambient_lights( + mut commands: Commands, + mut image_assets: ResMut>, + ambient_light: Res, + new_views: Query< + (Entity, Option>), + ( + With, + Without, + Without, + ), + >, + mut managed_views: Query< + (&mut EnvironmentMapLight, Option>), + With, + >, +) { + let ambient_light = ambient_light.into(); + for (entity, ambient_override) in new_views.iter() { + let ambient = ambient_override.as_ref().unwrap_or(&ambient_light); + let ambient_required = ambient.brightness > 0.0 && ambient.color != Color::BLACK; + if ambient_required && ambient.is_changed() { + commands + .entity(entity) + .insert(EnvironmentMapLight { + intensity: ambient.brightness, + affects_lightmapped_mesh_diffuse: ambient.affects_lightmapped_meshes, + ..EnvironmentMapLight::solid_color(image_assets.as_mut(), ambient.color) + }) + .insert(EnvironmentMapLightFromAmbientLight); + } + } + for (mut env_map, ambient_override) in managed_views.iter_mut() { + let ambient = ambient_override.as_ref().unwrap_or(&ambient_light); + let ambient_required = ambient.brightness > 0.0 && ambient.color != Color::BLACK; + if ambient_required && ambient.is_changed() { + *env_map = EnvironmentMapLight { + intensity: ambient.brightness, + affects_lightmapped_mesh_diffuse: ambient.affects_lightmapped_meshes, + ..EnvironmentMapLight::solid_color(image_assets.as_mut(), ambient.color) + }; + } + } +} + pub fn update_directional_light_frusta( mut views: Query< ( diff --git a/crates/bevy_pbr/src/light_probe/environment_map.rs b/crates/bevy_pbr/src/light_probe/environment_map.rs index 8069f2acac752..fcc1b64a97808 100644 --- a/crates/bevy_pbr/src/light_probe/environment_map.rs +++ b/crates/bevy_pbr/src/light_probe/environment_map.rs @@ -44,7 +44,8 @@ //! //! [several pre-filtered environment maps]: https://github.com/KhronosGroup/glTF-Sample-Environments -use bevy_asset::{weak_handle, AssetId, Handle}; +use bevy_asset::{weak_handle, AssetId, Assets, Handle, RenderAssetUsages}; +use bevy_color::{Color, ColorToPacked, Srgba}; use bevy_ecs::{ component::Component, query::QueryItem, reflect::ReflectComponent, system::lifetimeless::Read, }; @@ -56,8 +57,9 @@ use bevy_render::{ render_asset::RenderAssets, render_resource::{ binding_types::{self, uniform_buffer}, - BindGroupLayoutEntryBuilder, Sampler, SamplerBindingType, Shader, ShaderStages, - TextureSampleType, TextureView, + BindGroupLayoutEntryBuilder, Extent3d, Sampler, SamplerBindingType, Shader, ShaderStages, + TextureDimension, TextureFormat, TextureSampleType, TextureView, TextureViewDescriptor, + TextureViewDimension, }, renderer::{RenderAdapter, RenderDevice}, texture::{FallbackImage, GpuImage}, @@ -114,6 +116,83 @@ pub struct EnvironmentMapLight { pub affects_lightmapped_mesh_diffuse: bool, } +impl EnvironmentMapLight { + /// An environment map with a uniform color, useful for uniform ambient lighting. + pub fn solid_color(assets: &mut Assets, color: Color) -> Self { + let color: Srgba = color.into(); + let image = Image { + texture_view_descriptor: Some(TextureViewDescriptor { + dimension: Some(TextureViewDimension::Cube), + ..Default::default() + }), + ..Image::new_fill( + Extent3d { + width: 1, + height: 1, + depth_or_array_layers: 6, + }, + TextureDimension::D2, + &color.to_u8_array(), + TextureFormat::Rgba8UnormSrgb, + RenderAssetUsages::RENDER_WORLD, + ) + }; + let handle = assets.add(image); + + Self { + diffuse_map: handle.clone(), + specular_map: handle, + ..Default::default() + } + } + + /// An environment map with a hemispherical gradient, fading between the sky and ground colors + /// at the horizon. Useful as a very simple 'sky'. + pub fn hemispherical_gradient( + assets: &mut Assets, + top_color: Color, + bottom_color: Color, + ) -> Self { + let top_color: Srgba = top_color.into(); + let bottom_color: Srgba = bottom_color.into(); + let mid_color = (top_color + bottom_color) / 2.0; + let image = Image { + texture_view_descriptor: Some(TextureViewDescriptor { + dimension: Some(TextureViewDimension::Cube), + ..Default::default() + }), + ..Image::new( + Extent3d { + width: 1, + height: 1, + depth_or_array_layers: 6, + }, + TextureDimension::D2, + [ + mid_color, + mid_color, + top_color, + bottom_color, + mid_color, + mid_color, + ] + .into_iter() + .flat_map(Srgba::to_u8_array) + .collect(), + TextureFormat::Rgba8UnormSrgb, + RenderAssetUsages::RENDER_WORLD, + ) + }; + let handle = assets.add(image); + + Self { + diffuse_map: handle.clone(), + specular_map: handle, + ..Default::default() + } + } +} + impl Default for EnvironmentMapLight { fn default() -> Self { EnvironmentMapLight { diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index 6f3216d896995..b96c1d07c3ccb 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -139,7 +139,6 @@ bitflags::bitflags! { #[derive(Copy, Clone, Debug, ShaderType)] pub struct GpuLights { directional_lights: [GpuDirectionalLight; MAX_DIRECTIONAL_LIGHTS], - ambient_color: Vec4, // xyz are x/y/z cluster dimensions and w is the number of clusters cluster_dimensions: UVec4, // xy are vec2(cluster_dimensions.xy) / vec2(view.width, view.height) @@ -149,7 +148,6 @@ pub struct GpuLights { n_directional_lights: u32, // offset from spot light's light index to spot light's shadow map index spot_light_shadowmap_offset: i32, - ambient_light_affects_lightmapped_meshes: u32, } // NOTE: When running bevy on Adreno GPU chipsets in WebGL, any value above 1 will result in a crash @@ -729,11 +727,9 @@ pub fn prepare_lights( &ExtractedClusterConfig, Option<&RenderLayers>, Has, - Option<&AmbientLight>, ), With, >, - ambient_light: Res, point_light_shadow_map: Res, directional_light_shadow_map: Res, mut shadow_render_phases: ResMut>, @@ -1142,18 +1138,11 @@ pub fn prepare_lights( let mut live_views = EntityHashSet::with_capacity(views_count); // set up light data for each view - for ( - entity, - camera_main_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()) + for (entity, camera_main_entity, extracted_view, clusters, maybe_layers, no_indirect_drawing) in + sorted_cameras + .0 + .iter() + .filter_map(|sorted_camera| views.get(sorted_camera.entity).ok()) { live_views.insert(entity); @@ -1175,11 +1164,8 @@ 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()) - * ambient_light.brightness, cluster_factors: Vec4::new( clusters.dimensions.x as f32 / extracted_view.viewport.z as f32, clusters.dimensions.y as f32 / extracted_view.viewport.w as f32, @@ -1194,8 +1180,6 @@ pub fn prepare_lights( // index to shadow map index, we need to subtract point light count and add directional shadowmap count. spot_light_shadowmap_offset: num_directional_cascades_enabled as i32 - point_light_count as i32, - ambient_light_affects_lightmapped_meshes: ambient_light.affects_lightmapped_meshes - as u32, }; // TODO: this should select lights based on relevance to the view instead of the first ones that show up in a query diff --git a/crates/bevy_pbr/src/render/mesh_view_types.wgsl b/crates/bevy_pbr/src/render/mesh_view_types.wgsl index 6db72759df307..cd46708e74f9d 100644 --- a/crates/bevy_pbr/src/render/mesh_view_types.wgsl +++ b/crates/bevy_pbr/src/render/mesh_view_types.wgsl @@ -50,7 +50,6 @@ const DIRECTIONAL_LIGHT_FLAGS_AFFECTS_LIGHTMAPPED_MESH_DIFFUSE_BIT: u32 = 4u; struct Lights { // NOTE: this array size must be kept in sync with the constants defined in bevy_pbr/src/render/light.rs directional_lights: array, - ambient_color: vec4, // x/y/z dimensions and n_clusters in w cluster_dimensions: vec4, // xy are vec2(cluster_dimensions.xy) / vec2(view.width, view.height) diff --git a/crates/bevy_pbr/src/render/pbr_ambient.wgsl b/crates/bevy_pbr/src/render/pbr_ambient.wgsl deleted file mode 100644 index 7b174da35c9db..0000000000000 --- a/crates/bevy_pbr/src/render/pbr_ambient.wgsl +++ /dev/null @@ -1,29 +0,0 @@ -#define_import_path bevy_pbr::ambient - -#import bevy_pbr::{ - lighting::{EnvBRDFApprox, F_AB}, - mesh_view_bindings::lights, -} - -// A precomputed `NdotV` is provided because it is computed regardless, -// but `world_normal` and the view vector `V` are provided separately for more advanced uses. -fn ambient_light( - world_position: vec4, - world_normal: vec3, - V: vec3, - NdotV: f32, - diffuse_color: vec3, - specular_color: vec3, - perceptual_roughness: f32, - occlusion: vec3, -) -> vec3 { - let diffuse_ambient = EnvBRDFApprox(diffuse_color, F_AB(1.0, NdotV)); - let specular_ambient = EnvBRDFApprox(specular_color, F_AB(perceptual_roughness, NdotV)); - - // No real world material has specular values under 0.02, so we use this range as a - // "pre-baked specular occlusion" that extinguishes the fresnel term, for artistic control. - // See: https://google.github.io/filament/Filament.html#specularocclusion - let specular_occlusion = saturate(dot(specular_color, vec3(50.0 * 0.33))); - - return (diffuse_ambient + specular_ambient * specular_occlusion) * lights.ambient_color.rgb * occlusion; -} diff --git a/crates/bevy_pbr/src/render/pbr_functions.wgsl b/crates/bevy_pbr/src/render/pbr_functions.wgsl index e9b4e1f1a844d..72d8ed35dcb50 100644 --- a/crates/bevy_pbr/src/render/pbr_functions.wgsl +++ b/crates/bevy_pbr/src/render/pbr_functions.wgsl @@ -561,18 +561,6 @@ fn apply_pbr_lighting( #endif } -#ifdef STANDARD_MATERIAL_DIFFUSE_TRANSMISSION - // NOTE: We use the diffuse transmissive color, the second Lambertian lobe's calculated - // world position, inverted normal and view vectors, and the following simplified - // values for a fully diffuse transmitted light contribution approximation: - // - // perceptual_roughness = 1.0; - // NdotV = 1.0; - // F0 = vec3(0.0) - // diffuse_occlusion = vec3(1.0) - transmitted_light += ambient::ambient_light(diffuse_transmissive_lobe_world_position, -in.N, -in.V, 1.0, diffuse_transmissive_color, vec3(0.0), 1.0, vec3(1.0)); -#endif - // Diffuse indirect lighting can come from a variety of sources. The // priority goes like this: // @@ -644,9 +632,6 @@ fn apply_pbr_lighting( #endif // ENVIRONMENT_MAP - // Ambient light (indirect) - indirect_light += ambient::ambient_light(in.world_position, in.N, in.V, NdotV, diffuse_color, F0, perceptual_roughness, diffuse_occlusion); - // we'll use the specular component of the transmitted environment // light in the call to `specular_transmissive_light()` below var specular_transmitted_environment_light = vec3(0.0); diff --git a/examples/2d/custom_gltf_vertex_attribute.rs b/examples/2d/custom_gltf_vertex_attribute.rs index 0742e3616fe04..903898ce7f651 100644 --- a/examples/2d/custom_gltf_vertex_attribute.rs +++ b/examples/2d/custom_gltf_vertex_attribute.rs @@ -24,11 +24,6 @@ const ATTRIBUTE_BARYCENTRIC: MeshVertexAttribute = fn main() { App::new() - .insert_resource(AmbientLight { - color: Color::WHITE, - brightness: 1.0 / 5.0f32, - ..default() - }) .add_plugins(( DefaultPlugins.set( GltfPlugin::default() @@ -48,6 +43,7 @@ fn setup( mut commands: Commands, asset_server: Res, mut materials: ResMut>, + mut images: ResMut>, ) { // Add a mesh loaded from a glTF file. This mesh has data for `ATTRIBUTE_BARYCENTRIC`. let mesh = asset_server.load( @@ -63,7 +59,13 @@ fn setup( Transform::from_scale(150.0 * Vec3::ONE), )); - commands.spawn(Camera2d); + commands.spawn(( + Camera2d, + EnvironmentMapLight { + intensity: 1.0 / 5.0, + ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + }, + )); } /// This custom material uses barycentric coordinates from diff --git a/examples/3d/auto_exposure.rs b/examples/3d/auto_exposure.rs index 79fece61c8e36..027d06fa4fc59 100644 --- a/examples/3d/auto_exposure.rs +++ b/examples/3d/auto_exposure.rs @@ -101,11 +101,11 @@ fn setup( } } - commands.insert_resource(AmbientLight { - color: Color::WHITE, - brightness: 0.0, - ..default() - }); + #[expect( + deprecated, + reason = "Once AmbientLight is removed, the resource can be removed" + )] + commands.insert_resource(AmbientLight::NONE); commands.spawn(( PointLight { diff --git a/examples/3d/fog.rs b/examples/3d/fog.rs index 9793ae0ad356a..0f713b5cdd3bc 100644 --- a/examples/3d/fog.rs +++ b/examples/3d/fog.rs @@ -21,6 +21,10 @@ use bevy::{ }; fn main() { + #[expect( + deprecated, + reason = "Once AmbientLight is removed, the resource can be removed" + )] App::new() .insert_resource(AmbientLight::NONE) .add_plugins(DefaultPlugins) diff --git a/examples/3d/fog_volumes.rs b/examples/3d/fog_volumes.rs index 68fc6d0ea783e..189a397894804 100644 --- a/examples/3d/fog_volumes.rs +++ b/examples/3d/fog_volumes.rs @@ -13,6 +13,10 @@ use bevy::{ /// Entry point. fn main() { + #[expect( + deprecated, + reason = "Once AmbientLight is removed, the resource can be removed" + )] App::new() .add_plugins(DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { diff --git a/examples/3d/irradiance_volumes.rs b/examples/3d/irradiance_volumes.rs index 31529c421986d..dffe5fb9bf05c 100644 --- a/examples/3d/irradiance_volumes.rs +++ b/examples/3d/irradiance_volumes.rs @@ -157,11 +157,6 @@ fn main() { .add_plugins(MaterialPlugin::::default()) .init_resource::() .init_resource::() - .insert_resource(AmbientLight { - color: Color::WHITE, - brightness: 0.0, - ..default() - }) .add_systems(Startup, setup) .add_systems(PreUpdate, create_cubes) .add_systems(Update, rotate_camera) @@ -216,9 +211,14 @@ fn main() { } // Spawns all the scene objects. -fn setup(mut commands: Commands, assets: Res, app_status: Res) { +fn setup( + mut commands: Commands, + images: ResMut>, + assets: Res, + app_status: Res, +) { spawn_main_scene(&mut commands, &assets); - spawn_camera(&mut commands, &assets); + spawn_camera(&mut commands, images, &assets); spawn_irradiance_volume(&mut commands, &assets); spawn_light(&mut commands); spawn_sphere(&mut commands, &assets); @@ -231,7 +231,11 @@ fn spawn_main_scene(commands: &mut Commands, assets: &ExampleAssets) { commands.spawn(SceneRoot(assets.main_scene.clone())); } -fn spawn_camera(commands: &mut Commands, assets: &ExampleAssets) { +fn spawn_camera( + commands: &mut Commands, + mut images: ResMut>, + assets: &ExampleAssets, +) { commands.spawn(( Camera3d::default(), Transform::from_xyz(-10.012, 4.8605, 13.281).looking_at(Vec3::ZERO, Vec3::Y), @@ -240,6 +244,10 @@ fn spawn_camera(commands: &mut Commands, assets: &ExampleAssets) { brightness: 150.0, ..default() }, + EnvironmentMapLight { + intensity: 0.0, + ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + }, )); } @@ -415,7 +423,7 @@ fn toggle_irradiance_volumes( light_probe_query: Query>, mut app_status: ResMut, assets: Res, - mut ambient_light: ResMut, + mut ambient_light: Query<&mut EnvironmentMapLight>, ) { if !keyboard.just_pressed(KeyCode::Space) { return; @@ -427,7 +435,9 @@ fn toggle_irradiance_volumes( if app_status.irradiance_volume_present { commands.entity(light_probe).remove::(); - ambient_light.brightness = AMBIENT_LIGHT_BRIGHTNESS * IRRADIANCE_VOLUME_INTENSITY; + for mut light in ambient_light.iter_mut() { + light.intensity = AMBIENT_LIGHT_BRIGHTNESS * IRRADIANCE_VOLUME_INTENSITY; + } app_status.irradiance_volume_present = false; } else { commands.entity(light_probe).insert(IrradianceVolume { @@ -435,7 +445,9 @@ fn toggle_irradiance_volumes( intensity: IRRADIANCE_VOLUME_INTENSITY, ..default() }); - ambient_light.brightness = 0.0; + for mut light in ambient_light.iter_mut() { + light.intensity = 0.0; + } app_status.irradiance_volume_present = true; } } diff --git a/examples/3d/lighting.rs b/examples/3d/lighting.rs index b8d7883763019..226a8f90b74c2 100644 --- a/examples/3d/lighting.rs +++ b/examples/3d/lighting.rs @@ -35,6 +35,7 @@ fn setup( parameters: Res, mut commands: Commands, mut meshes: ResMut>, + mut images: ResMut>, mut materials: ResMut>, asset_server: Res, ) { @@ -110,13 +111,6 @@ fn setup( Movable, )); - // ambient light - commands.insert_resource(AmbientLight { - color: ORANGE_RED.into(), - brightness: 0.02, - ..default() - }); - // red point light commands.spawn(( PointLight { @@ -236,6 +230,10 @@ fn setup( Camera3d::default(), Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), Exposure::from_physical_camera(**parameters), + EnvironmentMapLight { + intensity: 0.02, + ..EnvironmentMapLight::solid_color(&mut images, ORANGE_RED.into()) + }, )); } diff --git a/examples/3d/lightmaps.rs b/examples/3d/lightmaps.rs index 975b37d7f2873..824b548687cb9 100644 --- a/examples/3d/lightmaps.rs +++ b/examples/3d/lightmaps.rs @@ -25,6 +25,10 @@ fn main() { let args: Args = Args::from_args(&[], &[]).unwrap(); let mut app = App::new(); + #[expect( + deprecated, + reason = "Once AmbientLight is removed, the resource can be removed" + )] app.add_plugins(DefaultPlugins) .insert_resource(AmbientLight::NONE); diff --git a/examples/3d/mixed_lighting.rs b/examples/3d/mixed_lighting.rs index f7ebbd5cfca3a..49a1c2f097701 100644 --- a/examples/3d/mixed_lighting.rs +++ b/examples/3d/mixed_lighting.rs @@ -123,11 +123,6 @@ fn main() { ..default() })) .add_plugins(MeshPickingPlugin) - .insert_resource(AmbientLight { - color: ClearColor::default().0, - brightness: 10000.0, - affects_lightmapped_meshes: true, - }) .init_resource::() .add_event::>() .add_event::() @@ -145,18 +140,28 @@ fn main() { } /// Creates the scene. -fn setup(mut commands: Commands, asset_server: Res, app_status: Res) { - spawn_camera(&mut commands); +fn setup( + mut commands: Commands, + images: ResMut>, + asset_server: Res, + app_status: Res, +) { + spawn_camera(&mut commands, images); spawn_scene(&mut commands, &asset_server); spawn_buttons(&mut commands); spawn_help_text(&mut commands, &app_status); } /// Spawns the 3D camera. -fn spawn_camera(commands: &mut Commands) { - commands - .spawn(Camera3d::default()) - .insert(Transform::from_xyz(-0.7, 0.7, 1.0).looking_at(vec3(0.0, 0.3, 0.0), Vec3::Y)); +fn spawn_camera(commands: &mut Commands, mut images: ResMut>) { + commands.spawn(( + Camera3d::default(), + Transform::from_xyz(-0.7, 0.7, 1.0).looking_at(vec3(0.0, 0.3, 0.0), Vec3::Y), + EnvironmentMapLight { + intensity: 10000.0, + ..EnvironmentMapLight::solid_color(&mut images, ClearColor::default().0) + }, + )); } /// Spawns the scene. diff --git a/examples/3d/motion_blur.rs b/examples/3d/motion_blur.rs index 68bb556c6b3e0..3d3cbab2c9cde 100644 --- a/examples/3d/motion_blur.rs +++ b/examples/3d/motion_blur.rs @@ -17,7 +17,7 @@ fn main() { .run(); } -fn setup_camera(mut commands: Commands) { +fn setup_camera(mut commands: Commands, mut images: ResMut>) { commands.spawn(( Camera3d::default(), // Add the `MotionBlur` component to a camera to enable motion blur. @@ -32,6 +32,10 @@ fn setup_camera(mut commands: Commands) { // MSAA and Motion Blur together are not compatible on WebGL #[cfg(all(feature = "webgl2", target_arch = "wasm32", not(feature = "webgpu")))] Msaa::Off, + EnvironmentMapLight { + intensity: 300.0, + ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + }, )); } @@ -59,11 +63,6 @@ fn setup_scene( mut meshes: ResMut>, mut materials: ResMut>, ) { - commands.insert_resource(AmbientLight { - color: Color::WHITE, - brightness: 300.0, - ..default() - }); commands.insert_resource(CameraMode::Chase); commands.spawn(( DirectionalLight { diff --git a/examples/3d/skybox.rs b/examples/3d/skybox.rs index dd797473bf57d..9c009eb8d2461 100644 --- a/examples/3d/skybox.rs +++ b/examples/3d/skybox.rs @@ -57,7 +57,11 @@ struct Cubemap { image_handle: Handle, } -fn setup(mut commands: Commands, asset_server: Res) { +fn setup( + mut commands: Commands, + asset_server: Res, + mut images: ResMut>, +) { // directional 'sun' light commands.spawn(( DirectionalLight { @@ -78,17 +82,15 @@ fn setup(mut commands: Commands, asset_server: Res) { brightness: 1000.0, ..default() }, + // This should ideally be using a convolved environment map for diffuse, but for simplicity + // we're just using a solid color here. + EnvironmentMapLight { + intensity: 1.0, + specular_map: skybox_handle.clone(), + ..EnvironmentMapLight::solid_color(&mut images, Color::srgb_u8(210, 220, 240)) + }, )); - // 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 { - color: Color::srgb_u8(210, 220, 240), - brightness: 1.0, - ..default() - }); - commands.insert_resource(Cubemap { is_loaded: false, index: 0, diff --git a/examples/3d/specular_tint.rs b/examples/3d/specular_tint.rs index 5dc362b9c12e6..6954a0204980e 100644 --- a/examples/3d/specular_tint.rs +++ b/examples/3d/specular_tint.rs @@ -49,6 +49,10 @@ enum TintType { /// The entry point. fn main() { + #[expect( + deprecated, + reason = "Once AmbientLight is removed, the resource can be removed" + )] App::new() .add_plugins(DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { @@ -59,11 +63,7 @@ fn main() { })) .init_resource::() .init_resource::() - .insert_resource(AmbientLight { - color: Color::BLACK, - brightness: 0.0, - ..default() - }) + .insert_resource(AmbientLight::NONE) .add_systems(Startup, setup) .add_systems(Update, rotate_camera) .add_systems(Update, (toggle_specular_map, update_text).chain()) diff --git a/examples/3d/spherical_area_lights.rs b/examples/3d/spherical_area_lights.rs index c3e945a8f3492..9c7c1486e89e6 100644 --- a/examples/3d/spherical_area_lights.rs +++ b/examples/3d/spherical_area_lights.rs @@ -4,10 +4,6 @@ use bevy::prelude::*; fn main() { App::new() - .insert_resource(AmbientLight { - brightness: 60.0, - ..default() - }) .add_plugins(DefaultPlugins) .add_systems(Startup, setup) .run(); @@ -16,12 +12,17 @@ fn main() { fn setup( mut commands: Commands, mut meshes: ResMut>, + mut images: ResMut>, mut materials: ResMut>, ) { // camera commands.spawn(( Camera3d::default(), Transform::from_xyz(0.2, 1.5, 2.5).looking_at(Vec3::ZERO, Vec3::Y), + EnvironmentMapLight { + intensity: 60.0, + ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + }, )); // plane diff --git a/examples/3d/spotlight.rs b/examples/3d/spotlight.rs index c92843404ef37..b71374582176f 100644 --- a/examples/3d/spotlight.rs +++ b/examples/3d/spotlight.rs @@ -20,10 +20,6 @@ Rotate Camera: Left and Right Arrows"; fn main() { App::new() - .insert_resource(AmbientLight { - brightness: 20.0, - ..default() - }) .add_plugins(DefaultPlugins) .add_systems(Startup, setup) .add_systems(Update, (light_sway, movement, rotation)) @@ -37,6 +33,7 @@ struct Movable; fn setup( mut commands: Commands, mut meshes: ResMut>, + mut images: ResMut>, mut materials: ResMut>, ) { // ground plane @@ -124,6 +121,10 @@ fn setup( ..default() }, Transform::from_xyz(-4.0, 5.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y), + EnvironmentMapLight { + intensity: 20.0, + ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + }, )); commands.spawn(( diff --git a/examples/3d/ssao.rs b/examples/3d/ssao.rs index 17c54db633a8d..5e3031afb384b 100644 --- a/examples/3d/ssao.rs +++ b/examples/3d/ssao.rs @@ -11,10 +11,6 @@ use std::f32::consts::PI; fn main() { App::new() - .insert_resource(AmbientLight { - brightness: 1000., - ..default() - }) .add_plugins((DefaultPlugins, TemporalAntiAliasPlugin)) .add_systems(Startup, setup) .add_systems(Update, update) @@ -24,6 +20,7 @@ fn main() { fn setup( mut commands: Commands, mut meshes: ResMut>, + mut images: ResMut>, mut materials: ResMut>, ) { commands.spawn(( @@ -36,6 +33,10 @@ fn setup( Msaa::Off, ScreenSpaceAmbientOcclusion::default(), TemporalAntiAliasing::default(), + EnvironmentMapLight { + intensity: 1000.0, + ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + }, )); let material = materials.add(StandardMaterial { diff --git a/examples/3d/transmission.rs b/examples/3d/transmission.rs index 97f1014c22a89..a0f126fc3cf7e 100644 --- a/examples/3d/transmission.rs +++ b/examples/3d/transmission.rs @@ -42,13 +42,14 @@ use rand::random; fn main() { let mut app = App::new(); + #[expect( + deprecated, + reason = "Once AmbientLight is removed, the resource can be removed" + )] app.add_plugins(DefaultPlugins) .insert_resource(ClearColor(Color::BLACK)) .insert_resource(PointLightShadowMap { size: 2048 }) - .insert_resource(AmbientLight { - brightness: 0.0, - ..default() - }) + .insert_resource(AmbientLight::NONE) .add_systems(Startup, setup) .add_systems(Update, (example_control_system, flicker_system)); diff --git a/examples/3d/volumetric_fog.rs b/examples/3d/volumetric_fog.rs index 9cfef624c6594..8130c8a3f716a 100644 --- a/examples/3d/volumetric_fog.rs +++ b/examples/3d/volumetric_fog.rs @@ -37,6 +37,10 @@ struct MoveBackAndForthHorizontally { } fn main() { + #[expect( + deprecated, + reason = "Once AmbientLight is removed, the resource can be removed" + )] App::new() .add_plugins(DefaultPlugins) .insert_resource(ClearColor(Color::Srgba(Srgba { diff --git a/examples/animation/animated_mesh.rs b/examples/animation/animated_mesh.rs index ecea86fb178a7..4ac6cb3fde701 100644 --- a/examples/animation/animated_mesh.rs +++ b/examples/animation/animated_mesh.rs @@ -9,11 +9,6 @@ const GLTF_PATH: &str = "models/animated/Fox.glb"; fn main() { App::new() - .insert_resource(AmbientLight { - color: Color::WHITE, - brightness: 2000., - ..default() - }) .add_plugins(DefaultPlugins) .add_systems(Startup, setup_mesh_and_animation) .add_systems(Startup, setup_camera_and_environment) @@ -98,12 +93,17 @@ fn play_animation_when_ready( fn setup_camera_and_environment( mut commands: Commands, mut meshes: ResMut>, + mut images: ResMut>, mut materials: ResMut>, ) { // Camera commands.spawn(( Camera3d::default(), Transform::from_xyz(100.0, 100.0, 150.0).looking_at(Vec3::new(0.0, 20.0, 0.0), Vec3::Y), + EnvironmentMapLight { + intensity: 2000.0, + ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + }, )); // Plane diff --git a/examples/animation/animated_mesh_control.rs b/examples/animation/animated_mesh_control.rs index 0dafd0de11892..0bf23a42c5446 100644 --- a/examples/animation/animated_mesh_control.rs +++ b/examples/animation/animated_mesh_control.rs @@ -8,11 +8,6 @@ const FOX_PATH: &str = "models/animated/Fox.glb"; fn main() { App::new() - .insert_resource(AmbientLight { - color: Color::WHITE, - brightness: 2000., - ..default() - }) .add_plugins(DefaultPlugins) .add_systems(Startup, setup) .add_systems(Update, setup_scene_once_loaded) @@ -30,6 +25,7 @@ fn setup( mut commands: Commands, asset_server: Res, mut meshes: ResMut>, + mut images: ResMut>, mut materials: ResMut>, mut graphs: ResMut>, ) { @@ -52,6 +48,10 @@ fn setup( commands.spawn(( Camera3d::default(), Transform::from_xyz(100.0, 100.0, 150.0).looking_at(Vec3::new(0.0, 20.0, 0.0), Vec3::Y), + EnvironmentMapLight { + intensity: 2000.0, + ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + }, )); // Plane diff --git a/examples/animation/animated_mesh_events.rs b/examples/animation/animated_mesh_events.rs index 2048f573fd704..73b98524085de 100644 --- a/examples/animation/animated_mesh_events.rs +++ b/examples/animation/animated_mesh_events.rs @@ -13,11 +13,6 @@ const FOX_PATH: &str = "models/animated/Fox.glb"; fn main() { App::new() - .insert_resource(AmbientLight { - color: Color::WHITE, - brightness: 2000., - ..default() - }) .add_plugins(DefaultPlugins) .init_resource::() .init_resource::() @@ -78,6 +73,7 @@ fn setup( mut commands: Commands, asset_server: Res, mut meshes: ResMut>, + mut images: ResMut>, mut materials: ResMut>, mut graphs: ResMut>, ) { @@ -98,6 +94,10 @@ fn setup( commands.spawn(( Camera3d::default(), Transform::from_xyz(100.0, 100.0, 150.0).looking_at(Vec3::new(0.0, 20.0, 0.0), Vec3::Y), + EnvironmentMapLight { + intensity: 2000.0, + ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + }, )); // Plane diff --git a/examples/animation/animated_transform.rs b/examples/animation/animated_transform.rs index decb3d34a69df..08e7528797c77 100644 --- a/examples/animation/animated_transform.rs +++ b/examples/animation/animated_transform.rs @@ -10,11 +10,6 @@ use bevy::{ fn main() { App::new() .add_plugins(DefaultPlugins) - .insert_resource(AmbientLight { - color: Color::WHITE, - brightness: 150.0, - ..default() - }) .add_systems(Startup, setup) .run(); } @@ -22,6 +17,7 @@ fn main() { fn setup( mut commands: Commands, mut meshes: ResMut>, + mut images: ResMut>, mut materials: ResMut>, mut animations: ResMut>, mut graphs: ResMut>, @@ -30,6 +26,10 @@ fn setup( commands.spawn(( Camera3d::default(), Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), + EnvironmentMapLight { + intensity: 150.0, + ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + }, )); // Light diff --git a/examples/animation/animation_graph.rs b/examples/animation/animation_graph.rs index 76da8a6644ef1..d063f321d0c67 100644 --- a/examples/animation/animation_graph.rs +++ b/examples/animation/animation_graph.rs @@ -88,11 +88,6 @@ fn main() { (handle_weight_drag, update_ui, sync_weights).chain(), ) .insert_resource(args) - .insert_resource(AmbientLight { - color: WHITE.into(), - brightness: 100.0, - ..default() - }) .run(); } @@ -216,11 +211,16 @@ fn setup_scene( mut commands: Commands, asset_server: Res, mut meshes: ResMut>, + mut images: ResMut>, mut materials: ResMut>, ) { commands.spawn(( Camera3d::default(), Transform::from_xyz(-10.0, 5.0, 13.0).looking_at(Vec3::new(0., 1., 0.), Vec3::Y), + EnvironmentMapLight { + intensity: 100.0, + ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + }, )); commands.spawn(( diff --git a/examples/animation/animation_masks.rs b/examples/animation/animation_masks.rs index 72408260d62f6..131656e82e278 100644 --- a/examples/animation/animation_masks.rs +++ b/examples/animation/animation_masks.rs @@ -2,7 +2,7 @@ use bevy::{ animation::{AnimationTarget, AnimationTargetId}, - color::palettes::css::{LIGHT_GRAY, WHITE}, + color::palettes::css::LIGHT_GRAY, prelude::*, }; use std::collections::HashSet; @@ -105,11 +105,6 @@ fn main() { .add_systems(Update, setup_animation_graph_once_loaded) .add_systems(Update, handle_button_toggles) .add_systems(Update, update_ui) - .insert_resource(AmbientLight { - color: WHITE.into(), - brightness: 100.0, - ..default() - }) .init_resource::() .run(); } @@ -120,12 +115,17 @@ fn setup_scene( mut commands: Commands, asset_server: Res, mut meshes: ResMut>, + mut images: ResMut>, mut materials: ResMut>, ) { // Spawn the camera. commands.spawn(( Camera3d::default(), Transform::from_xyz(-15.0, 10.0, 20.0).looking_at(Vec3::new(0., 1., 0.), Vec3::Y), + EnvironmentMapLight { + intensity: 100.0, + ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + }, )); // Spawn the light. diff --git a/examples/animation/custom_skinned_mesh.rs b/examples/animation/custom_skinned_mesh.rs index b091f2dd4254c..d86e98295add8 100644 --- a/examples/animation/custom_skinned_mesh.rs +++ b/examples/animation/custom_skinned_mesh.rs @@ -20,10 +20,6 @@ use rand_chacha::ChaCha8Rng; fn main() { App::new() .add_plugins(DefaultPlugins) - .insert_resource(AmbientLight { - brightness: 3000.0, - ..default() - }) .add_systems(Startup, setup) .add_systems(Update, joint_animation) .run(); @@ -40,6 +36,7 @@ fn setup( mut commands: Commands, asset_server: Res, mut meshes: ResMut>, + mut images: ResMut>, mut materials: ResMut>, mut skinned_mesh_inverse_bindposes_assets: ResMut>, ) { @@ -47,6 +44,10 @@ fn setup( commands.spawn(( Camera3d::default(), Transform::from_xyz(2.5, 2.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y), + EnvironmentMapLight { + intensity: 3000.0, + ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + }, )); // Create inverse bindpose matrices for a skeleton consists of 2 joints diff --git a/examples/animation/gltf_skinned_mesh.rs b/examples/animation/gltf_skinned_mesh.rs index 48f7cd6f39c89..5f414087fa2ef 100644 --- a/examples/animation/gltf_skinned_mesh.rs +++ b/examples/animation/gltf_skinned_mesh.rs @@ -8,20 +8,24 @@ use bevy::{math::ops, prelude::*, render::mesh::skinning::SkinnedMesh}; fn main() { App::new() .add_plugins(DefaultPlugins) - .insert_resource(AmbientLight { - brightness: 750.0, - ..default() - }) .add_systems(Startup, setup) .add_systems(Update, joint_animation) .run(); } -fn setup(mut commands: Commands, asset_server: Res) { +fn setup( + mut commands: Commands, + asset_server: Res, + mut images: ResMut>, +) { // Create a camera commands.spawn(( Camera3d::default(), Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::new(0.0, 1.0, 0.0), Vec3::Y), + EnvironmentMapLight { + intensity: 750.0, + ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + }, )); // Spawn the first scene in `models/SimpleSkin/SimpleSkin.gltf` diff --git a/examples/animation/morph_targets.rs b/examples/animation/morph_targets.rs index 258059bf55655..7c2c9a00ac6dd 100644 --- a/examples/animation/morph_targets.rs +++ b/examples/animation/morph_targets.rs @@ -19,10 +19,6 @@ fn main() { }), ..default() })) - .insert_resource(AmbientLight { - brightness: 150.0, - ..default() - }) .add_systems(Startup, setup) .add_systems(Update, (name_morphs, setup_animations)) .run(); @@ -34,7 +30,11 @@ struct MorphData { mesh: Handle, } -fn setup(asset_server: Res, mut commands: Commands) { +fn setup( + asset_server: Res, + mut commands: Commands, + mut images: ResMut>, +) { commands.insert_resource(MorphData { the_wave: asset_server .load(GltfAssetLabel::Animation(2).from_asset("models/animated/MorphStressTest.gltf")), @@ -56,6 +56,10 @@ fn setup(asset_server: Res, mut commands: Commands) { commands.spawn(( Camera3d::default(), Transform::from_xyz(3.0, 2.1, 10.2).looking_at(Vec3::ZERO, Vec3::Y), + EnvironmentMapLight { + intensity: 150.0, + ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + }, )); } diff --git a/examples/asset/multi_asset_sync.rs b/examples/asset/multi_asset_sync.rs index cc233eb5fd4db..c4b4c9268480f 100644 --- a/examples/asset/multi_asset_sync.rs +++ b/examples/asset/multi_asset_sync.rs @@ -17,11 +17,6 @@ fn main() { App::new() .add_plugins(DefaultPlugins) .init_state::() - .insert_resource(AmbientLight { - color: Color::WHITE, - brightness: 2000., - ..default() - }) .add_systems(Startup, setup_assets) .add_systems(Startup, setup_scene) .add_systems(Startup, setup_ui) @@ -185,12 +180,17 @@ fn setup_ui(mut commands: Commands) { fn setup_scene( mut commands: Commands, mut meshes: ResMut>, + mut images: ResMut>, mut materials: ResMut>, ) { // Camera commands.spawn(( Camera3d::default(), Transform::from_xyz(10.0, 10.0, 15.0).looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y), + EnvironmentMapLight { + intensity: 2000.0, + ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + }, )); // Light diff --git a/examples/math/render_primitives.rs b/examples/math/render_primitives.rs index 56633977e6d81..26246faf79c34 100644 --- a/examples/math/render_primitives.rs +++ b/examples/math/render_primitives.rs @@ -14,7 +14,7 @@ fn main() { .init_state::(); // cameras - app.add_systems(Startup, (setup_cameras, setup_lights, setup_ambient_light)) + app.add_systems(Startup, (setup_cameras, setup_lights)) .add_systems( Update, ( @@ -292,14 +292,21 @@ const CIRCULAR_SEGMENT: CircularSegment = CircularSegment { }, }; -fn setup_cameras(mut commands: Commands) { +fn setup_cameras(mut commands: Commands, mut images: ResMut>) { let start_in_2d = true; let make_camera = |is_active| Camera { is_active, ..Default::default() }; - commands.spawn((Camera2d, make_camera(start_in_2d))); + commands.spawn(( + Camera2d, + make_camera(start_in_2d), + EnvironmentMapLight { + intensity: 50.0, + ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + }, + )); commands.spawn(( Camera3d::default(), @@ -308,10 +315,6 @@ fn setup_cameras(mut commands: Commands) { )); } -fn setup_ambient_light(mut ambient_light: ResMut) { - ambient_light.brightness = 50.0; -} - fn setup_lights(mut commands: Commands) { commands.spawn(( PointLight { From 8274ccf96b3d190b15480aed1d6fc16f22e00ed0 Mon Sep 17 00:00:00 2001 From: SparkyPotato Date: Mon, 10 Mar 2025 22:20:29 +0000 Subject: [PATCH 02/18] replace default AmbientLight with default EnvironmentMapLight --- crates/bevy_pbr/src/lib.rs | 23 ++++++++++++++++--- crates/bevy_pbr/src/light/mod.rs | 13 +++++++---- .../src/light_probe/environment_map.rs | 21 ++++++++++------- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/crates/bevy_pbr/src/lib.rs b/crates/bevy_pbr/src/lib.rs index 75f04581472b4..5feb4a25981b2 100644 --- a/crates/bevy_pbr/src/lib.rs +++ b/crates/bevy_pbr/src/lib.rs @@ -128,10 +128,16 @@ pub mod graph { } } -use crate::{deferred::DeferredPbrLightingPlugin, graph::NodePbr}; +use crate::{ + deferred::DeferredPbrLightingPlugin, environment_map::DEFAULT_ENVIRONMENT_MAP_TEXTURE_HANDLE, + graph::NodePbr, prelude::EnvironmentMapLight, +}; use bevy_app::prelude::*; use bevy_asset::{load_internal_asset, weak_handle, AssetApp, Assets, Handle}; -use bevy_core_pipeline::core_3d::graph::{Core3d, Node3d}; +use bevy_core_pipeline::core_3d::{ + graph::{Core3d, Node3d}, + Camera3d, +}; use bevy_ecs::prelude::*; use bevy_image::Image; use bevy_render::{ @@ -203,6 +209,8 @@ pub struct PbrPlugin { pub use_gpu_instance_buffer_builder: bool, /// Debugging flags that can optionally be set when constructing the renderer. pub debug_flags: RenderDebugFlags, + /// Controls if the default environment map light is added to every [`Camera3d`]. + pub default_environment_map_light: bool, } impl Default for PbrPlugin { @@ -212,6 +220,7 @@ impl Default for PbrPlugin { add_default_deferred_lighting_plugin: true, use_gpu_instance_buffer_builder: true, debug_flags: RenderDebugFlags::default(), + default_environment_map_light: true, } } } @@ -344,7 +353,6 @@ impl Plugin for PbrPlugin { .register_type::() .register_type::() .register_type::() - .init_resource::() .init_resource::() .init_resource::() .init_resource::() @@ -457,6 +465,15 @@ impl Plugin for PbrPlugin { app.add_plugins(DeferredPbrLightingPlugin); } + if self.default_environment_map_light { + app.world_mut() + .register_required_components::(); + } + app.world_mut().resource_mut::>().insert( + &DEFAULT_ENVIRONMENT_MAP_TEXTURE_HANDLE, + EnvironmentMapLight::solid_color_image(Color::WHITE), + ); + // Initialize the default material handle. app.world_mut() .resource_mut::>() diff --git a/crates/bevy_pbr/src/light/mod.rs b/crates/bevy_pbr/src/light/mod.rs index 68d01ea6568cb..cba94fab5d761 100644 --- a/crates/bevy_pbr/src/light/mod.rs +++ b/crates/bevy_pbr/src/light/mod.rs @@ -537,7 +537,7 @@ pub struct EnvironmentMapLightFromAmbientLight; pub fn map_ambient_lights( mut commands: Commands, mut image_assets: ResMut>, - ambient_light: Res, + ambient_light: Option>, new_views: Query< (Entity, Option>), ( @@ -551,9 +551,12 @@ pub fn map_ambient_lights( With, >, ) { - let ambient_light = ambient_light.into(); + let ambient_light = ambient_light.map(|x| x.into()); + let ref_ambient_light = ambient_light.as_ref(); for (entity, ambient_override) in new_views.iter() { - let ambient = ambient_override.as_ref().unwrap_or(&ambient_light); + let Some(ambient) = ambient_override.as_ref().or(ref_ambient_light) else { + continue; + }; let ambient_required = ambient.brightness > 0.0 && ambient.color != Color::BLACK; if ambient_required && ambient.is_changed() { commands @@ -567,7 +570,9 @@ pub fn map_ambient_lights( } } for (mut env_map, ambient_override) in managed_views.iter_mut() { - let ambient = ambient_override.as_ref().unwrap_or(&ambient_light); + let Some(ambient) = ambient_override.as_ref().or(ref_ambient_light) else { + continue; + }; let ambient_required = ambient.brightness > 0.0 && ambient.color != Color::BLACK; if ambient_required && ambient.is_changed() { *env_map = EnvironmentMapLight { diff --git a/crates/bevy_pbr/src/light_probe/environment_map.rs b/crates/bevy_pbr/src/light_probe/environment_map.rs index fcc1b64a97808..9d9885952067a 100644 --- a/crates/bevy_pbr/src/light_probe/environment_map.rs +++ b/crates/bevy_pbr/src/light_probe/environment_map.rs @@ -117,10 +117,9 @@ pub struct EnvironmentMapLight { } impl EnvironmentMapLight { - /// An environment map with a uniform color, useful for uniform ambient lighting. - pub fn solid_color(assets: &mut Assets, color: Color) -> Self { + pub(crate) fn solid_color_image(color: Color) -> Image { let color: Srgba = color.into(); - let image = Image { + Image { texture_view_descriptor: Some(TextureViewDescriptor { dimension: Some(TextureViewDimension::Cube), ..Default::default() @@ -136,9 +135,12 @@ impl EnvironmentMapLight { TextureFormat::Rgba8UnormSrgb, RenderAssetUsages::RENDER_WORLD, ) - }; - let handle = assets.add(image); + } + } + /// An environment map with a uniform color, useful for uniform ambient lighting. + pub fn solid_color(assets: &mut Assets, color: Color) -> Self { + let handle = assets.add(Self::solid_color_image(color)); Self { diffuse_map: handle.clone(), specular_map: handle, @@ -193,12 +195,15 @@ impl EnvironmentMapLight { } } +pub const DEFAULT_ENVIRONMENT_MAP_TEXTURE_HANDLE: Handle = + weak_handle!("99e3f21e-9c08-4924-9895-fa8599416316"); + impl Default for EnvironmentMapLight { fn default() -> Self { EnvironmentMapLight { - diffuse_map: Handle::default(), - specular_map: Handle::default(), - intensity: 0.0, + diffuse_map: DEFAULT_ENVIRONMENT_MAP_TEXTURE_HANDLE, + specular_map: DEFAULT_ENVIRONMENT_MAP_TEXTURE_HANDLE, + intensity: 50.0, rotation: Quat::IDENTITY, affects_lightmapped_mesh_diffuse: true, } From 492016bb735dbcef9f43419ea5aa96d49a08210b Mon Sep 17 00:00:00 2001 From: SparkyPotato Date: Mon, 10 Mar 2025 22:24:40 +0000 Subject: [PATCH 03/18] clippy --- crates/bevy_pbr/src/light/ambient_light.rs | 2 +- crates/bevy_pbr/src/light/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_pbr/src/light/ambient_light.rs b/crates/bevy_pbr/src/light/ambient_light.rs index 14ab9a8b1f808..55c7861667b84 100644 --- a/crates/bevy_pbr/src/light/ambient_light.rs +++ b/crates/bevy_pbr/src/light/ambient_light.rs @@ -48,7 +48,7 @@ impl Default for AmbientLight { fn default() -> Self { Self { color: Color::WHITE, - brightness: 80.0, + brightness: 50.0, affects_lightmapped_meshes: true, } } diff --git a/crates/bevy_pbr/src/light/mod.rs b/crates/bevy_pbr/src/light/mod.rs index cba94fab5d761..48ad340871861 100644 --- a/crates/bevy_pbr/src/light/mod.rs +++ b/crates/bevy_pbr/src/light/mod.rs @@ -551,7 +551,7 @@ pub fn map_ambient_lights( With, >, ) { - let ambient_light = ambient_light.map(|x| x.into()); + let ambient_light = ambient_light.map(Into::into); let ref_ambient_light = ambient_light.as_ref(); for (entity, ambient_override) in new_views.iter() { let Some(ambient) = ambient_override.as_ref().or(ref_ambient_light) else { From 247c829269c7f5ce7aba189e7b223fd00b7035c7 Mon Sep 17 00:00:00 2001 From: SparkyPotato Date: Mon, 10 Mar 2025 22:47:55 +0000 Subject: [PATCH 04/18] rustdoc --- crates/bevy_pbr/src/light/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_pbr/src/light/mod.rs b/crates/bevy_pbr/src/light/mod.rs index 48ad340871861..bc2009a6bfc01 100644 --- a/crates/bevy_pbr/src/light/mod.rs +++ b/crates/bevy_pbr/src/light/mod.rs @@ -470,7 +470,7 @@ pub struct NotShadowReceiver; #[reflect(Component, Default, Debug)] pub struct TransmittedShadowReceiver; -/// Add this component to a [`Camera3d`](bevy_core_pipeline::core_3d::Camera3d) +/// Add this component to a [`Camera3d`] /// to control how to anti-alias shadow edges. /// /// The different modes use different approaches to From f52ac2dfac5910de5ce0381a3594ae37909bae64 Mon Sep 17 00:00:00 2001 From: SparkyPotato Date: Mon, 28 Jul 2025 22:28:40 +0100 Subject: [PATCH 05/18] get rid of unneeded extracts --- crates/bevy_light/src/lib.rs | 4 ++++ crates/bevy_render/src/extract_impls.rs | 20 ++------------------ 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/crates/bevy_light/src/lib.rs b/crates/bevy_light/src/lib.rs index 995ac610a59e0..b8a1a67c09c8d 100644 --- a/crates/bevy_light/src/lib.rs +++ b/crates/bevy_light/src/lib.rs @@ -28,6 +28,10 @@ use cluster::{ GlobalVisibleClusterableObjects, VisibleClusterableObjects, }; mod ambient_light; +#[expect( + deprecated, + reason = "AmbientLight has been replaced by EnvironmentMapLight" +)] pub use ambient_light::AmbientLight; mod probe; pub use probe::{EnvironmentMapLight, IrradianceVolume, LightProbe}; diff --git a/crates/bevy_render/src/extract_impls.rs b/crates/bevy_render/src/extract_impls.rs index 87b854363abea..1df8530838b9a 100644 --- a/crates/bevy_render/src/extract_impls.rs +++ b/crates/bevy_render/src/extract_impls.rs @@ -1,9 +1,9 @@ //! This module exists because of the orphan rule use bevy_ecs::query::QueryItem; -use bevy_light::{cluster::ClusteredDecal, AmbientLight, ShadowFilteringMethod}; +use bevy_light::{cluster::ClusteredDecal, ShadowFilteringMethod}; -use crate::{extract_component::ExtractComponent, extract_resource::ExtractResource}; +use crate::extract_component::ExtractComponent; impl ExtractComponent for ClusteredDecal { type QueryData = &'static Self; @@ -14,22 +14,6 @@ impl ExtractComponent for ClusteredDecal { Some(item.clone()) } } -impl ExtractResource for AmbientLight { - type Source = Self; - - fn extract_resource(source: &Self::Source) -> Self { - source.clone() - } -} -impl ExtractComponent for AmbientLight { - type QueryData = &'static Self; - type QueryFilter = (); - type Out = Self; - - fn extract_component(item: QueryItem) -> Option { - Some(item.clone()) - } -} impl ExtractComponent for ShadowFilteringMethod { type QueryData = &'static Self; type QueryFilter = (); From c70513bea06c9d3da0a2c83511768e344dc1695f Mon Sep 17 00:00:00 2001 From: SparkyPotato Date: Mon, 28 Jul 2025 22:44:43 +0100 Subject: [PATCH 06/18] fix ci --- examples/3d/lighting.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/3d/lighting.rs b/examples/3d/lighting.rs index a7441afc92748..3a1eea0a4cdd1 100644 --- a/examples/3d/lighting.rs +++ b/examples/3d/lighting.rs @@ -288,7 +288,7 @@ fn update_exposure( fn toggle_ambient_light( key_input: Res>, - mut environment_map_lights: Query<&mut EnvironmentMapLight>, + environment_map_lights: Query<&mut EnvironmentMapLight>, text: Single>, mut writer: TextUiWriter, ) { From 63790110e6a49bd77716de25cadb92df1846a164 Mon Sep 17 00:00:00 2001 From: SparkyPotato Date: Mon, 28 Jul 2025 23:02:20 +0100 Subject: [PATCH 07/18] fix invalid skinned mesh test --- tests/3d/test_invalid_skinned_mesh.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/3d/test_invalid_skinned_mesh.rs b/tests/3d/test_invalid_skinned_mesh.rs index a4567016ed3c5..a0229cc536786 100644 --- a/tests/3d/test_invalid_skinned_mesh.rs +++ b/tests/3d/test_invalid_skinned_mesh.rs @@ -18,10 +18,6 @@ use core::f32::consts::TAU; fn main() { App::new() .add_plugins(DefaultPlugins) - .insert_resource(AmbientLight { - brightness: 20_000.0, - ..default() - }) .add_systems(Startup, (setup_environment, setup_meshes)) .add_systems(Update, update_animated_joints) .run(); @@ -30,6 +26,7 @@ fn main() { fn setup_environment( mut commands: Commands, mut mesh_assets: ResMut>, + mut image_assets: ResMut>, mut material_assets: ResMut>, ) { let description = "(left to right)\n\ @@ -58,6 +55,10 @@ fn setup_environment( }, ..OrthographicProjection::default_3d() }), + EnvironmentMapLight { + intensity: 20_000.0, + ..EnvironmentMapLight::solid_color(&mut *image_assets, Color::WHITE) + }, // Add motion blur so we can check if it's working for skinned meshes. // This also exercises the renderer's prepass path. MotionBlur { From 1ea7cf5e3c5f2b58fefc334d3d71fc19c5d2aa86 Mon Sep 17 00:00:00 2001 From: SparkyPotato Date: Mon, 28 Jul 2025 23:18:24 +0100 Subject: [PATCH 08/18] clippy --- tests/3d/test_invalid_skinned_mesh.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/3d/test_invalid_skinned_mesh.rs b/tests/3d/test_invalid_skinned_mesh.rs index a0229cc536786..9993239d87550 100644 --- a/tests/3d/test_invalid_skinned_mesh.rs +++ b/tests/3d/test_invalid_skinned_mesh.rs @@ -57,7 +57,7 @@ fn setup_environment( }), EnvironmentMapLight { intensity: 20_000.0, - ..EnvironmentMapLight::solid_color(&mut *image_assets, Color::WHITE) + ..EnvironmentMapLight::solid_color(&mut image_assets, Color::WHITE) }, // Add motion blur so we can check if it's working for skinned meshes. // This also exercises the renderer's prepass path. From 1c4a8c9ae27547b76d2568a5e0118efc9ecf6bb3 Mon Sep 17 00:00:00 2001 From: SparkyPotato Date: Mon, 28 Jul 2025 23:52:25 +0100 Subject: [PATCH 09/18] fix doc --- crates/bevy_pbr/src/lib.rs | 3 ++- crates/bevy_pbr/src/light_probe/environment_map.rs | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/bevy_pbr/src/lib.rs b/crates/bevy_pbr/src/lib.rs index 0b339694c5a91..5ffd15d694629 100644 --- a/crates/bevy_pbr/src/lib.rs +++ b/crates/bevy_pbr/src/lib.rs @@ -181,7 +181,8 @@ pub struct PbrPlugin { /// This requires compute shader support and so will be forcibly disabled if /// the platform doesn't support those. pub use_gpu_instance_buffer_builder: bool, - /// Controls if the default environment map light is added to every [`Camera3d`]. + /// Controls if the default environment map light is added to every + /// [`Camera3d`](bevy_core_pipeline::prelude::Camera3d). pub default_environment_map_light: bool, /// Debugging flags that can optionally be set when constructing the renderer. pub debug_flags: RenderDebugFlags, diff --git a/crates/bevy_pbr/src/light_probe/environment_map.rs b/crates/bevy_pbr/src/light_probe/environment_map.rs index e6dfebd903ad1..d63a5fb2474b7 100644 --- a/crates/bevy_pbr/src/light_probe/environment_map.rs +++ b/crates/bevy_pbr/src/light_probe/environment_map.rs @@ -9,10 +9,9 @@ //! entities they're attached to have: //! //! 1. If attached to a view, they represent the objects located a very far -//! distance from the view, in a similar manner to a skybox. Essentially, these -//! *view environment maps* represent a higher-quality replacement for -//! [`AmbientLight`](crate::AmbientLight) for outdoor scenes. The indirect light from such -//! environment maps are added to every point of the scene, including +//! distance from the view, in a similar manner to a skybox. These +//! *view environment maps* provide ambient lighting for outdoor scenes. +//! The indirect light from such environment maps are added to every point of the scene, including //! interior enclosed areas. //! //! 2. If attached to a [`crate::LightProbe`], environment maps represent the immediate From 362be001e78adc73ae8fa12561d441f5a94edab3 Mon Sep 17 00:00:00 2001 From: SparkyPotato Date: Mon, 28 Jul 2025 22:43:35 +0100 Subject: [PATCH 10/18] add migration guide --- .../migration-guides/AmbientLight_deprecation.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 release-content/migration-guides/AmbientLight_deprecation.md diff --git a/release-content/migration-guides/AmbientLight_deprecation.md b/release-content/migration-guides/AmbientLight_deprecation.md new file mode 100644 index 0000000000000..521f5e4137bd5 --- /dev/null +++ b/release-content/migration-guides/AmbientLight_deprecation.md @@ -0,0 +1,9 @@ +--- +title: `AmbientLight` deprecated +pull_requests: [18207] +--- + +`AmbientLight`s have been deprecated in favor of using `EnvironmentMapLight`s for the same purpose. +All usages of an ambient light can be replaced by `EnvironmentMapLight::solid_color` added to the camera. +This will render slightly differently, as previously, `AmbientLight`s were (incorrectly) treated as diffuse-only light sources, +while `EnvironmentMapLight`s have both a specular and diffuse component. From c87a15c50d27d69d376ab60e94cf2e3777f5aca4 Mon Sep 17 00:00:00 2001 From: atlas dostal Date: Sat, 2 Aug 2025 13:35:07 -0400 Subject: [PATCH 11/18] apply my feedback --- crates/bevy_light/src/lib.rs | 6 +- crates/bevy_light/src/probe.rs | 58 +++++++------------ examples/2d/custom_gltf_vertex_attribute.rs | 3 +- examples/3d/irradiance_volumes.rs | 6 +- examples/3d/motion_blur.rs | 4 +- examples/3d/spherical_area_lights.rs | 3 +- examples/3d/spotlight.rs | 3 +- examples/3d/ssao.rs | 3 +- examples/animation/animated_mesh.rs | 3 +- examples/animation/animated_mesh_control.rs | 3 +- examples/animation/animated_mesh_events.rs | 3 +- examples/animation/animated_transform.rs | 3 +- examples/animation/animation_graph.rs | 3 +- examples/animation/animation_masks.rs | 3 +- examples/animation/custom_skinned_mesh.rs | 3 +- examples/animation/gltf_skinned_mesh.rs | 3 +- examples/animation/morph_targets.rs | 3 +- examples/asset/multi_asset_sync.rs | 3 +- examples/math/render_primitives.rs | 4 +- .../AmbientLight_deprecation.md | 2 +- 20 files changed, 48 insertions(+), 74 deletions(-) diff --git a/crates/bevy_light/src/lib.rs b/crates/bevy_light/src/lib.rs index 0cdf27e81e0ce..3c959538f39b2 100644 --- a/crates/bevy_light/src/lib.rs +++ b/crates/bevy_light/src/lib.rs @@ -227,7 +227,11 @@ impl Plugin for LightPlugin { app.world_mut().resource_mut::>().insert( &DEFAULT_ENVIRONMENT_MAP_TEXTURE_HANDLE, - EnvironmentMapLight::solid_color_image(Color::WHITE), + EnvironmentMapLight::hemispherical_gradient_cubemap( + Color::WHITE, + Color::WHITE, + Color::WHITE, + ), ); } } diff --git a/crates/bevy_light/src/probe.rs b/crates/bevy_light/src/probe.rs index d723401572a1b..1786c0f548a2c 100644 --- a/crates/bevy_light/src/probe.rs +++ b/crates/bevy_light/src/probe.rs @@ -101,35 +101,9 @@ pub struct EnvironmentMapLight { } impl EnvironmentMapLight { - pub(crate) fn solid_color_image(color: Color) -> Image { - let color: Srgba = color.into(); - Image { - texture_view_descriptor: Some(TextureViewDescriptor { - dimension: Some(TextureViewDimension::Cube), - ..Default::default() - }), - ..Image::new_fill( - Extent3d { - width: 1, - height: 1, - depth_or_array_layers: 6, - }, - TextureDimension::D2, - &color.to_u8_array(), - TextureFormat::Rgba8UnormSrgb, - RenderAssetUsages::RENDER_WORLD, - ) - } - } - /// An environment map with a uniform color, useful for uniform ambient lighting. pub fn solid_color(assets: &mut Assets, color: Color) -> Self { - let handle = assets.add(Self::solid_color_image(color)); - Self { - diffuse_map: handle.clone(), - specular_map: handle, - ..Default::default() - } + Self::hemispherical_gradient(assets, color, color, color) } /// An environment map with a hemispherical gradient, fading between the sky and ground colors @@ -137,12 +111,31 @@ impl EnvironmentMapLight { pub fn hemispherical_gradient( assets: &mut Assets, top_color: Color, + mid_color: Color, bottom_color: Color, ) -> Self { + let handle = assets.add(Self::hemispherical_gradient_cubemap( + top_color, + mid_color, + bottom_color, + )); + + Self { + diffuse_map: handle.clone(), + specular_map: handle, + ..Default::default() + } + } + + pub(crate) fn hemispherical_gradient_cubemap( + top_color: Color, + mid_color: Color, + bottom_color: Color, + ) -> Image { let top_color: Srgba = top_color.into(); + let mid_color: Srgba = mid_color.into(); let bottom_color: Srgba = bottom_color.into(); - let mid_color = (top_color + bottom_color) / 2.0; - let image = Image { + Image { texture_view_descriptor: Some(TextureViewDescriptor { dimension: Some(TextureViewDimension::Cube), ..Default::default() @@ -168,13 +161,6 @@ impl EnvironmentMapLight { TextureFormat::Rgba8UnormSrgb, RenderAssetUsages::RENDER_WORLD, ) - }; - let handle = assets.add(image); - - Self { - diffuse_map: handle.clone(), - specular_map: handle, - ..Default::default() } } } diff --git a/examples/2d/custom_gltf_vertex_attribute.rs b/examples/2d/custom_gltf_vertex_attribute.rs index 903898ce7f651..6e6d3baa66bfb 100644 --- a/examples/2d/custom_gltf_vertex_attribute.rs +++ b/examples/2d/custom_gltf_vertex_attribute.rs @@ -43,7 +43,6 @@ fn setup( mut commands: Commands, asset_server: Res, mut materials: ResMut>, - mut images: ResMut>, ) { // Add a mesh loaded from a glTF file. This mesh has data for `ATTRIBUTE_BARYCENTRIC`. let mesh = asset_server.load( @@ -63,7 +62,7 @@ fn setup( Camera2d, EnvironmentMapLight { intensity: 1.0 / 5.0, - ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + ..default() }, )); } diff --git a/examples/3d/irradiance_volumes.rs b/examples/3d/irradiance_volumes.rs index d69f3c0a107d8..343ae45c83ed7 100644 --- a/examples/3d/irradiance_volumes.rs +++ b/examples/3d/irradiance_volumes.rs @@ -213,12 +213,11 @@ fn main() { // Spawns all the scene objects. fn setup( mut commands: Commands, - images: ResMut>, assets: Res, app_status: Res, ) { spawn_main_scene(&mut commands, &assets); - spawn_camera(&mut commands, images, &assets); + spawn_camera(&mut commands, &assets); spawn_irradiance_volume(&mut commands, &assets); spawn_light(&mut commands); spawn_sphere(&mut commands, &assets); @@ -233,7 +232,6 @@ fn spawn_main_scene(commands: &mut Commands, assets: &ExampleAssets) { fn spawn_camera( commands: &mut Commands, - mut images: ResMut>, assets: &ExampleAssets, ) { commands.spawn(( @@ -246,7 +244,7 @@ fn spawn_camera( }, EnvironmentMapLight { intensity: 0.0, - ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + ..default() }, )); } diff --git a/examples/3d/motion_blur.rs b/examples/3d/motion_blur.rs index 8bdc98800d1b5..b85e22f596bc7 100644 --- a/examples/3d/motion_blur.rs +++ b/examples/3d/motion_blur.rs @@ -17,7 +17,7 @@ fn main() { .run(); } -fn setup_camera(mut commands: Commands, mut images: ResMut>) { +fn setup_camera(mut commands: Commands) { commands.spawn(( Camera3d::default(), // Add the `MotionBlur` component to a camera to enable motion blur. @@ -32,7 +32,7 @@ fn setup_camera(mut commands: Commands, mut images: ResMut>) { Msaa::Off, EnvironmentMapLight { intensity: 300.0, - ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + ..default() }, )); } diff --git a/examples/3d/spherical_area_lights.rs b/examples/3d/spherical_area_lights.rs index 9c7c1486e89e6..54caf3f4edda9 100644 --- a/examples/3d/spherical_area_lights.rs +++ b/examples/3d/spherical_area_lights.rs @@ -12,7 +12,6 @@ fn main() { fn setup( mut commands: Commands, mut meshes: ResMut>, - mut images: ResMut>, mut materials: ResMut>, ) { // camera @@ -21,7 +20,7 @@ fn setup( Transform::from_xyz(0.2, 1.5, 2.5).looking_at(Vec3::ZERO, Vec3::Y), EnvironmentMapLight { intensity: 60.0, - ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + ..default() }, )); diff --git a/examples/3d/spotlight.rs b/examples/3d/spotlight.rs index 61aa64e65e4db..6e655adfd391f 100644 --- a/examples/3d/spotlight.rs +++ b/examples/3d/spotlight.rs @@ -34,7 +34,6 @@ struct Movable; fn setup( mut commands: Commands, mut meshes: ResMut>, - mut images: ResMut>, mut materials: ResMut>, ) { // ground plane @@ -121,7 +120,7 @@ fn setup( Transform::from_xyz(-4.0, 5.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y), EnvironmentMapLight { intensity: 20.0, - ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + ..default() }, )); diff --git a/examples/3d/ssao.rs b/examples/3d/ssao.rs index 9726bf07a79c0..e70588dd7018e 100644 --- a/examples/3d/ssao.rs +++ b/examples/3d/ssao.rs @@ -20,7 +20,6 @@ fn main() { fn setup( mut commands: Commands, mut meshes: ResMut>, - mut images: ResMut>, mut materials: ResMut>, ) { commands.spawn(( @@ -32,7 +31,7 @@ fn setup( TemporalAntiAliasing::default(), EnvironmentMapLight { intensity: 1000.0, - ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + ..default() }, )); diff --git a/examples/animation/animated_mesh.rs b/examples/animation/animated_mesh.rs index 90ce4ba968b3e..a665771f1b10f 100644 --- a/examples/animation/animated_mesh.rs +++ b/examples/animation/animated_mesh.rs @@ -93,7 +93,6 @@ fn play_animation_when_ready( fn setup_camera_and_environment( mut commands: Commands, mut meshes: ResMut>, - mut images: ResMut>, mut materials: ResMut>, ) { // Camera @@ -102,7 +101,7 @@ fn setup_camera_and_environment( Transform::from_xyz(100.0, 100.0, 150.0).looking_at(Vec3::new(0.0, 20.0, 0.0), Vec3::Y), EnvironmentMapLight { intensity: 2000.0, - ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + ..default() }, )); diff --git a/examples/animation/animated_mesh_control.rs b/examples/animation/animated_mesh_control.rs index 0bf23a42c5446..ef7f586ed6350 100644 --- a/examples/animation/animated_mesh_control.rs +++ b/examples/animation/animated_mesh_control.rs @@ -25,7 +25,6 @@ fn setup( mut commands: Commands, asset_server: Res, mut meshes: ResMut>, - mut images: ResMut>, mut materials: ResMut>, mut graphs: ResMut>, ) { @@ -50,7 +49,7 @@ fn setup( Transform::from_xyz(100.0, 100.0, 150.0).looking_at(Vec3::new(0.0, 20.0, 0.0), Vec3::Y), EnvironmentMapLight { intensity: 2000.0, - ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + ..default() }, )); diff --git a/examples/animation/animated_mesh_events.rs b/examples/animation/animated_mesh_events.rs index da17a3da472d0..4000954cee45f 100644 --- a/examples/animation/animated_mesh_events.rs +++ b/examples/animation/animated_mesh_events.rs @@ -73,7 +73,6 @@ fn setup( mut commands: Commands, asset_server: Res, mut meshes: ResMut>, - mut images: ResMut>, mut materials: ResMut>, mut graphs: ResMut>, ) { @@ -96,7 +95,7 @@ fn setup( Transform::from_xyz(100.0, 100.0, 150.0).looking_at(Vec3::new(0.0, 20.0, 0.0), Vec3::Y), EnvironmentMapLight { intensity: 2000.0, - ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + ..default() }, )); diff --git a/examples/animation/animated_transform.rs b/examples/animation/animated_transform.rs index 08e7528797c77..cc44ef0d24f69 100644 --- a/examples/animation/animated_transform.rs +++ b/examples/animation/animated_transform.rs @@ -17,7 +17,6 @@ fn main() { fn setup( mut commands: Commands, mut meshes: ResMut>, - mut images: ResMut>, mut materials: ResMut>, mut animations: ResMut>, mut graphs: ResMut>, @@ -28,7 +27,7 @@ fn setup( Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), EnvironmentMapLight { intensity: 150.0, - ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + ..default() }, )); diff --git a/examples/animation/animation_graph.rs b/examples/animation/animation_graph.rs index 8e7154c9a09a7..8ab33b35c0b9b 100644 --- a/examples/animation/animation_graph.rs +++ b/examples/animation/animation_graph.rs @@ -217,7 +217,6 @@ fn setup_scene( mut commands: Commands, asset_server: Res, mut meshes: ResMut>, - mut images: ResMut>, mut materials: ResMut>, ) { commands.spawn(( @@ -225,7 +224,7 @@ fn setup_scene( Transform::from_xyz(-10.0, 5.0, 13.0).looking_at(Vec3::new(0., 1., 0.), Vec3::Y), EnvironmentMapLight { intensity: 100.0, - ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + ..default() }, )); diff --git a/examples/animation/animation_masks.rs b/examples/animation/animation_masks.rs index a47f2c110f3c3..ac0f9babfc976 100644 --- a/examples/animation/animation_masks.rs +++ b/examples/animation/animation_masks.rs @@ -115,7 +115,6 @@ fn setup_scene( mut commands: Commands, asset_server: Res, mut meshes: ResMut>, - mut images: ResMut>, mut materials: ResMut>, ) { // Spawn the camera. @@ -124,7 +123,7 @@ fn setup_scene( Transform::from_xyz(-15.0, 10.0, 20.0).looking_at(Vec3::new(0., 1., 0.), Vec3::Y), EnvironmentMapLight { intensity: 100.0, - ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + ..default() }, )); diff --git a/examples/animation/custom_skinned_mesh.rs b/examples/animation/custom_skinned_mesh.rs index d86e98295add8..abc8c356721de 100644 --- a/examples/animation/custom_skinned_mesh.rs +++ b/examples/animation/custom_skinned_mesh.rs @@ -36,7 +36,6 @@ fn setup( mut commands: Commands, asset_server: Res, mut meshes: ResMut>, - mut images: ResMut>, mut materials: ResMut>, mut skinned_mesh_inverse_bindposes_assets: ResMut>, ) { @@ -46,7 +45,7 @@ fn setup( Transform::from_xyz(2.5, 2.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y), EnvironmentMapLight { intensity: 3000.0, - ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + ..default() }, )); diff --git a/examples/animation/gltf_skinned_mesh.rs b/examples/animation/gltf_skinned_mesh.rs index 256e5ecdae074..395bb9f1f867a 100644 --- a/examples/animation/gltf_skinned_mesh.rs +++ b/examples/animation/gltf_skinned_mesh.rs @@ -16,7 +16,6 @@ fn main() { fn setup( mut commands: Commands, asset_server: Res, - mut images: ResMut>, ) { // Create a camera commands.spawn(( @@ -24,7 +23,7 @@ fn setup( Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::new(0.0, 1.0, 0.0), Vec3::Y), EnvironmentMapLight { intensity: 750.0, - ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + ..default() }, )); diff --git a/examples/animation/morph_targets.rs b/examples/animation/morph_targets.rs index 7c2c9a00ac6dd..116fd7ae9e6a5 100644 --- a/examples/animation/morph_targets.rs +++ b/examples/animation/morph_targets.rs @@ -33,7 +33,6 @@ struct MorphData { fn setup( asset_server: Res, mut commands: Commands, - mut images: ResMut>, ) { commands.insert_resource(MorphData { the_wave: asset_server @@ -58,7 +57,7 @@ fn setup( Transform::from_xyz(3.0, 2.1, 10.2).looking_at(Vec3::ZERO, Vec3::Y), EnvironmentMapLight { intensity: 150.0, - ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + ..default() }, )); } diff --git a/examples/asset/multi_asset_sync.rs b/examples/asset/multi_asset_sync.rs index 608c616d24408..7f4146eefb5ec 100644 --- a/examples/asset/multi_asset_sync.rs +++ b/examples/asset/multi_asset_sync.rs @@ -180,7 +180,6 @@ fn setup_ui(mut commands: Commands) { fn setup_scene( mut commands: Commands, mut meshes: ResMut>, - mut images: ResMut>, mut materials: ResMut>, ) { // Camera @@ -189,7 +188,7 @@ fn setup_scene( Transform::from_xyz(10.0, 10.0, 15.0).looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y), EnvironmentMapLight { intensity: 2000.0, - ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + ..default() }, )); diff --git a/examples/math/render_primitives.rs b/examples/math/render_primitives.rs index 28287b45fb426..a9c35f90c394c 100644 --- a/examples/math/render_primitives.rs +++ b/examples/math/render_primitives.rs @@ -292,7 +292,7 @@ const CIRCULAR_SEGMENT: CircularSegment = CircularSegment { }, }; -fn setup_cameras(mut commands: Commands, mut images: ResMut>) { +fn setup_cameras(mut commands: Commands) { let start_in_2d = true; let make_camera = |is_active| Camera { is_active, @@ -304,7 +304,7 @@ fn setup_cameras(mut commands: Commands, mut images: ResMut>) { make_camera(start_in_2d), EnvironmentMapLight { intensity: 50.0, - ..EnvironmentMapLight::solid_color(&mut images, Color::WHITE) + ..default() }, )); diff --git a/release-content/migration-guides/AmbientLight_deprecation.md b/release-content/migration-guides/AmbientLight_deprecation.md index 521f5e4137bd5..fafc9b7bfc0e7 100644 --- a/release-content/migration-guides/AmbientLight_deprecation.md +++ b/release-content/migration-guides/AmbientLight_deprecation.md @@ -5,5 +5,5 @@ pull_requests: [18207] `AmbientLight`s have been deprecated in favor of using `EnvironmentMapLight`s for the same purpose. All usages of an ambient light can be replaced by `EnvironmentMapLight::solid_color` added to the camera. -This will render slightly differently, as previously, `AmbientLight`s were (incorrectly) treated as diffuse-only light sources, +This will render slightly differently, as previously, `AmbientLight`s were (incorrectly) treated as diffuse-only light sources, while `EnvironmentMapLight`s have both a specular and diffuse component. From 435af5d7b859de8608ebb4848bbf28ff3a3c1c15 Mon Sep 17 00:00:00 2001 From: atlas dostal Date: Sat, 2 Aug 2025 14:00:11 -0400 Subject: [PATCH 12/18] fix --- crates/bevy_light/src/probe.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_light/src/probe.rs b/crates/bevy_light/src/probe.rs index 1786c0f548a2c..fb2b90f569d42 100644 --- a/crates/bevy_light/src/probe.rs +++ b/crates/bevy_light/src/probe.rs @@ -171,8 +171,8 @@ pub const DEFAULT_ENVIRONMENT_MAP_TEXTURE_HANDLE: Handle = impl Default for EnvironmentMapLight { fn default() -> Self { EnvironmentMapLight { - diffuse_map: Handle::default(), - specular_map: Handle::default(), + diffuse_map: DEFAULT_ENVIRONMENT_MAP_TEXTURE_HANDLE, + specular_map: DEFAULT_ENVIRONMENT_MAP_TEXTURE_HANDLE, intensity: 0.0, rotation: Quat::IDENTITY, affects_lightmapped_mesh_diffuse: true, From 7256c26837d9dff9fc819aadde042a21622fa607 Mon Sep 17 00:00:00 2001 From: atlas dostal Date: Sat, 2 Aug 2025 14:17:58 -0400 Subject: [PATCH 13/18] fix wgpu --- crates/bevy_light/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_light/Cargo.toml b/crates/bevy_light/Cargo.toml index 2f8951cc44132..760826c49adbb 100644 --- a/crates/bevy_light/Cargo.toml +++ b/crates/bevy_light/Cargo.toml @@ -27,7 +27,7 @@ bevy_color = { path = "../bevy_color", version = "0.17.0-dev", features = [ # other tracing = { version = "0.1", default-features = false } -wgpu-types = { version = "25", default-features = false } +wgpu-types = { version = "26", default-features = false } [features] default = [] From 4c7c2f0add3ff81421966c49f37dfddf72bb5717 Mon Sep 17 00:00:00 2001 From: atlas dostal Date: Sat, 2 Aug 2025 14:27:01 -0400 Subject: [PATCH 14/18] fmt --- examples/3d/irradiance_volumes.rs | 11 ++--------- examples/animation/gltf_skinned_mesh.rs | 5 +---- examples/animation/morph_targets.rs | 5 +---- 3 files changed, 4 insertions(+), 17 deletions(-) diff --git a/examples/3d/irradiance_volumes.rs b/examples/3d/irradiance_volumes.rs index 343ae45c83ed7..7b72a16695ea4 100644 --- a/examples/3d/irradiance_volumes.rs +++ b/examples/3d/irradiance_volumes.rs @@ -211,11 +211,7 @@ fn main() { } // Spawns all the scene objects. -fn setup( - mut commands: Commands, - assets: Res, - app_status: Res, -) { +fn setup(mut commands: Commands, assets: Res, app_status: Res) { spawn_main_scene(&mut commands, &assets); spawn_camera(&mut commands, &assets); spawn_irradiance_volume(&mut commands, &assets); @@ -230,10 +226,7 @@ fn spawn_main_scene(commands: &mut Commands, assets: &ExampleAssets) { commands.spawn(SceneRoot(assets.main_scene.clone())); } -fn spawn_camera( - commands: &mut Commands, - assets: &ExampleAssets, -) { +fn spawn_camera(commands: &mut Commands, assets: &ExampleAssets) { commands.spawn(( Camera3d::default(), Transform::from_xyz(-10.012, 4.8605, 13.281).looking_at(Vec3::ZERO, Vec3::Y), diff --git a/examples/animation/gltf_skinned_mesh.rs b/examples/animation/gltf_skinned_mesh.rs index 395bb9f1f867a..27a7683892fd3 100644 --- a/examples/animation/gltf_skinned_mesh.rs +++ b/examples/animation/gltf_skinned_mesh.rs @@ -13,10 +13,7 @@ fn main() { .run(); } -fn setup( - mut commands: Commands, - asset_server: Res, -) { +fn setup(mut commands: Commands, asset_server: Res) { // Create a camera commands.spawn(( Camera3d::default(), diff --git a/examples/animation/morph_targets.rs b/examples/animation/morph_targets.rs index 116fd7ae9e6a5..3233035ffbca0 100644 --- a/examples/animation/morph_targets.rs +++ b/examples/animation/morph_targets.rs @@ -30,10 +30,7 @@ struct MorphData { mesh: Handle, } -fn setup( - asset_server: Res, - mut commands: Commands, -) { +fn setup(asset_server: Res, mut commands: Commands) { commands.insert_resource(MorphData { the_wave: asset_server .load(GltfAssetLabel::Animation(2).from_asset("models/animated/MorphStressTest.gltf")), From e58a1b7b3b6a282461650cbc131197e37c7a887f Mon Sep 17 00:00:00 2001 From: Shaye Garg <64652557+SparkyPotato@users.noreply.github.com> Date: Tue, 5 Aug 2025 17:45:52 +0100 Subject: [PATCH 15/18] update default environment light Co-authored-by: atlv --- crates/bevy_light/src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/bevy_light/src/lib.rs b/crates/bevy_light/src/lib.rs index 3c959538f39b2..648ac66d27103 100644 --- a/crates/bevy_light/src/lib.rs +++ b/crates/bevy_light/src/lib.rs @@ -222,7 +222,12 @@ impl Plugin for LightPlugin { if self.default_environment_map_light { app.world_mut() - .register_required_components::(); + .register_required_components_with::(|| { + EnvironmentMapLight { + intensity: 50.0, + ..Default::default() + } + }); } app.world_mut().resource_mut::>().insert( From d3fb19b5b42378b5897c243d01dbaa60618656c7 Mon Sep 17 00:00:00 2001 From: SparkyPotato Date: Tue, 5 Aug 2025 19:52:27 +0100 Subject: [PATCH 16/18] fix lighting example --- examples/3d/lighting.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/3d/lighting.rs b/examples/3d/lighting.rs index 3a1eea0a4cdd1..8eb14311d6579 100644 --- a/examples/3d/lighting.rs +++ b/examples/3d/lighting.rs @@ -242,7 +242,7 @@ fn setup( Exposure::from_physical_camera(**parameters), // environment lights' brightnesses are measured in candela per meter square, calculable as (color * intensity) EnvironmentMapLight { - intensity: 0.02, + intensity: 80.0, ..EnvironmentMapLight::solid_color(&mut images, ORANGE_RED.into()) }, )); @@ -299,7 +299,7 @@ fn toggle_ambient_light( if light.intensity > 1. { light.intensity = 0.; } else { - light.intensity = 200.; + light.intensity = 80.; } let entity = *text; From 83fe161e124a2b8120e0c2ca8c0c512d884ec9d0 Mon Sep 17 00:00:00 2001 From: atlas Date: Tue, 5 Aug 2025 14:52:30 -0400 Subject: [PATCH 17/18] fix examples --- crates/bevy_light/src/probe.rs | 2 +- examples/3d/auto_exposure.rs | 10 +++------- examples/3d/fog.rs | 9 +++------ examples/3d/fog_volumes.rs | 25 +++++++++++++------------ examples/3d/lightmaps.rs | 7 +------ examples/3d/specular_tint.rs | 25 +++++++++++++------------ examples/3d/transmission.rs | 9 +++------ examples/3d/volumetric_fog.rs | 9 +++------ 8 files changed, 40 insertions(+), 56 deletions(-) diff --git a/crates/bevy_light/src/probe.rs b/crates/bevy_light/src/probe.rs index fb2b90f569d42..e1c3cfbc560c5 100644 --- a/crates/bevy_light/src/probe.rs +++ b/crates/bevy_light/src/probe.rs @@ -175,7 +175,7 @@ impl Default for EnvironmentMapLight { specular_map: DEFAULT_ENVIRONMENT_MAP_TEXTURE_HANDLE, intensity: 0.0, rotation: Quat::IDENTITY, - affects_lightmapped_mesh_diffuse: true, + affects_lightmapped_mesh_diffuse: false, } } } diff --git a/examples/3d/auto_exposure.rs b/examples/3d/auto_exposure.rs index a06425d75ce34..e418c413a177f 100644 --- a/examples/3d/auto_exposure.rs +++ b/examples/3d/auto_exposure.rs @@ -22,7 +22,9 @@ use bevy::{ fn main() { App::new() - .add_plugins(DefaultPlugins) + .add_plugins(DefaultPlugins.set(bevy::light::LightPlugin { + default_environment_map_light: false, + })) .add_plugins(AutoExposurePlugin) .add_systems(Startup, setup) .add_systems(Update, example_control_system) @@ -97,12 +99,6 @@ fn setup( } } - #[expect( - deprecated, - reason = "Once AmbientLight is removed, the resource can be removed" - )] - commands.insert_resource(AmbientLight::NONE); - commands.spawn(( PointLight { intensity: 2000.0, diff --git a/examples/3d/fog.rs b/examples/3d/fog.rs index 23369a4ff16e0..a96068f013239 100644 --- a/examples/3d/fog.rs +++ b/examples/3d/fog.rs @@ -28,13 +28,10 @@ use bevy::{ }; fn main() { - #[expect( - deprecated, - reason = "Once AmbientLight is removed, the resource can be removed" - )] App::new() - .insert_resource(AmbientLight::NONE) - .add_plugins(DefaultPlugins) + .add_plugins(DefaultPlugins.set(bevy::light::LightPlugin { + default_environment_map_light: false, + })) .add_systems( Startup, (setup_camera_fog, setup_pyramid_scene, setup_instructions), diff --git a/examples/3d/fog_volumes.rs b/examples/3d/fog_volumes.rs index 051a173d3f1d8..6422f786d5f3d 100644 --- a/examples/3d/fog_volumes.rs +++ b/examples/3d/fog_volumes.rs @@ -14,19 +14,20 @@ use bevy::{ /// Entry point. fn main() { - #[expect( - deprecated, - reason = "Once AmbientLight is removed, the resource can be removed" - )] App::new() - .add_plugins(DefaultPlugins.set(WindowPlugin { - primary_window: Some(Window { - title: "Bevy Fog Volumes Example".into(), - ..default() - }), - ..default() - })) - .insert_resource(AmbientLight::NONE) + .add_plugins( + DefaultPlugins + .set(WindowPlugin { + primary_window: Some(Window { + title: "Bevy Fog Volumes Example".into(), + ..default() + }), + ..default() + }) + .set(bevy::light::LightPlugin { + default_environment_map_light: false, + }), + ) .add_systems(Startup, setup) .add_systems(Update, rotate_camera) .run(); diff --git a/examples/3d/lightmaps.rs b/examples/3d/lightmaps.rs index e02872d96079f..2bb9d5d2a5b1d 100644 --- a/examples/3d/lightmaps.rs +++ b/examples/3d/lightmaps.rs @@ -26,12 +26,7 @@ fn main() { let args: Args = Args::from_args(&[], &[]).unwrap(); let mut app = App::new(); - #[expect( - deprecated, - reason = "Once AmbientLight is removed, the resource can be removed" - )] - app.add_plugins(DefaultPlugins) - .insert_resource(AmbientLight::NONE); + app.add_plugins(DefaultPlugins); if args.deferred { app.insert_resource(DefaultOpaqueRendererMethod::deferred()); diff --git a/examples/3d/specular_tint.rs b/examples/3d/specular_tint.rs index 987a74c524b63..a1bded8a2b354 100644 --- a/examples/3d/specular_tint.rs +++ b/examples/3d/specular_tint.rs @@ -49,21 +49,22 @@ enum TintType { /// The entry point. fn main() { - #[expect( - deprecated, - reason = "Once AmbientLight is removed, the resource can be removed" - )] App::new() - .add_plugins(DefaultPlugins.set(WindowPlugin { - primary_window: Some(Window { - title: "Bevy Specular Tint Example".into(), - ..default() - }), - ..default() - })) + .add_plugins( + DefaultPlugins + .set(WindowPlugin { + primary_window: Some(Window { + title: "Bevy Specular Tint Example".into(), + ..default() + }), + ..default() + }) + .set(bevy::light::LightPlugin { + default_environment_map_light: false, + }), + ) .init_resource::() .init_resource::() - .insert_resource(AmbientLight::NONE) .add_systems(Startup, setup) .add_systems(Update, rotate_camera) .add_systems(Update, (toggle_specular_map, update_text).chain()) diff --git a/examples/3d/transmission.rs b/examples/3d/transmission.rs index 60b9b94a75f6b..2279118cabcdb 100644 --- a/examples/3d/transmission.rs +++ b/examples/3d/transmission.rs @@ -44,15 +44,12 @@ use bevy::anti_aliasing::taa::TemporalAntiAliasing; use rand::random; fn main() { - #[expect( - deprecated, - reason = "Once AmbientLight is removed, the resource can be removed" - )] App::new() - .add_plugins(DefaultPlugins) + .add_plugins(DefaultPlugins.set(bevy::light::LightPlugin { + default_environment_map_light: false, + })) .insert_resource(ClearColor(Color::BLACK)) .insert_resource(PointLightShadowMap { size: 2048 }) - .insert_resource(AmbientLight::NONE) .add_systems(Startup, setup) .add_systems(Update, (example_control_system, flicker_system)) .run(); diff --git a/examples/3d/volumetric_fog.rs b/examples/3d/volumetric_fog.rs index e64ea432c249a..8509b09534c60 100644 --- a/examples/3d/volumetric_fog.rs +++ b/examples/3d/volumetric_fog.rs @@ -37,19 +37,16 @@ struct MoveBackAndForthHorizontally { } fn main() { - #[expect( - deprecated, - reason = "Once AmbientLight is removed, the resource can be removed" - )] App::new() - .add_plugins(DefaultPlugins) + .add_plugins(DefaultPlugins.set(bevy::light::LightPlugin { + default_environment_map_light: false, + })) .insert_resource(ClearColor(Color::Srgba(Srgba { red: 0.02, green: 0.02, blue: 0.02, alpha: 1.0, }))) - .insert_resource(AmbientLight::NONE) .init_resource::() .add_systems(Startup, setup) .add_systems(Update, tweak_scene) From e4798f30f8f4b0658766fbba34f589ea6cb06ac8 Mon Sep 17 00:00:00 2001 From: atlas Date: Tue, 5 Aug 2025 17:20:40 -0400 Subject: [PATCH 18/18] fix again :( --- examples/3d/auto_exposure.rs | 3 ++- examples/3d/fog.rs | 3 ++- examples/3d/fog_volumes.rs | 3 ++- examples/3d/specular_tint.rs | 3 ++- examples/3d/transmission.rs | 3 ++- examples/3d/volumetric_fog.rs | 3 ++- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/examples/3d/auto_exposure.rs b/examples/3d/auto_exposure.rs index e418c413a177f..acc075ac7a49e 100644 --- a/examples/3d/auto_exposure.rs +++ b/examples/3d/auto_exposure.rs @@ -22,8 +22,9 @@ use bevy::{ fn main() { App::new() - .add_plugins(DefaultPlugins.set(bevy::light::LightPlugin { + .add_plugins(DefaultPlugins.set(bevy::pbr::PbrPlugin { default_environment_map_light: false, + ..default() })) .add_plugins(AutoExposurePlugin) .add_systems(Startup, setup) diff --git a/examples/3d/fog.rs b/examples/3d/fog.rs index a96068f013239..0251d2bcf496a 100644 --- a/examples/3d/fog.rs +++ b/examples/3d/fog.rs @@ -29,8 +29,9 @@ use bevy::{ fn main() { App::new() - .add_plugins(DefaultPlugins.set(bevy::light::LightPlugin { + .add_plugins(DefaultPlugins.set(bevy::pbr::PbrPlugin { default_environment_map_light: false, + ..default() })) .add_systems( Startup, diff --git a/examples/3d/fog_volumes.rs b/examples/3d/fog_volumes.rs index 6422f786d5f3d..0ec3cbc4b8a1f 100644 --- a/examples/3d/fog_volumes.rs +++ b/examples/3d/fog_volumes.rs @@ -24,8 +24,9 @@ fn main() { }), ..default() }) - .set(bevy::light::LightPlugin { + .set(bevy::pbr::PbrPlugin { default_environment_map_light: false, + ..default() }), ) .add_systems(Startup, setup) diff --git a/examples/3d/specular_tint.rs b/examples/3d/specular_tint.rs index a1bded8a2b354..d5aab4f82228c 100644 --- a/examples/3d/specular_tint.rs +++ b/examples/3d/specular_tint.rs @@ -59,8 +59,9 @@ fn main() { }), ..default() }) - .set(bevy::light::LightPlugin { + .set(bevy::pbr::PbrPlugin { default_environment_map_light: false, + ..default() }), ) .init_resource::() diff --git a/examples/3d/transmission.rs b/examples/3d/transmission.rs index 2279118cabcdb..05d461eb27938 100644 --- a/examples/3d/transmission.rs +++ b/examples/3d/transmission.rs @@ -45,8 +45,9 @@ use rand::random; fn main() { App::new() - .add_plugins(DefaultPlugins.set(bevy::light::LightPlugin { + .add_plugins(DefaultPlugins.set(bevy::pbr::PbrPlugin { default_environment_map_light: false, + ..default() })) .insert_resource(ClearColor(Color::BLACK)) .insert_resource(PointLightShadowMap { size: 2048 }) diff --git a/examples/3d/volumetric_fog.rs b/examples/3d/volumetric_fog.rs index 8509b09534c60..0378374c82876 100644 --- a/examples/3d/volumetric_fog.rs +++ b/examples/3d/volumetric_fog.rs @@ -38,8 +38,9 @@ struct MoveBackAndForthHorizontally { fn main() { App::new() - .add_plugins(DefaultPlugins.set(bevy::light::LightPlugin { + .add_plugins(DefaultPlugins.set(bevy::pbr::PbrPlugin { default_environment_map_light: false, + ..default() })) .insert_resource(ClearColor(Color::Srgba(Srgba { red: 0.02,