From dc9b4866500a942a15379af59326742fd728d00c Mon Sep 17 00:00:00 2001 From: Doonv <58695417+doonv@users.noreply.github.com> Date: Wed, 14 Feb 2024 22:43:10 +0200 Subject: [PATCH] Change light defaults & fix light examples (#11581) # Objective Fix https://github.com/bevyengine/bevy/issues/11577. ## Solution Fix the examples, add a few constants to make setting light values easier, and change the default lighting settings to be more realistic. (Now designed for an overcast day instead of an indoor environment) --- I did not include any example-related changes in here. ## Changelogs (not including breaking changes) ### bevy_pbr - Added `light_consts` module (included in prelude), which contains common lux and lumen values for lights. - Added `AmbientLight::NONE` constant, which is an ambient light with a brightness of 0. - Added non-EV100 variants for `ExposureSettings`'s EV100 constants, which allow easier construction of an `ExposureSettings` from a EV100 constant. ## Breaking changes ### bevy_pbr The several default lighting values were changed: - `PointLight`'s default `intensity` is now `2000.0` - `SpotLight`'s default `intensity` is now `2000.0` - `DirectionalLight`'s default `illuminance` is now `light_consts::lux::OVERCAST_DAY` (`1000.`) - `AmbientLight`'s default `brightness` is now `20.0` --- crates/bevy_pbr/src/lib.rs | 2 +- crates/bevy_pbr/src/light.rs | 73 +++++++++++++++++-- crates/bevy_render/src/camera/camera.rs | 14 +++- examples/3d/3d_gizmos.rs | 8 +- examples/3d/3d_scene.rs | 8 +- examples/3d/3d_shapes.rs | 9 +-- examples/3d/3d_viewport_to_world.rs | 5 +- examples/3d/animated_material.rs | 2 +- examples/3d/anti_aliasing.rs | 2 +- examples/3d/atmospheric_fog.rs | 2 +- examples/3d/blend_modes.rs | 8 +- examples/3d/deferred_rendering.rs | 8 +- examples/3d/fog.rs | 8 +- examples/3d/generate_custom_mesh.rs | 7 +- examples/3d/lighting.rs | 8 +- examples/3d/lightmaps.rs | 4 +- examples/3d/load_gltf.rs | 4 +- examples/3d/orthographic.rs | 8 +- examples/3d/parallax_mapping.rs | 2 +- examples/3d/parenting.rs | 8 +- examples/3d/pbr.rs | 16 +--- examples/3d/reflection_probes.rs | 22 +++--- examples/3d/render_to_texture.rs | 12 +-- examples/3d/shadow_biases.rs | 7 +- examples/3d/shadow_caster_receiver.rs | 8 +- examples/3d/spherical_area_lights.rs | 7 +- examples/3d/split_screen.rs | 1 - examples/3d/spotlight.rs | 18 ++--- examples/3d/ssao.rs | 6 +- examples/3d/tonemapping.rs | 6 +- examples/3d/transmission.rs | 8 +- examples/3d/transparency_3d.rs | 28 ++++--- examples/3d/two_passes.rs | 21 +++--- examples/3d/update_gltf_scene.rs | 2 +- examples/3d/vertex_colors.rs | 14 ++-- examples/3d/wireframe.rs | 4 +- examples/animation/animated_fox.rs | 5 -- examples/animation/cubic_curve.rs | 8 +- examples/animation/morph_targets.rs | 6 +- examples/asset/asset_loading.rs | 9 +-- examples/asset/hot_asset_reloading.rs | 9 +-- examples/audio/spatial_audio_3d.rs | 7 +- examples/ecs/iter_combinations.rs | 4 +- examples/shader/array_texture.rs | 17 +---- examples/shader/extended_material.rs | 15 +--- examples/shader/post_processing.rs | 9 +-- .../shader_material_screenspace_texture.rs | 9 +-- examples/shader/shader_prepass.rs | 7 +- examples/stress_tests/many_cubes.rs | 2 +- examples/stress_tests/many_foxes.rs | 5 -- examples/stress_tests/many_lights.rs | 2 +- examples/tools/scene_viewer/main.rs | 6 +- examples/transforms/3d_rotation.rs | 8 +- examples/transforms/scale.rs | 8 +- examples/transforms/transform.rs | 8 +- examples/transforms/translation.rs | 8 +- examples/ui/render_ui_to_texture.rs | 9 +-- examples/window/low_power.rs | 10 +-- examples/window/multiple_windows.rs | 8 +- examples/window/screenshot.rs | 7 +- 60 files changed, 261 insertions(+), 295 deletions(-) diff --git a/crates/bevy_pbr/src/lib.rs b/crates/bevy_pbr/src/lib.rs index 6d5fc10873178..5da0deaea3b0f 100644 --- a/crates/bevy_pbr/src/lib.rs +++ b/crates/bevy_pbr/src/lib.rs @@ -42,7 +42,7 @@ pub mod prelude { SpotLightBundle, }, fog::{FogFalloff, FogSettings}, - light::{AmbientLight, DirectionalLight, PointLight, SpotLight}, + light::{light_consts, AmbientLight, DirectionalLight, PointLight, SpotLight}, light_probe::{ environment_map::{EnvironmentMapLight, ReflectionProbeBundle}, LightProbe, diff --git a/crates/bevy_pbr/src/light.rs b/crates/bevy_pbr/src/light.rs index ffc1e67d0502c..376981e833cf0 100644 --- a/crates/bevy_pbr/src/light.rs +++ b/crates/bevy_pbr/src/light.rs @@ -21,6 +21,61 @@ use bevy_utils::tracing::warn; use crate::*; +/// Constants for operating with the light units: lumens, and lux. +pub mod light_consts { + /// Approximations for converting the wattage of lamps to lumens. + /// + /// The **lumen** (symbol: **lm**) is the unit of [luminous flux], a measure + /// of the total quantity of [visible light] emitted by a source per unit of + /// time, in the [International System of Units] (SI). + /// + /// For more information, see [wikipedia](https://en.wikipedia.org/wiki/Lumen_(unit)) + /// + /// [luminous flux]: https://en.wikipedia.org/wiki/Luminous_flux + /// [visible light]: https://en.wikipedia.org/wiki/Visible_light + /// [International System of Units]: https://en.wikipedia.org/wiki/International_System_of_Units + pub mod lumens { + pub const LUMENS_PER_LED_WATTS: f32 = 90.0; + pub const LUMENS_PER_INCANDESCENT_WATTS: f32 = 13.8; + pub const LUMENS_PER_HALOGEN_WATTS: f32 = 19.8; + } + + /// Predefined for lux values in several locations. + /// + /// The **lux** (symbol: **lx**) is the unit of [illuminance], or [luminous flux] per unit area, + /// in the [International System of Units] (SI). It is equal to one lumen per square metre. + /// + /// For more information, see [wikipedia](https://en.wikipedia.org/wiki/Lux) + /// + /// [illuminance]: https://en.wikipedia.org/wiki/Illuminance + /// [luminous flux]: https://en.wikipedia.org/wiki/Luminous_flux + /// [International System of Units]: https://en.wikipedia.org/wiki/International_System_of_Units + pub mod lux { + /// The amount of light (lux) in a moonless, overcast night sky. (starlight) + pub const MOONLESS_NIGHT: f32 = 0.0001; + /// The amount of light (lux) during a full moon on a clear night. + pub const FULL_MOON_NIGHT: f32 = 0.05; + /// The amount of light (lux) during the dark limit of civil twilight under a clear sky. + pub const CIVIL_TWILIGHT: f32 = 3.4; + /// The amount of light (lux) in family living room lights. + pub const LIVING_ROOM: f32 = 50.; + /// The amount of light (lux) in an office building's hallway/toilet lighting. + pub const HALLWAY: f32 = 80.; + /// The amount of light (lux) in very dark overcast day + pub const DARK_OVERCAST_DAY: f32 = 100.; + /// The amount of light (lux) in an office. + pub const OFFICE: f32 = 320.; + /// The amount of light (lux) during sunrise or sunset on a clear day. + pub const CLEAR_SUNRISE: f32 = 400.; + /// The amount of light (lux) on a overcast day; typical TV studio lighting + pub const OVERCAST_DAY: f32 = 1000.; + /// The amount of light (lux) in full daylight (not direct sun). + pub const FULL_DAYLIGHT: f32 = 10_000.; + /// The amount of light (lux) in direct sunlight. + pub const DIRECT_SUNLIGHT: f32 = 50_000.; + } +} + /// A light that emits light in all directions from a central point. /// /// Real-world values for `intensity` (luminous power in lumens) based on the electrical power @@ -58,7 +113,7 @@ impl Default for PointLight { fn default() -> Self { PointLight { color: Color::rgb(1.0, 1.0, 1.0), - intensity: 800.0, // Roughly a 60W non-halogen incandescent bulb + intensity: 2000.0, // Roughly a 20-watt LED bulb range: 20.0, radius: 0.0, shadows_enabled: false, @@ -126,7 +181,7 @@ impl Default for SpotLight { // a quarter arc attenuating from the center Self { color: Color::rgb(1.0, 1.0, 1.0), - intensity: 800.0, // Roughly a 60W non-halogen incandescent bulb + intensity: 2000.0, // Roughly a 20-watt LED bulb range: 20.0, radius: 0.0, shadows_enabled: false, @@ -207,7 +262,7 @@ impl Default for DirectionalLight { fn default() -> Self { DirectionalLight { color: Color::rgb(1.0, 1.0, 1.0), - illuminance: 100000.0, + illuminance: light_consts::lux::OVERCAST_DAY, shadows_enabled: false, shadow_depth_bias: Self::DEFAULT_SHADOW_DEPTH_BIAS, shadow_normal_bias: Self::DEFAULT_SHADOW_NORMAL_BIAS, @@ -567,7 +622,7 @@ fn calculate_cascade( /// # use bevy_ecs::system::ResMut; /// # use bevy_pbr::AmbientLight; /// fn setup_ambient_light(mut ambient_light: ResMut) { -/// ambient_light.brightness = 20.0; +/// ambient_light.brightness = 100.0; /// } /// ``` #[derive(Resource, Clone, Debug, ExtractResource, Reflect)] @@ -581,11 +636,17 @@ pub struct AmbientLight { impl Default for AmbientLight { fn default() -> Self { Self { - color: Color::rgb(1.0, 1.0, 1.0), - brightness: 8.0, + color: Color::WHITE, + brightness: 20.0, } } } +impl AmbientLight { + pub const NONE: AmbientLight = AmbientLight { + color: Color::WHITE, + brightness: 0.0, + }; +} /// Add this component to make a [`Mesh`](bevy_render::mesh::Mesh) not cast shadows. #[derive(Component, Reflect, Default)] diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index a2fff3edf0468..61d897f12980d 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -96,6 +96,16 @@ pub struct ExposureSettings { } impl ExposureSettings { + pub const SUNLIGHT: Self = Self { + ev100: Self::EV100_SUNLIGHT, + }; + pub const OVERCAST: Self = Self { + ev100: Self::EV100_OVERCAST, + }; + pub const INDOOR: Self = Self { + ev100: Self::EV100_INDOOR, + }; + pub const EV100_SUNLIGHT: f32 = 15.0; pub const EV100_OVERCAST: f32 = 12.0; pub const EV100_INDOOR: f32 = 7.0; @@ -116,9 +126,7 @@ impl ExposureSettings { impl Default for ExposureSettings { fn default() -> Self { - Self { - ev100: Self::EV100_INDOOR, - } + Self::INDOOR } } diff --git a/examples/3d/3d_gizmos.rs b/examples/3d/3d_gizmos.rs index c5d81f7a0ed61..5e2e5185b02a5 100644 --- a/examples/3d/3d_gizmos.rs +++ b/examples/3d/3d_gizmos.rs @@ -41,13 +41,13 @@ fn setup( ..default() }); // light - commands.spawn(PointLightBundle { - point_light: PointLight { - intensity: 250000.0, + commands.spawn(DirectionalLightBundle { + directional_light: DirectionalLight { + illuminance: light_consts::lux::OVERCAST_DAY, shadows_enabled: true, ..default() }, - transform: Transform::from_xyz(4.0, 8.0, 4.0), + transform: Transform::from_xyz(4.0, 8.0, 4.0).looking_at(Vec3::ZERO, Vec3::Y), ..default() }); diff --git a/examples/3d/3d_scene.rs b/examples/3d/3d_scene.rs index 54c129d077c12..2766ac0639126 100644 --- a/examples/3d/3d_scene.rs +++ b/examples/3d/3d_scene.rs @@ -30,13 +30,13 @@ fn setup( ..default() }); // light - commands.spawn(PointLightBundle { - point_light: PointLight { - intensity: 250_000.0, + commands.spawn(DirectionalLightBundle { + directional_light: DirectionalLight { + illuminance: light_consts::lux::OVERCAST_DAY, shadows_enabled: true, ..default() }, - transform: Transform::from_xyz(4.0, 8.0, 4.0), + transform: Transform::from_xyz(4.0, 8.0, 4.0).looking_at(Vec3::ZERO, Vec3::Y), ..default() }); // camera diff --git a/examples/3d/3d_shapes.rs b/examples/3d/3d_shapes.rs index fe6135cca62aa..a510ffa7f1a0d 100644 --- a/examples/3d/3d_shapes.rs +++ b/examples/3d/3d_shapes.rs @@ -64,14 +64,13 @@ fn setup( )); } - commands.spawn(PointLightBundle { - point_light: PointLight { - intensity: 1500000.0, - range: 100., + commands.spawn(DirectionalLightBundle { + directional_light: DirectionalLight { + illuminance: light_consts::lux::OVERCAST_DAY, shadows_enabled: true, ..default() }, - transform: Transform::from_xyz(8.0, 16.0, 8.0), + transform: Transform::from_xyz(8.0, 16.0, 8.0).looking_at(Vec3::ZERO, Vec3::Y), ..default() }); diff --git a/examples/3d/3d_viewport_to_world.rs b/examples/3d/3d_viewport_to_world.rs index 6ca166297f3b7..be06156f475bd 100644 --- a/examples/3d/3d_viewport_to_world.rs +++ b/examples/3d/3d_viewport_to_world.rs @@ -66,10 +66,7 @@ fn setup( // light commands.spawn(DirectionalLightBundle { transform: Transform::from_translation(Vec3::ONE).looking_at(Vec3::ZERO, Vec3::Y), - directional_light: DirectionalLight { - illuminance: 2000.0, - ..default() - }, + directional_light: DirectionalLight::default(), ..default() }); diff --git a/examples/3d/animated_material.rs b/examples/3d/animated_material.rs index 2d1c3ff1adbd1..7f7e8f47aca05 100644 --- a/examples/3d/animated_material.rs +++ b/examples/3d/animated_material.rs @@ -25,7 +25,7 @@ fn setup( EnvironmentMapLight { diffuse_map: asset_server.load("environment_maps/pisa_diffuse_rgb9e5_zstd.ktx2"), specular_map: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"), - intensity: 1500.0, + intensity: 1_000.0, }, )); diff --git a/examples/3d/anti_aliasing.rs b/examples/3d/anti_aliasing.rs index 2ef37854d809b..d841f9ae5a66c 100644 --- a/examples/3d/anti_aliasing.rs +++ b/examples/3d/anti_aliasing.rs @@ -289,7 +289,7 @@ fn setup( // Light commands.spawn(DirectionalLightBundle { directional_light: DirectionalLight { - illuminance: 3000.0, + illuminance: light_consts::lux::OVERCAST_DAY, shadows_enabled: true, ..default() }, diff --git a/examples/3d/atmospheric_fog.rs b/examples/3d/atmospheric_fog.rs index 5d742cf39fb5f..c14b0582427e2 100644 --- a/examples/3d/atmospheric_fog.rs +++ b/examples/3d/atmospheric_fog.rs @@ -61,7 +61,7 @@ fn setup_terrain_scene( commands.spawn(DirectionalLightBundle { directional_light: DirectionalLight { color: Color::rgb(0.98, 0.95, 0.82), - illuminance: 3000.0, + illuminance: light_consts::lux::OVERCAST_DAY, shadows_enabled: true, ..default() }, diff --git a/examples/3d/blend_modes.rs b/examples/3d/blend_modes.rs index 0d1431b296877..1f24f957787a9 100644 --- a/examples/3d/blend_modes.rs +++ b/examples/3d/blend_modes.rs @@ -167,12 +167,12 @@ fn setup( } // Light - commands.spawn(PointLightBundle { - point_light: PointLight { - intensity: 150_000.0, + commands.spawn(DirectionalLightBundle { + directional_light: DirectionalLight { + illuminance: light_consts::lux::OVERCAST_DAY, ..default() }, - transform: Transform::from_xyz(4.0, 8.0, 4.0), + transform: Transform::from_xyz(4.0, 8.0, 4.0).looking_at(Vec3::ZERO, Vec3::Y), ..default() }); diff --git a/examples/3d/deferred_rendering.rs b/examples/3d/deferred_rendering.rs index d499ce7f3cff0..0ff57d94e4d12 100644 --- a/examples/3d/deferred_rendering.rs +++ b/examples/3d/deferred_rendering.rs @@ -18,10 +18,6 @@ fn main() { App::new() .insert_resource(Msaa::Off) .insert_resource(DefaultOpaqueRendererMethod::deferred()) - .insert_resource(AmbientLight { - color: Color::WHITE, - brightness: 1.0 / 5.0f32, - }) .insert_resource(DirectionalLightShadowMap { size: 4096 }) .add_plugins(DefaultPlugins) .insert_resource(Normal(None)) @@ -62,7 +58,7 @@ fn setup( EnvironmentMapLight { diffuse_map: asset_server.load("environment_maps/pisa_diffuse_rgb9e5_zstd.ktx2"), specular_map: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"), - intensity: 150.0, + intensity: 250.0, }, DepthPrepass, MotionVectorPrepass, @@ -72,7 +68,7 @@ fn setup( commands.spawn(DirectionalLightBundle { directional_light: DirectionalLight { - illuminance: 4000.0, + illuminance: light_consts::lux::OVERCAST_DAY, shadows_enabled: true, ..default() }, diff --git a/examples/3d/fog.rs b/examples/3d/fog.rs index d3b0599f0b01c..5e221b5c00ef4 100644 --- a/examples/3d/fog.rs +++ b/examples/3d/fog.rs @@ -17,10 +17,12 @@ use bevy::{ pbr::{NotShadowCaster, NotShadowReceiver}, prelude::*, + render::camera::ExposureSettings, }; fn main() { App::new() + .insert_resource(AmbientLight::NONE) .add_plugins(DefaultPlugins) .add_systems( Startup, @@ -41,6 +43,9 @@ fn setup_camera_fog(mut commands: Commands) { }, ..default() }, + // This is a dark scene, + // increasing the exposure makes it easier to see + ExposureSettings { ev100: 4.0 }, )); } @@ -114,8 +119,7 @@ fn setup_pyramid_scene( commands.spawn(PointLightBundle { transform: Transform::from_xyz(0.0, 1.0, 0.0), point_light: PointLight { - intensity: 300_000., - range: 100., + intensity: 4_000., shadows_enabled: true, ..default() }, diff --git a/examples/3d/generate_custom_mesh.rs b/examples/3d/generate_custom_mesh.rs index 428ce8cd1d2b0..4086c2d8c522a 100644 --- a/examples/3d/generate_custom_mesh.rs +++ b/examples/3d/generate_custom_mesh.rs @@ -57,10 +57,9 @@ fn setup( }); // Light up the scene. - commands.spawn(PointLightBundle { - point_light: PointLight { - intensity: 100_000.0, - range: 100.0, + commands.spawn(DirectionalLightBundle { + directional_light: DirectionalLight { + illuminance: light_consts::lux::OVERCAST_DAY, ..default() }, transform: camera_and_light_transform, diff --git a/examples/3d/lighting.rs b/examples/3d/lighting.rs index e7971766f1a37..647f2a98f6154 100644 --- a/examples/3d/lighting.rs +++ b/examples/3d/lighting.rs @@ -4,7 +4,7 @@ use std::f32::consts::PI; use bevy::{ - pbr::CascadeShadowConfigBuilder, + pbr::{light_consts, CascadeShadowConfigBuilder}, prelude::*, render::camera::{ExposureSettings, PhysicalCameraParameters}, }; @@ -14,8 +14,8 @@ fn main() { .add_plugins(DefaultPlugins) .insert_resource(Parameters(PhysicalCameraParameters { aperture_f_stops: 1.0, - shutter_speed_s: 1.0 / 15.0, - sensitivity_iso: 400.0, + shutter_speed_s: 1.0 / 100.0, + sensitivity_iso: 100.0, })) .add_systems(Startup, setup) .add_systems(Update, (update_exposure, movement, animate_light_direction)) @@ -207,7 +207,7 @@ fn setup( // directional 'sun' light commands.spawn(DirectionalLightBundle { directional_light: DirectionalLight { - illuminance: 100.0, + illuminance: light_consts::lux::OVERCAST_DAY, shadows_enabled: true, ..default() }, diff --git a/examples/3d/lightmaps.rs b/examples/3d/lightmaps.rs index 7601acc86c8bd..e8f210c341bd1 100644 --- a/examples/3d/lightmaps.rs +++ b/examples/3d/lightmaps.rs @@ -21,10 +21,10 @@ fn setup(mut commands: Commands, asset_server: Res) { ..default() }); - commands.spawn(Camera3dBundle { + commands.spawn((Camera3dBundle { transform: Transform::from_xyz(-278.0, 273.0, 800.0), ..default() - }); + },)); } fn add_lightmaps_to_meshes( diff --git a/examples/3d/load_gltf.rs b/examples/3d/load_gltf.rs index 954c78426b573..8632dcb754f6c 100644 --- a/examples/3d/load_gltf.rs +++ b/examples/3d/load_gltf.rs @@ -25,13 +25,13 @@ fn setup(mut commands: Commands, asset_server: Res) { EnvironmentMapLight { diffuse_map: asset_server.load("environment_maps/pisa_diffuse_rgb9e5_zstd.ktx2"), specular_map: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"), - intensity: 150.0, + intensity: 250.0, }, )); commands.spawn(DirectionalLightBundle { directional_light: DirectionalLight { - illuminance: 2000.0, + illuminance: light_consts::lux::OVERCAST_DAY, shadows_enabled: true, ..default() }, diff --git a/examples/3d/orthographic.rs b/examples/3d/orthographic.rs index fcae862362a5d..9d473cc933333 100644 --- a/examples/3d/orthographic.rs +++ b/examples/3d/orthographic.rs @@ -59,10 +59,10 @@ fn setup( ..default() }); // light - commands.spawn(PointLightBundle { - transform: Transform::from_xyz(3.0, 8.0, 5.0), - point_light: PointLight { - intensity: 150_000.0, + commands.spawn(DirectionalLightBundle { + transform: Transform::from_xyz(3.0, 8.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y), + directional_light: DirectionalLight { + illuminance: light_consts::lux::OVERCAST_DAY, ..default() }, ..default() diff --git a/examples/3d/parallax_mapping.rs b/examples/3d/parallax_mapping.rs index 8dcff989b3c33..e1a019a76252c 100644 --- a/examples/3d/parallax_mapping.rs +++ b/examples/3d/parallax_mapping.rs @@ -224,7 +224,7 @@ fn setup( .spawn(PointLightBundle { transform: Transform::from_xyz(1.8, 0.7, -1.1), point_light: PointLight { - intensity: 50_000.0, + intensity: 100_000.0, // Mini-sun point light shadows_enabled: true, ..default() }, diff --git a/examples/3d/parenting.rs b/examples/3d/parenting.rs index 193ffe088775d..21aad8e91c3ce 100644 --- a/examples/3d/parenting.rs +++ b/examples/3d/parenting.rs @@ -55,10 +55,10 @@ fn setup( }); }); // light - commands.spawn(PointLightBundle { - transform: Transform::from_xyz(4.0, 5.0, -4.0), - point_light: PointLight { - intensity: 150_000.0, + commands.spawn(DirectionalLightBundle { + transform: Transform::from_xyz(4.0, 5.0, -4.0).looking_at(Vec3::ZERO, Vec3::Y), + directional_light: DirectionalLight { + illuminance: light_consts::lux::OVERCAST_DAY, ..default() }, ..default() diff --git a/examples/3d/pbr.rs b/examples/3d/pbr.rs index 93db44862c68b..2c1a751d9fae6 100644 --- a/examples/3d/pbr.rs +++ b/examples/3d/pbr.rs @@ -1,6 +1,6 @@ //! This example shows how to configure Physically Based Rendering (PBR) parameters. -use bevy::{asset::LoadState, prelude::*}; +use bevy::{asset::LoadState, prelude::*, render::camera::ExposureSettings}; fn main() { App::new() @@ -51,17 +51,6 @@ fn setup( ..default() }); - // light - commands.spawn(PointLightBundle { - transform: Transform::from_xyz(50.0, 50.0, 50.0), - point_light: PointLight { - intensity: 100_000_000., - range: 100., - ..default() - }, - ..default() - }); - // labels commands.spawn( TextBundle::from_section( @@ -132,8 +121,9 @@ fn setup( EnvironmentMapLight { diffuse_map: asset_server.load("environment_maps/pisa_diffuse_rgb9e5_zstd.ktx2"), specular_map: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"), - intensity: 150.0, + intensity: 7000.0, }, + ExposureSettings::OVERCAST, )); } diff --git a/examples/3d/reflection_probes.rs b/examples/3d/reflection_probes.rs index cefe66422dedf..934564cc12c58 100644 --- a/examples/3d/reflection_probes.rs +++ b/examples/3d/reflection_probes.rs @@ -8,6 +8,7 @@ use bevy::core_pipeline::Skybox; use bevy::prelude::*; +use bevy::render::camera::ExposureSettings; use std::fmt::{Display, Formatter, Result as FmtResult}; @@ -105,14 +106,17 @@ fn spawn_scene(commands: &mut Commands, asset_server: &AssetServer) { // Spawns the camera. fn spawn_camera(commands: &mut Commands) { - commands.spawn(Camera3dBundle { - camera: Camera { - hdr: true, + commands.spawn(( + Camera3dBundle { + camera: Camera { + hdr: true, + ..default() + }, + transform: Transform::from_xyz(-6.483, 0.325, 4.381).looking_at(Vec3::ZERO, Vec3::Y), ..default() }, - transform: Transform::from_xyz(-6.483, 0.325, 4.381).looking_at(Vec3::ZERO, Vec3::Y), - ..default() - }); + ExposureSettings::OVERCAST, + )); } // Creates the sphere mesh and spawns it. @@ -150,7 +154,7 @@ fn spawn_reflection_probe(commands: &mut Commands, cubemaps: &Cubemaps) { environment_map: EnvironmentMapLight { diffuse_map: cubemaps.diffuse.clone(), specular_map: cubemaps.specular_reflection_probe.clone(), - intensity: 150.0, + intensity: 5000.0, }, }); } @@ -186,7 +190,7 @@ fn add_environment_map_to_camera( .insert(create_camera_environment_map_light(&cubemaps)) .insert(Skybox { image: cubemaps.skybox.clone(), - brightness: 150.0, + brightness: 5000.0, }); } } @@ -305,7 +309,7 @@ fn create_camera_environment_map_light(cubemaps: &Cubemaps) -> EnvironmentMapLig EnvironmentMapLight { diffuse_map: cubemaps.diffuse.clone(), specular_map: cubemaps.specular_environment_map.clone(), - intensity: 150.0, + intensity: 5000.0, } } diff --git a/examples/3d/render_to_texture.rs b/examples/3d/render_to_texture.rs index 179915738a512..9689f40aaddee 100644 --- a/examples/3d/render_to_texture.rs +++ b/examples/3d/render_to_texture.rs @@ -89,17 +89,7 @@ fn setup( // NOTE: we add the light to all layers so it affects both the rendered-to-texture cube, and the cube on which we display the texture // Setting the layer to RenderLayers::layer(0) would cause the main view to be lit, but the rendered-to-texture cube to be unlit. // Setting the layer to RenderLayers::layer(1) would cause the rendered-to-texture cube to be lit, but the main view to be unlit. - commands.spawn(( - PointLightBundle { - transform: Transform::from_translation(Vec3::new(0.0, 0.0, 10.0)), - point_light: PointLight { - intensity: 150_000.0, - ..default() - }, - ..default() - }, - RenderLayers::all(), - )); + commands.spawn((DirectionalLightBundle::default(), RenderLayers::all())); commands.spawn(( Camera3dBundle { diff --git a/examples/3d/shadow_biases.rs b/examples/3d/shadow_biases.rs index bce16ac9f7758..3cb5e7afd9496 100644 --- a/examples/3d/shadow_biases.rs +++ b/examples/3d/shadow_biases.rs @@ -3,7 +3,10 @@ #[path = "../helpers/camera_controller.rs"] mod camera_controller; -use bevy::{pbr::ShadowFilteringMethod, prelude::*}; +use bevy::{ + pbr::{light_consts, ShadowFilteringMethod}, + prelude::*, +}; use camera_controller::{CameraController, CameraControllerPlugin}; fn main() { @@ -68,7 +71,7 @@ fn setup( }); builder.spawn(DirectionalLightBundle { directional_light: DirectionalLight { - illuminance: 1500.0, + illuminance: light_consts::lux::OVERCAST_DAY, shadow_depth_bias: 0.0, shadow_normal_bias: 0.0, shadows_enabled: true, diff --git a/examples/3d/shadow_caster_receiver.rs b/examples/3d/shadow_caster_receiver.rs index 9506e1809552d..d0d04cfe2eea1 100644 --- a/examples/3d/shadow_caster_receiver.rs +++ b/examples/3d/shadow_caster_receiver.rs @@ -3,7 +3,7 @@ use std::f32::consts::PI; use bevy::{ - pbr::{CascadeShadowConfigBuilder, NotShadowCaster, NotShadowReceiver}, + pbr::{light_consts, CascadeShadowConfigBuilder, NotShadowCaster, NotShadowReceiver}, prelude::*, }; @@ -92,7 +92,7 @@ fn setup( commands.spawn(DirectionalLightBundle { directional_light: DirectionalLight { - illuminance: 1500.0, + illuminance: light_consts::lux::OVERCAST_DAY, shadows_enabled: true, ..default() }, @@ -128,7 +128,7 @@ fn toggle_light( for mut light in &mut point_lights { light.intensity = if light.intensity == 0.0 { println!("Using PointLight"); - 500_000.0 + 1_000_000.0 // Mini-sun point light } else { 0.0 }; @@ -136,7 +136,7 @@ fn toggle_light( for mut light in &mut directional_lights { light.illuminance = if light.illuminance == 0.0 { println!("Using DirectionalLight"); - 1500.0 + light_consts::lux::OVERCAST_DAY } else { 0.0 }; diff --git a/examples/3d/spherical_area_lights.rs b/examples/3d/spherical_area_lights.rs index e4667e0a1e36a..0060d71d065ec 100644 --- a/examples/3d/spherical_area_lights.rs +++ b/examples/3d/spherical_area_lights.rs @@ -4,6 +4,7 @@ use bevy::prelude::*; fn main() { App::new() + .insert_resource(AmbientLight::NONE) .add_plugins(DefaultPlugins) .add_systems(Startup, setup) .run(); @@ -15,10 +16,10 @@ fn setup( mut materials: ResMut>, ) { // camera - commands.spawn(Camera3dBundle { + commands.spawn((Camera3dBundle { transform: Transform::from_xyz(0.2, 1.5, 2.5).looking_at(Vec3::ZERO, Vec3::Y), ..default() - }); + },)); // plane commands.spawn(PbrBundle { @@ -58,7 +59,7 @@ fn setup( .with_children(|children| { children.spawn(PointLightBundle { point_light: PointLight { - intensity: 100_000.0, + intensity: 4000.0, radius, color: Color::rgb(0.2, 0.2, 1.0), ..default() diff --git a/examples/3d/split_screen.rs b/examples/3d/split_screen.rs index 898c911548d78..6cc63ad7af0ed 100644 --- a/examples/3d/split_screen.rs +++ b/examples/3d/split_screen.rs @@ -37,7 +37,6 @@ fn setup( commands.spawn(DirectionalLightBundle { transform: Transform::from_rotation(Quat::from_euler(EulerRot::ZYX, 0.0, 1.0, -PI / 4.)), directional_light: DirectionalLight { - illuminance: 1500.0, shadows_enabled: true, ..default() }, diff --git a/examples/3d/spotlight.rs b/examples/3d/spotlight.rs index d3c86356aeef8..73704be9bfca7 100644 --- a/examples/3d/spotlight.rs +++ b/examples/3d/spotlight.rs @@ -2,11 +2,7 @@ use std::f32::consts::*; -use bevy::{ - diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, - pbr::NotShadowCaster, - prelude::*, -}; +use bevy::{pbr::NotShadowCaster, prelude::*}; use rand::{rngs::StdRng, Rng, SeedableRng}; fn main() { @@ -15,11 +11,7 @@ fn main() { brightness: 4.0, ..default() }) - .add_plugins(( - DefaultPlugins, - FrameTimeDiagnosticsPlugin, - LogDiagnosticsPlugin::default(), - )) + .add_plugins(DefaultPlugins) .add_systems(Startup, setup) .add_systems(Update, (light_sway, movement)) .run(); @@ -82,7 +74,7 @@ fn setup( transform: Transform::from_xyz(1.0 + x, 2.0, z) .looking_at(Vec3::new(1.0 + x, 0.0, z), Vec3::X), spot_light: SpotLight { - intensity: 100_000.0, // lumens + intensity: 4000.0, // lumens color: Color::WHITE, shadows_enabled: true, inner_angle: PI / 4.0 * 0.85, @@ -111,14 +103,14 @@ fn setup( } // camera - commands.spawn((Camera3dBundle { + commands.spawn(Camera3dBundle { camera: Camera { hdr: true, ..default() }, transform: Transform::from_xyz(-4.0, 5.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y), ..default() - },)); + }); } fn light_sway(time: Res