From 3bbdd769399ea30bc5fd36b0d01503e1b8b36de1 Mon Sep 17 00:00:00 2001 From: Doonv <58695417+doonv@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:39:57 +0200 Subject: [PATCH 01/22] Add DirectionLight lux constants --- crates/bevy_pbr/src/light.rs | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/crates/bevy_pbr/src/light.rs b/crates/bevy_pbr/src/light.rs index 4befa56fff767..e746ece377247 100644 --- a/crates/bevy_pbr/src/light.rs +++ b/crates/bevy_pbr/src/light.rs @@ -215,8 +215,45 @@ impl Default for DirectionalLight { } impl DirectionalLight { + /// | 0.0001 | | +/// | 0.002 | Moonless clear night sky with airglow | +/// | 0.05–0.3 | Full moon on a clear night | +/// | 3.4 | Dark limit of civil twilight under a clear sky | +/// | 20–50 | Public areas with dark surroundings | +/// | 50 | Family living room lights | +/// | 80 | Office building hallway/toilet lighting | +/// | 100 | Very dark overcast day | +/// | 150 | Train station platforms | +/// | 320–500 | Office lighting | +/// | 400 | Sunrise or sunset on a clear day. | +/// | 1000 | Overcast day; typical TV studio lighting | +/// | 10,000–25,000 | Full daylight (not direct sun) | +/// | 32,000–100,000 | Direct sunlight | pub const DEFAULT_SHADOW_DEPTH_BIAS: f32 = 0.02; pub const DEFAULT_SHADOW_NORMAL_BIAS: f32 = 1.8; + + /// The amount of light (lux) in a moonless, overcast night sky. (starlight) + pub const MOONLESS_NIGHT_LUX: f32 = 0.0001; + /// The amount of light (lux) in a moonless clear night sky with airglow. + pub const FULL_MOON_NIGHT_LUX: f32 = 0.05; + /// The amount of light (lux) in a full moon on a clear night. + pub const CIVIL_TWILIGHT_LUX: f32 = 3.4; + /// The amount of light (lux) in a dark limit of civil twilight under a clear sky. + pub const LIVING_ROOM_LUX: f32 = 50.; + /// The amount of light (lux) in a office building hallway/toilet lighting. + pub const HALLWAY_LUX: f32 = 80.; + /// The amount of light (lux) in a family living room lights. + pub const DARK_OVERCAST_DAY_LUX: f32 = 100.; + /// The amount of light (lux) in a office. + pub const OFFICE_LUX: f32 = 320.; + /// The amount of light (lux) on Sunrise or sunset on a clear day. + pub const CLEAR_SUNRISE_LUX: f32 = 400.; + /// The amount of light (lux) on very dark overcast day. + pub const OVERCAST_DAY_LUX: 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.; } /// Controls the resolution of [`DirectionalLight`] shadow maps. From db0588353d08878740f4c8944db4f891361dd2d9 Mon Sep 17 00:00:00 2001 From: Doonv <58695417+doonv@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:40:09 +0200 Subject: [PATCH 02/22] Fix lighting example --- examples/3d/lighting.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/3d/lighting.rs b/examples/3d/lighting.rs index 9e68a4012c0d2..d0a7e39b15d97 100644 --- a/examples/3d/lighting.rs +++ b/examples/3d/lighting.rs @@ -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)) @@ -220,7 +220,7 @@ fn setup( // directional 'sun' light commands.spawn(DirectionalLightBundle { directional_light: DirectionalLight { - illuminance: 100.0, + illuminance: DirectionalLight::OVERCAST_DAY_LUX, shadows_enabled: true, ..default() }, From 2d1e53555df22c43f4f68e115b5bcc0c03476b1a Mon Sep 17 00:00:00 2001 From: Doonv <58695417+doonv@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:45:12 +0200 Subject: [PATCH 03/22] Fix pbr example --- examples/3d/pbr.rs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/examples/3d/pbr.rs b/examples/3d/pbr.rs index 1195c46f9c611..2892b5f53c19c 100644 --- a/examples/3d/pbr.rs +++ b/examples/3d/pbr.rs @@ -57,17 +57,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( @@ -138,7 +127,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: 200.0, }, )); } From 04e78a628db270a1801ec91b6d3bb479805cf69e Mon Sep 17 00:00:00 2001 From: Doonv <58695417+doonv@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:50:54 +0200 Subject: [PATCH 04/22] Fix wireframe example --- examples/3d/wireframe.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/examples/3d/wireframe.rs b/examples/3d/wireframe.rs index f21d74fe44966..a1559b76a8cd2 100644 --- a/examples/3d/wireframe.rs +++ b/examples/3d/wireframe.rs @@ -17,6 +17,7 @@ use bevy::{ RenderPlugin, }, }; +use bevy_internal::render::camera::ExposureSettings; fn main() { App::new() @@ -94,19 +95,24 @@ fn setup( // light commands.spawn(PointLightBundle { - transform: Transform::from_xyz(4.0, 8.0, 4.0), + transform: Transform::from_xyz(0.0, 2.0, 0.0), point_light: PointLight { - intensity: 150_000.0, + intensity: 4000.0, ..default() }, ..default() }); // camera - commands.spawn(Camera3dBundle { - transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), - ..default() - }); + commands.spawn(( + Camera3dBundle { + transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), + ..default() + }, + ExposureSettings { + ev100: ExposureSettings::EV100_INDOOR, + }, + )); // Text used to show controls commands.spawn( From bca8c959ee5afbf519506061e34a02c7e87e1805 Mon Sep 17 00:00:00 2001 From: Doonv <58695417+doonv@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:54:33 +0200 Subject: [PATCH 05/22] Fix vertex_colors example --- examples/3d/vertex_colors.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/examples/3d/vertex_colors.rs b/examples/3d/vertex_colors.rs index 8bd8c46f7c031..703db763e3228 100644 --- a/examples/3d/vertex_colors.rs +++ b/examples/3d/vertex_colors.rs @@ -42,17 +42,19 @@ fn setup( transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }); - // light - commands.spawn(PointLightBundle { - point_light: PointLight { - intensity: 500_000.0, + + // Light + commands.spawn(DirectionalLightBundle { + directional_light: DirectionalLight { + illuminance: DirectionalLight::OVERCAST_DAY_LUX, shadows_enabled: true, ..default() }, - transform: Transform::from_xyz(4.0, 8.0, 4.0), + transform: Transform::from_xyz(4.0, 5.0, 4.0).looking_at(Vec3::ZERO, Vec3::Y), ..default() }); - // camera + + // Camera commands.spawn(Camera3dBundle { transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), ..default() From 42cd62892288692764072002f075a79e60b8b8f1 Mon Sep 17 00:00:00 2001 From: Doonv <58695417+doonv@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:57:59 +0200 Subject: [PATCH 06/22] Fix DirectionLight constants --- crates/bevy_pbr/src/light.rs | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/crates/bevy_pbr/src/light.rs b/crates/bevy_pbr/src/light.rs index e746ece377247..83fdecffcf741 100644 --- a/crates/bevy_pbr/src/light.rs +++ b/crates/bevy_pbr/src/light.rs @@ -215,28 +215,14 @@ impl Default for DirectionalLight { } impl DirectionalLight { - /// | 0.0001 | | -/// | 0.002 | Moonless clear night sky with airglow | -/// | 0.05–0.3 | Full moon on a clear night | -/// | 3.4 | Dark limit of civil twilight under a clear sky | -/// | 20–50 | Public areas with dark surroundings | -/// | 50 | Family living room lights | -/// | 80 | Office building hallway/toilet lighting | -/// | 100 | Very dark overcast day | -/// | 150 | Train station platforms | -/// | 320–500 | Office lighting | -/// | 400 | Sunrise or sunset on a clear day. | -/// | 1000 | Overcast day; typical TV studio lighting | -/// | 10,000–25,000 | Full daylight (not direct sun) | -/// | 32,000–100,000 | Direct sunlight | pub const DEFAULT_SHADOW_DEPTH_BIAS: f32 = 0.02; pub const DEFAULT_SHADOW_NORMAL_BIAS: f32 = 1.8; /// The amount of light (lux) in a moonless, overcast night sky. (starlight) pub const MOONLESS_NIGHT_LUX: f32 = 0.0001; - /// The amount of light (lux) in a moonless clear night sky with airglow. - pub const FULL_MOON_NIGHT_LUX: f32 = 0.05; /// The amount of light (lux) in a full moon on a clear night. + pub const FULL_MOON_NIGHT_LUX: f32 = 0.05; + /// The amount of light (lux) in dark limit of civil twilight under a clear sky. pub const CIVIL_TWILIGHT_LUX: f32 = 3.4; /// The amount of light (lux) in a dark limit of civil twilight under a clear sky. pub const LIVING_ROOM_LUX: f32 = 50.; From 082abdb370d30f1411ea13f7582a30e1bd296e15 Mon Sep 17 00:00:00 2001 From: Doonv <58695417+doonv@users.noreply.github.com> Date: Sun, 28 Jan 2024 17:58:30 +0200 Subject: [PATCH 07/22] A lot more examples --- crates/bevy_pbr/src/light.rs | 69 ++++++++++++++++++++++------------ examples/3d/lighting.rs | 4 +- examples/3d/spotlight.rs | 9 +---- examples/3d/transmission.rs | 10 +++-- examples/3d/transparency_3d.rs | 28 ++++++++------ examples/3d/two_passes.rs | 22 ++++++----- examples/3d/vertex_colors.rs | 3 +- examples/3d/wireframe.rs | 2 +- 8 files changed, 89 insertions(+), 58 deletions(-) diff --git a/crates/bevy_pbr/src/light.rs b/crates/bevy_pbr/src/light.rs index 83fdecffcf741..0f532de17aa0b 100644 --- a/crates/bevy_pbr/src/light.rs +++ b/crates/bevy_pbr/src/light.rs @@ -20,6 +20,52 @@ use bevy_utils::{tracing::warn, EntityHashMap}; use crate::*; +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 quantityof 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)) + 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) + 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) in a full moon on a clear night. + pub const FULL_MOON_NIGHT: f32 = 0.05; + /// The amount of light (lux) in dark limit of civil twilight under a clear sky. + pub const CIVIL_TWILIGHT: f32 = 3.4; + /// The amount of light (lux) in a dark limit of civil twilight under a clear sky. + pub const LIVING_ROOM: f32 = 50.; + /// The amount of light (lux) in a office building hallway/toilet lighting. + pub const HALLWAY: f32 = 80.; + /// The amount of light (lux) in a family living room lights. + pub const DARK_OVERCAST_DAY: f32 = 100.; + /// The amount of light (lux) in a office. + pub const OFFICE: f32 = 320.; + /// The amount of light (lux) on Sunrise or sunset on a clear day. + pub const CLEAR_SUNRISE: f32 = 400.; + /// The amount of light (lux) on very dark overcast day. + 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 @@ -217,29 +263,6 @@ impl Default for DirectionalLight { impl DirectionalLight { pub const DEFAULT_SHADOW_DEPTH_BIAS: f32 = 0.02; pub const DEFAULT_SHADOW_NORMAL_BIAS: f32 = 1.8; - - /// The amount of light (lux) in a moonless, overcast night sky. (starlight) - pub const MOONLESS_NIGHT_LUX: f32 = 0.0001; - /// The amount of light (lux) in a full moon on a clear night. - pub const FULL_MOON_NIGHT_LUX: f32 = 0.05; - /// The amount of light (lux) in dark limit of civil twilight under a clear sky. - pub const CIVIL_TWILIGHT_LUX: f32 = 3.4; - /// The amount of light (lux) in a dark limit of civil twilight under a clear sky. - pub const LIVING_ROOM_LUX: f32 = 50.; - /// The amount of light (lux) in a office building hallway/toilet lighting. - pub const HALLWAY_LUX: f32 = 80.; - /// The amount of light (lux) in a family living room lights. - pub const DARK_OVERCAST_DAY_LUX: f32 = 100.; - /// The amount of light (lux) in a office. - pub const OFFICE_LUX: f32 = 320.; - /// The amount of light (lux) on Sunrise or sunset on a clear day. - pub const CLEAR_SUNRISE_LUX: f32 = 400.; - /// The amount of light (lux) on very dark overcast day. - pub const OVERCAST_DAY_LUX: 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.; } /// Controls the resolution of [`DirectionalLight`] shadow maps. diff --git a/examples/3d/lighting.rs b/examples/3d/lighting.rs index d0a7e39b15d97..2e4b43c9258b6 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::{CascadeShadowConfigBuilder, light_consts}, prelude::*, render::camera::{ExposureSettings, PhysicalCameraParameters}, }; @@ -220,7 +220,7 @@ fn setup( // directional 'sun' light commands.spawn(DirectionalLightBundle { directional_light: DirectionalLight { - illuminance: DirectionalLight::OVERCAST_DAY_LUX, + illuminance: light_consts::lux::OVERCAST_DAY, shadows_enabled: true, ..default() }, diff --git a/examples/3d/spotlight.rs b/examples/3d/spotlight.rs index 533dc9dd2b817..b80657f8f5b36 100644 --- a/examples/3d/spotlight.rs +++ b/examples/3d/spotlight.rs @@ -1,7 +1,6 @@ use std::f32::consts::*; use bevy::{ - diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, pbr::NotShadowCaster, prelude::*, }; @@ -13,11 +12,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(); @@ -86,7 +81,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, diff --git a/examples/3d/transmission.rs b/examples/3d/transmission.rs index 156d51f2359f2..6c5d8454ab3d7 100644 --- a/examples/3d/transmission.rs +++ b/examples/3d/transmission.rs @@ -27,7 +27,7 @@ use bevy::{ }, pbr::{NotShadowCaster, PointLightShadowMap, TransmittedShadowReceiver}, prelude::*, - render::camera::TemporalJitter, + render::camera::{ExposureSettings, TemporalJitter}, render::view::ColorGrading, }; @@ -35,7 +35,6 @@ use bevy::{ use bevy::core_pipeline::experimental::taa::{ TemporalAntiAliasBundle, TemporalAntiAliasPlugin, TemporalAntiAliasSettings, }; - use rand::random; fn main() { @@ -325,7 +324,7 @@ fn setup( transform: Transform::from_xyz(-1.0, 1.7, 0.0), point_light: PointLight { color: Color::ANTIQUE_WHITE * 0.8 + Color::ORANGE_RED * 0.2, - intensity: 60_000.0, + intensity: 4_000.0, radius: 0.2, range: 5.0, shadows_enabled: true, @@ -359,6 +358,9 @@ fn setup( specular_map: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"), }, BloomSettings::default(), + ExposureSettings { + ev100: ExposureSettings::EV100_INDOOR, + }, )); // Controls Text @@ -648,7 +650,7 @@ fn flicker_system( let c = (s * 7.0).cos() * 0.0125 + (s * 2.0).cos() * 0.025; let (mut light, mut light_transform) = light.single_mut(); let mut flame_transform = flame.single_mut(); - light.intensity = 60_000.0 + 3000.0 * (a + b + c); + light.intensity = 4_000.0 + 3000.0 * (a + b + c); flame_transform.translation = Vec3::new(-1.0, 1.23, 0.0); flame_transform.look_at(Vec3::new(-1.0 - c, 1.7 - b, 0.0 - a), Vec3::X); flame_transform.rotate(Quat::from_euler(EulerRot::XYZ, 0.0, 0.0, PI / 2.0)); diff --git a/examples/3d/transparency_3d.rs b/examples/3d/transparency_3d.rs index 697728dc317a0..af710182fcba4 100644 --- a/examples/3d/transparency_3d.rs +++ b/examples/3d/transparency_3d.rs @@ -3,6 +3,7 @@ //! The `fade_transparency` system smoothly changes the transparency over time. use bevy::prelude::*; +use bevy::pbr::light_consts; fn main() { App::new() @@ -18,13 +19,14 @@ fn setup( mut meshes: ResMut>, mut materials: ResMut>, ) { - // opaque plane, uses `alpha_mode: Opaque` by default + // Opaque plane, uses `alpha_mode: Opaque` by default commands.spawn(PbrBundle { mesh: meshes.add(shape::Plane::from_size(6.0)), material: materials.add(Color::rgb(0.3, 0.5, 0.3)), ..default() }); - // transparent sphere, uses `alpha_mode: Mask(f32)` + + // Transparent sphere, uses `alpha_mode: Mask(f32)` commands.spawn(PbrBundle { mesh: meshes.add( Mesh::try_from(shape::Icosphere { @@ -47,7 +49,8 @@ fn setup( transform: Transform::from_xyz(1.0, 0.5, -1.5), ..default() }); - // transparent unlit sphere, uses `alpha_mode: Mask(f32)` + + // Transparent unlit sphere, uses `alpha_mode: Mask(f32)` commands.spawn(PbrBundle { mesh: meshes.add( Mesh::try_from(shape::Icosphere { @@ -65,7 +68,8 @@ fn setup( transform: Transform::from_xyz(-1.0, 0.5, -1.5), ..default() }); - // transparent cube, uses `alpha_mode: Blend` + + // Transparent cube, uses `alpha_mode: Blend` commands.spawn(PbrBundle { mesh: meshes.add(shape::Cube { size: 1.0 }), // Notice how there is no need to set the `alpha_mode` explicitly here. @@ -75,7 +79,7 @@ fn setup( transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }); - // opaque sphere + // Opaque sphere commands.spawn(PbrBundle { mesh: meshes.add( Mesh::try_from(shape::Icosphere { @@ -88,17 +92,19 @@ fn setup( transform: Transform::from_xyz(0.0, 0.5, -1.5), ..default() }); - // light - commands.spawn(PointLightBundle { - point_light: PointLight { - intensity: 1_000_000.0, + + // Light + commands.spawn(DirectionalLightBundle { + directional_light: DirectionalLight { + illuminance: light_consts::lux::CLEAR_SUNRISE, 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 + + // Camera commands.spawn(Camera3dBundle { transform: Transform::from_xyz(-2.0, 3.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y), ..default() diff --git a/examples/3d/two_passes.rs b/examples/3d/two_passes.rs index 51d6b45b90e1d..0d5a9f60855ad 100644 --- a/examples/3d/two_passes.rs +++ b/examples/3d/two_passes.rs @@ -1,5 +1,6 @@ //! Renders two 3d passes to the same window from different perspectives. +use bevy::pbr::light_consts; use bevy::prelude::*; fn main() { @@ -9,36 +10,39 @@ fn main() { .run(); } -/// set up a simple 3D scene +/// Set up a simple 3D scene fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, ) { - // plane + // Plane commands.spawn(PbrBundle { mesh: meshes.add(shape::Plane::from_size(5.0)), material: materials.add(Color::rgb(0.3, 0.5, 0.3)), ..default() }); - // cube + + // Cube commands.spawn(PbrBundle { mesh: meshes.add(shape::Cube { size: 1.0 }), material: materials.add(Color::rgb(0.8, 0.7, 0.6)), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }); - // light - commands.spawn(PointLightBundle { - point_light: PointLight { - intensity: 500_000.0, + + // Light + 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 + + // Camera commands.spawn(Camera3dBundle { transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), ..default() diff --git a/examples/3d/vertex_colors.rs b/examples/3d/vertex_colors.rs index 703db763e3228..2f566fd0677bf 100644 --- a/examples/3d/vertex_colors.rs +++ b/examples/3d/vertex_colors.rs @@ -1,6 +1,7 @@ //! Illustrates the use of vertex colors. use bevy::{prelude::*, render::mesh::VertexAttributeValues}; +use bevy::pbr::light_consts; fn main() { App::new() @@ -46,7 +47,7 @@ fn setup( // Light commands.spawn(DirectionalLightBundle { directional_light: DirectionalLight { - illuminance: DirectionalLight::OVERCAST_DAY_LUX, + illuminance: light_consts::lux::OVERCAST_DAY, shadows_enabled: true, ..default() }, diff --git a/examples/3d/wireframe.rs b/examples/3d/wireframe.rs index a1559b76a8cd2..0e334165483f8 100644 --- a/examples/3d/wireframe.rs +++ b/examples/3d/wireframe.rs @@ -12,12 +12,12 @@ use bevy::{ pbr::wireframe::{NoWireframe, Wireframe, WireframeColor, WireframeConfig, WireframePlugin}, prelude::*, render::{ + camera::ExposureSettings, render_resource::WgpuFeatures, settings::{RenderCreation, WgpuSettings}, RenderPlugin, }, }; -use bevy_internal::render::camera::ExposureSettings; fn main() { App::new() From 4d6ed12799645432710e721569b5bb670b4fdae0 Mon Sep 17 00:00:00 2001 From: Doonv <58695417+doonv@users.noreply.github.com> Date: Sun, 28 Jan 2024 19:46:03 +0200 Subject: [PATCH 08/22] Change default and fix even more examples --- crates/bevy_pbr/src/light.rs | 25 +++++++++++++++++-------- crates/bevy_render/src/camera/camera.rs | 14 +++++++++++--- examples/3d/lighting.rs | 2 +- examples/3d/spherical_area_lights.rs | 15 +++++++++------ examples/3d/split_screen.rs | 1 - examples/3d/spotlight.rs | 20 ++++++++++---------- examples/3d/ssao.rs | 6 +++--- examples/3d/tonemapping.rs | 4 ++-- examples/3d/transmission.rs | 4 +--- examples/3d/transparency_3d.rs | 4 ++-- examples/3d/two_passes.rs | 2 +- examples/3d/update_gltf_scene.rs | 3 ++- examples/3d/vertex_colors.rs | 4 ++-- examples/3d/wireframe.rs | 4 +--- 14 files changed, 62 insertions(+), 46 deletions(-) diff --git a/crates/bevy_pbr/src/light.rs b/crates/bevy_pbr/src/light.rs index 0f532de17aa0b..d8c08c23ea1a8 100644 --- a/crates/bevy_pbr/src/light.rs +++ b/crates/bevy_pbr/src/light.rs @@ -20,14 +20,19 @@ use bevy_utils::{tracing::warn, EntityHashMap}; 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 quantityof visible light emitted by a source per unit of time, - /// in the International System of Units (SI). - /// + /// + /// 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; @@ -36,10 +41,14 @@ pub mod light_consts { /// 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. + /// 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](super::lumens) 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; @@ -252,7 +261,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::FULL_DAYLIGHT, shadows_enabled: false, shadow_depth_bias: Self::DEFAULT_SHADOW_DEPTH_BIAS, shadow_normal_bias: Self::DEFAULT_SHADOW_NORMAL_BIAS, diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index 540f0fc3e30f5..25aa67728b00c 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -95,6 +95,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; @@ -115,9 +125,7 @@ impl ExposureSettings { impl Default for ExposureSettings { fn default() -> Self { - Self { - ev100: Self::EV100_INDOOR, - } + Self::OVERCAST } } diff --git a/examples/3d/lighting.rs b/examples/3d/lighting.rs index 2e4b43c9258b6..79cbeff9fb1b4 100644 --- a/examples/3d/lighting.rs +++ b/examples/3d/lighting.rs @@ -4,7 +4,7 @@ use std::f32::consts::PI; use bevy::{ - pbr::{CascadeShadowConfigBuilder, light_consts}, + pbr::{light_consts, CascadeShadowConfigBuilder}, prelude::*, render::camera::{ExposureSettings, PhysicalCameraParameters}, }; diff --git a/examples/3d/spherical_area_lights.rs b/examples/3d/spherical_area_lights.rs index 62d80d6422f23..fee25ff99744a 100644 --- a/examples/3d/spherical_area_lights.rs +++ b/examples/3d/spherical_area_lights.rs @@ -1,6 +1,6 @@ //! Demonstrates how lighting is affected by different radius of point lights. -use bevy::prelude::*; +use bevy::{prelude::*, render::camera::ExposureSettings}; fn main() { App::new() @@ -15,10 +15,13 @@ fn setup( mut materials: ResMut>, ) { // camera - commands.spawn(Camera3dBundle { - transform: Transform::from_xyz(0.2, 1.5, 2.5).looking_at(Vec3::ZERO, Vec3::Y), - ..default() - }); + commands.spawn(( + Camera3dBundle { + transform: Transform::from_xyz(0.2, 1.5, 2.5).looking_at(Vec3::ZERO, Vec3::Y), + ..default() + }, + ExposureSettings::INDOOR, + )); // plane commands.spawn(PbrBundle { @@ -62,7 +65,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 69ae185ad40da..f1faaad3d7dff 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 b80657f8f5b36..26d1485cec954 100644 --- a/examples/3d/spotlight.rs +++ b/examples/3d/spotlight.rs @@ -1,9 +1,6 @@ use std::f32::consts::*; -use bevy::{ - pbr::NotShadowCaster, - prelude::*, -}; +use bevy::{pbr::NotShadowCaster, render::camera::ExposureSettings, prelude::*}; use rand::{rngs::StdRng, Rng, SeedableRng}; fn main() { @@ -110,14 +107,17 @@ fn setup( } // camera - commands.spawn((Camera3dBundle { - camera: Camera { - hdr: true, + 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() }, - transform: Transform::from_xyz(-4.0, 5.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y), - ..default() - },)); + ExposureSettings::INDOOR, + )); } fn light_sway(time: Res