From 432c427f3249e0d41ed7f3a5749d09a4e7788e99 Mon Sep 17 00:00:00 2001 From: Robert Swain Date: Sun, 16 Apr 2023 22:33:38 +0200 Subject: [PATCH 01/46] Implement basic exposure settings --- crates/bevy_pbr/src/render/light.rs | 14 +------- crates/bevy_pbr/src/render/pbr_functions.wgsl | 2 +- crates/bevy_render/src/camera/camera.rs | 36 +++++++++++++++++++ crates/bevy_render/src/view/mod.rs | 27 +++++++++----- crates/bevy_render/src/view/view.wgsl | 1 + 5 files changed, 57 insertions(+), 23 deletions(-) diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index dc28bdfc0690b..f681ddf1778c3 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -854,18 +854,6 @@ pub fn prepare_lights( flags |= DirectionalLightFlags::SHADOWS_ENABLED; } - // convert from illuminance (lux) to candelas - // - // exposure is hard coded at the moment but should be replaced - // by values coming from the camera - // see: https://google.github.io/filament/Filament.html#imagingpipeline/physicallybasedcamera/exposuresettings - const APERTURE: f32 = 4.0; - const SHUTTER_SPEED: f32 = 1.0 / 250.0; - const SENSITIVITY: f32 = 100.0; - let ev100 = f32::log2(APERTURE * APERTURE / SHUTTER_SPEED) - f32::log2(SENSITIVITY / 100.0); - let exposure = 1.0 / (f32::powf(2.0, ev100) * 1.2); - let intensity = light.illuminance * exposure; - let num_cascades = light .cascade_shadow_config .bounds @@ -876,7 +864,7 @@ pub fn prepare_lights( cascades: [GpuDirectionalCascade::default(); MAX_CASCADES_PER_LIGHT], // premultiply color by intensity // we don't use the alpha at all, so no reason to multiply only [0..3] - color: Vec4::from_slice(&light.color.as_linear_rgba_f32()) * intensity, + color: Vec4::from_slice(&light.color.as_linear_rgba_f32()) * light.illuminance, // direction is negated to be ready for N.L dir_to_light: light.transform.back(), flags: flags.bits, diff --git a/crates/bevy_pbr/src/render/pbr_functions.wgsl b/crates/bevy_pbr/src/render/pbr_functions.wgsl index 1bc782fc19f3d..02474cd43fe8e 100644 --- a/crates/bevy_pbr/src/render/pbr_functions.wgsl +++ b/crates/bevy_pbr/src/render/pbr_functions.wgsl @@ -254,7 +254,7 @@ fn pbr( // Total light output_color = vec4( - direct_light + indirect_light + emissive_light, + view.exposure * (direct_light + indirect_light + emissive_light), output_color.a ); diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index 851783a3f12b6..75d09a53983c0 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -76,6 +76,36 @@ pub struct ComputedCameraValues { old_viewport_size: Option, } +#[derive(Component)] +pub struct ExposureSettings { + pub aperture_f_stops: f32, + pub shutter_speed_s: f32, + pub sensitivity_iso: f32, +} + +impl Default for ExposureSettings { + fn default() -> Self { + Self { + aperture_f_stops: 4.0, + shutter_speed_s: 1.0 / 250.0, + sensitivity_iso: 100.0, + } + } +} + +impl ExposureSettings { + #[inline] + pub fn ev100(&self) -> f32 { + (self.aperture_f_stops * self.aperture_f_stops / self.shutter_speed_s).log2() + - (self.sensitivity_iso / 100.0).log2() + } + + #[inline] + pub fn exposure(&self) -> f32 { + 1.0 / (2.0f32.powf(self.ev100()) * 1.2) + } +} + /// The defining component for camera entities, storing information about how and what to render /// through this camera. /// @@ -573,6 +603,7 @@ pub struct ExtractedCamera { pub output_mode: CameraOutputMode, pub msaa_writeback: bool, pub sorted_camera_index_for_target: usize, + pub exposure: f32, } pub fn extract_cameras( @@ -585,6 +616,7 @@ pub fn extract_cameras( &GlobalTransform, &VisibleEntities, Option<&ColorGrading>, + Option<&ExposureSettings>, Option<&TemporalJitter>, )>, >, @@ -598,6 +630,7 @@ pub fn extract_cameras( transform, visible_entities, color_grading, + exposure_settings, temporal_jitter, ) in query.iter() { @@ -630,6 +663,9 @@ pub fn extract_cameras( msaa_writeback: camera.msaa_writeback, // this will be set in sort_cameras sorted_camera_index_for_target: 0, + exposure: exposure_settings + .map(|e| e.exposure()) + .unwrap_or_else(|| ExposureSettings::default().exposure()), }, ExtractedView { projection: camera.projection_matrix(), diff --git a/crates/bevy_render/src/view/mod.rs b/crates/bevy_render/src/view/mod.rs index c602dd7628f12..27663eb437262 100644 --- a/crates/bevy_render/src/view/mod.rs +++ b/crates/bevy_render/src/view/mod.rs @@ -6,7 +6,7 @@ pub use visibility::*; pub use window::*; use crate::{ - camera::{ExtractedCamera, TemporalJitter}, + camera::{ExposureSettings, ExtractedCamera, TemporalJitter}, extract_resource::{ExtractResource, ExtractResourcePlugin}, prelude::{Image, Shader}, render_asset::RenderAssets, @@ -168,6 +168,7 @@ pub struct ViewUniform { projection: Mat4, inverse_projection: Mat4, world_position: Vec3, + exposure: f32, // viewport(x_origin, y_origin, width, height) viewport: Vec4, color_grading: ColorGrading, @@ -313,13 +314,18 @@ pub fn prepare_view_uniforms( render_device: Res, render_queue: Res, mut view_uniforms: ResMut, - views: Query<(Entity, &ExtractedView, Option<&TemporalJitter>)>, + views: Query<( + Entity, + Option<&ExtractedCamera>, + &ExtractedView, + Option<&TemporalJitter>, + )>, ) { view_uniforms.uniforms.clear(); - for (entity, camera, temporal_jitter) in &views { - let viewport = camera.viewport.as_vec4(); - let unjittered_projection = camera.projection; + for (entity, extracted_camera, extracted_view, temporal_jitter) in &views { + let viewport = extracted_view.viewport.as_vec4(); + let unjittered_projection = extracted_view.projection; let mut projection = unjittered_projection; if let Some(temporal_jitter) = temporal_jitter { @@ -327,12 +333,12 @@ pub fn prepare_view_uniforms( } let inverse_projection = projection.inverse(); - let view = camera.transform.compute_matrix(); + let view = extracted_view.transform.compute_matrix(); let inverse_view = view.inverse(); let view_uniforms = ViewUniformOffset { offset: view_uniforms.uniforms.push(ViewUniform { - view_proj: camera + view_proj: extracted_view .view_projection .unwrap_or_else(|| projection * inverse_view), unjittered_view_proj: unjittered_projection * inverse_view, @@ -341,9 +347,12 @@ pub fn prepare_view_uniforms( inverse_view, projection, inverse_projection, - world_position: camera.transform.translation(), + world_position: extracted_view.transform.translation(), + exposure: extracted_camera + .map(|c| c.exposure) + .unwrap_or_else(|| ExposureSettings::default().exposure()), viewport, - color_grading: camera.color_grading, + color_grading: extracted_view.color_grading, }), }; diff --git a/crates/bevy_render/src/view/view.wgsl b/crates/bevy_render/src/view/view.wgsl index ce50833e66f80..92349d333762b 100644 --- a/crates/bevy_render/src/view/view.wgsl +++ b/crates/bevy_render/src/view/view.wgsl @@ -16,6 +16,7 @@ struct View { projection: mat4x4, inverse_projection: mat4x4, world_position: vec3, + exposure: f32, // viewport(x_origin, y_origin, width, height) viewport: vec4, color_grading: ColorGrading, From 8fa78a92e2aa5f434013baaffada965e70bdd2dd Mon Sep 17 00:00:00 2001 From: Robert Swain Date: Sun, 16 Apr 2023 22:34:05 +0200 Subject: [PATCH 02/46] WIP: Test exposure settings in lighting example --- examples/3d/lighting.rs | 103 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 97 insertions(+), 6 deletions(-) diff --git a/examples/3d/lighting.rs b/examples/3d/lighting.rs index 4757f0e3dacb3..74381c83eace0 100644 --- a/examples/3d/lighting.rs +++ b/examples/3d/lighting.rs @@ -3,13 +3,13 @@ use std::f32::consts::PI; -use bevy::{pbr::CascadeShadowConfigBuilder, prelude::*}; +use bevy::{pbr::CascadeShadowConfigBuilder, prelude::*, render::camera::ExposureSettings}; fn main() { App::new() .add_plugins(DefaultPlugins) .add_systems(Startup, setup) - .add_systems(Update, (movement, animate_light_direction)) + .add_systems(Update, (update_exposure, movement, animate_light_direction)) .run(); } @@ -207,6 +207,7 @@ fn setup( // directional 'sun' light commands.spawn(DirectionalLightBundle { directional_light: DirectionalLight { + illuminance: 1000.0, shadows_enabled: true, ..default() }, @@ -227,11 +228,101 @@ fn setup( ..default() }); + let exposure_settings = ExposureSettings::default(); + let style = TextStyle { + font: asset_server.load("fonts/FiraMono-Medium.ttf"), + font_size: 18.0, + color: Color::WHITE, + }; + + commands.spawn( + TextBundle::from_sections(vec![ + TextSection::new( + format!("Aperture: f/{:.0}\n", exposure_settings.aperture_f_stops), + style.clone(), + ), + TextSection::new( + format!( + "Shutter speed: 1/{:.0}s\n", + 1.0 / exposure_settings.shutter_speed_s + ), + style.clone(), + ), + TextSection::new( + format!( + "Sensitivity: ISO {:.0}\n", + exposure_settings.sensitivity_iso + ), + style.clone(), + ), + TextSection::new("\n\n", style.clone()), + TextSection::new("Controls\n", style.clone()), + TextSection::new("---------------\n", style.clone()), + TextSection::new("1/2 - Decrease/Increase aperture\n", style.clone()), + TextSection::new("3/4 - Decrease/Increase shutter speed\n", style.clone()), + TextSection::new("5/6 - Decrease/Increase sensitivity\n", style), + ]) + .with_style(Style { + position_type: PositionType::Absolute, + top: Val::Px(10.0), + left: Val::Px(10.0), + ..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() + }, + exposure_settings, + )); +} + +fn update_exposure( + key_input: Res>, + mut query: Query<&mut ExposureSettings>, + mut text: Query<&mut Text>, +) { + let mut text = text.single_mut(); + let mut exposure_settings = query.single_mut(); + if key_input.just_pressed(KeyCode::Key2) { + exposure_settings.aperture_f_stops *= 2.0; + text.sections[0].value = format!("Aperture: f/{:.0}\n", exposure_settings.aperture_f_stops); + } else if key_input.just_pressed(KeyCode::Key1) { + exposure_settings.aperture_f_stops *= 0.5; + text.sections[0].value = format!("Aperture: f/{:.0}\n", exposure_settings.aperture_f_stops); + } + if key_input.just_pressed(KeyCode::Key4) { + exposure_settings.shutter_speed_s *= 2.0; + text.sections[1].value = format!( + "Shutter speed: 1/{:.0}s\n", + 1.0 / exposure_settings.shutter_speed_s + ); + } else if key_input.just_pressed(KeyCode::Key3) { + exposure_settings.shutter_speed_s *= 0.5; + text.sections[1].value = format!( + "Shutter speed: 1/{:.0}s\n", + 1.0 / exposure_settings.shutter_speed_s + ); + } + if key_input.just_pressed(KeyCode::Key6) { + exposure_settings.sensitivity_iso += 100.0; + text.sections[2].value = format!( + "Sensitivity: ISO {:.0}\n", + exposure_settings.sensitivity_iso + ); + } else if key_input.just_pressed(KeyCode::Key5) { + exposure_settings.sensitivity_iso -= 100.0; + text.sections[2].value = format!( + "Sensitivity: ISO {:.0}\n", + exposure_settings.sensitivity_iso + ); + } + if key_input.just_pressed(KeyCode::D) { + *exposure_settings = ExposureSettings::default(); + } } fn animate_light_direction( From 0cfbfd7a30ff6e16b425725fb5c1f3b6a7938a00 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Mon, 21 Aug 2023 21:18:38 -0700 Subject: [PATCH 03/46] Rebase fixes --- crates/bevy_pbr/src/render/pbr_functions.wgsl | 2 +- crates/bevy_render/src/view/mod.rs | 5 ++-- examples/3d/lighting.rs | 30 +++++-------------- 3 files changed, 10 insertions(+), 27 deletions(-) diff --git a/crates/bevy_pbr/src/render/pbr_functions.wgsl b/crates/bevy_pbr/src/render/pbr_functions.wgsl index 216719080d993..69d3f49ffbf20 100644 --- a/crates/bevy_pbr/src/render/pbr_functions.wgsl +++ b/crates/bevy_pbr/src/render/pbr_functions.wgsl @@ -272,7 +272,7 @@ fn pbr( // Total light output_color = vec4( - view.exposure * (direct_light + indirect_light + emissive_light), + view_bindings::view.exposure * (direct_light + indirect_light + emissive_light), output_color.a ); diff --git a/crates/bevy_render/src/view/mod.rs b/crates/bevy_render/src/view/mod.rs index 3900422399ff8..ce7a87d8ce3d2 100644 --- a/crates/bevy_render/src/view/mod.rs +++ b/crates/bevy_render/src/view/mod.rs @@ -359,6 +359,7 @@ pub fn prepare_view_uniforms( Option<&ExtractedCamera>, &ExtractedView, Option<&TemporalJitter>, + Option<&MipBias>, )>, ) { view_uniforms.uniforms.clear(); @@ -386,9 +387,7 @@ pub fn prepare_view_uniforms( let view_uniforms = ViewUniformOffset { offset: view_uniforms.uniforms.push(ViewUniform { - view_proj: extracted_view - .view_projection - .unwrap_or_else(|| projection * inverse_view), + view_proj, unjittered_view_proj: unjittered_projection * inverse_view, inverse_view_proj: view * inverse_projection, view, diff --git a/examples/3d/lighting.rs b/examples/3d/lighting.rs index 06c5f962d09ef..ea739b53f66dd 100644 --- a/examples/3d/lighting.rs +++ b/examples/3d/lighting.rs @@ -23,23 +23,6 @@ fn setup( mut materials: ResMut>, asset_server: Res, ) { - // example instructions - commands.spawn( - TextBundle::from_section( - "Use arrow keys to move objects", - TextStyle { - font_size: 20.0, - ..default() - }, - ) - .with_style(Style { - position_type: PositionType::Absolute, - top: Val::Px(12.0), - left: Val::Px(12.0), - ..default() - }), - ); - // ground plane commands.spawn(PbrBundle { mesh: meshes.add(shape::Plane::from_size(10.0).into()), @@ -246,12 +229,12 @@ fn setup( }); let exposure_settings = ExposureSettings::default(); + + // example instructions let style = TextStyle { - font: asset_server.load("fonts/FiraMono-Medium.ttf"), - font_size: 18.0, - color: Color::WHITE, + font_size: 20.0, + ..default() }; - commands.spawn( TextBundle::from_sections(vec![ TextSection::new( @@ -275,14 +258,15 @@ fn setup( TextSection::new("\n\n", style.clone()), TextSection::new("Controls\n", style.clone()), TextSection::new("---------------\n", style.clone()), + TextSection::new("Arrow keys - Move objects\n", style.clone()), TextSection::new("1/2 - Decrease/Increase aperture\n", style.clone()), TextSection::new("3/4 - Decrease/Increase shutter speed\n", style.clone()), TextSection::new("5/6 - Decrease/Increase sensitivity\n", style), ]) .with_style(Style { position_type: PositionType::Absolute, - top: Val::Px(10.0), - left: Val::Px(10.0), + top: Val::Px(12.0), + left: Val::Px(12.0), ..default() }), ); From ef62d30d9200f3cd95def90caece718900b9e10b Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Mon, 21 Aug 2023 21:47:39 -0700 Subject: [PATCH 04/46] Switch ExposureSettings to hold an EV100 value, improve example. --- crates/bevy_render/src/camera/camera.rs | 50 ++++++++++++----- examples/3d/lighting.rs | 73 ++++++++++++------------- 2 files changed, 71 insertions(+), 52 deletions(-) diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index bfa2e2376eed1..175aa9d5fd553 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -75,14 +75,49 @@ pub struct ComputedCameraValues { old_viewport_size: Option, } +/// How much energy a [`Camera3d`] absorbs from incoming light. +/// +/// #[derive(Component)] pub struct ExposureSettings { + /// + pub ev100: f32, +} + +impl ExposureSettings { + pub fn from_physical_camera(physical_camera_parameters: PhysicalCameraParameters) -> Self { + let p = physical_camera_parameters; + Self { + ev100: (p.aperture_f_stops * p.aperture_f_stops / p.shutter_speed_s).log2() + - (p.sensitivity_iso / 100.0).log2(), + } + } + + /// TODO: Docs + #[inline] + pub fn exposure(&self) -> f32 { + 1.0 / (2.0f32.powf(self.ev100) * 1.2) + } +} + +impl Default for ExposureSettings { + fn default() -> Self { + Self::from_physical_camera(PhysicalCameraParameters::default()) + } +} + +/// TODO: Docs (and double check these links / find better links) +#[derive(Clone, Copy)] +pub struct PhysicalCameraParameters { + /// pub aperture_f_stops: f32, + /// pub shutter_speed_s: f32, + /// pub sensitivity_iso: f32, } -impl Default for ExposureSettings { +impl Default for PhysicalCameraParameters { fn default() -> Self { Self { aperture_f_stops: 4.0, @@ -92,19 +127,6 @@ impl Default for ExposureSettings { } } -impl ExposureSettings { - #[inline] - pub fn ev100(&self) -> f32 { - (self.aperture_f_stops * self.aperture_f_stops / self.shutter_speed_s).log2() - - (self.sensitivity_iso / 100.0).log2() - } - - #[inline] - pub fn exposure(&self) -> f32 { - 1.0 / (2.0f32.powf(self.ev100()) * 1.2) - } -} - /// The defining [`Component`] for camera entities, /// storing information about how and what to render through this camera. /// diff --git a/examples/3d/lighting.rs b/examples/3d/lighting.rs index ea739b53f66dd..f402a08770203 100644 --- a/examples/3d/lighting.rs +++ b/examples/3d/lighting.rs @@ -3,21 +3,30 @@ use std::f32::consts::PI; -use bevy::{pbr::CascadeShadowConfigBuilder, prelude::*, render::camera::ExposureSettings}; +use bevy::{ + pbr::CascadeShadowConfigBuilder, + prelude::*, + render::camera::{ExposureSettings, PhysicalCameraParameters}, +}; fn main() { App::new() .add_plugins(DefaultPlugins) + .init_resource::() .add_systems(Startup, setup) .add_systems(Update, (update_exposure, movement, animate_light_direction)) .run(); } +#[derive(Resource, Default, Deref, DerefMut)] +struct Parameters(PhysicalCameraParameters); + #[derive(Component)] struct Movable; /// set up a simple 3D scene fn setup( + parameters: Res, mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, @@ -228,8 +237,6 @@ fn setup( ..default() }); - let exposure_settings = ExposureSettings::default(); - // example instructions let style = TextStyle { font_size: 20.0, @@ -238,21 +245,18 @@ fn setup( commands.spawn( TextBundle::from_sections(vec![ TextSection::new( - format!("Aperture: f/{:.0}\n", exposure_settings.aperture_f_stops), + format!("Aperture: f/{:.0}\n", parameters.aperture_f_stops), style.clone(), ), TextSection::new( format!( "Shutter speed: 1/{:.0}s\n", - 1.0 / exposure_settings.shutter_speed_s + 1.0 / parameters.shutter_speed_s ), style.clone(), ), TextSection::new( - format!( - "Sensitivity: ISO {:.0}\n", - exposure_settings.sensitivity_iso - ), + format!("Sensitivity: ISO {:.0}\n", parameters.sensitivity_iso), style.clone(), ), TextSection::new("\n\n", style.clone()), @@ -261,7 +265,8 @@ fn setup( TextSection::new("Arrow keys - Move objects\n", style.clone()), TextSection::new("1/2 - Decrease/Increase aperture\n", style.clone()), TextSection::new("3/4 - Decrease/Increase shutter speed\n", style.clone()), - TextSection::new("5/6 - Decrease/Increase sensitivity\n", style), + TextSection::new("5/6 - Decrease/Increase sensitivity\n", style.clone()), + TextSection::new("R - Reset exposure", style), ]) .with_style(Style { position_type: PositionType::Absolute, @@ -277,53 +282,45 @@ fn setup( transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), ..default() }, - exposure_settings, + ExposureSettings::from_physical_camera(**parameters), )); } fn update_exposure( key_input: Res>, + mut parameters: ResMut, mut query: Query<&mut ExposureSettings>, mut text: Query<&mut Text>, ) { + // TODO: Clamp values to a reasonable range let mut text = text.single_mut(); - let mut exposure_settings = query.single_mut(); if key_input.just_pressed(KeyCode::Key2) { - exposure_settings.aperture_f_stops *= 2.0; - text.sections[0].value = format!("Aperture: f/{:.0}\n", exposure_settings.aperture_f_stops); + parameters.aperture_f_stops *= 2.0; } else if key_input.just_pressed(KeyCode::Key1) { - exposure_settings.aperture_f_stops *= 0.5; - text.sections[0].value = format!("Aperture: f/{:.0}\n", exposure_settings.aperture_f_stops); + parameters.aperture_f_stops *= 0.5; } if key_input.just_pressed(KeyCode::Key4) { - exposure_settings.shutter_speed_s *= 2.0; - text.sections[1].value = format!( - "Shutter speed: 1/{:.0}s\n", - 1.0 / exposure_settings.shutter_speed_s - ); + parameters.shutter_speed_s *= 2.0; } else if key_input.just_pressed(KeyCode::Key3) { - exposure_settings.shutter_speed_s *= 0.5; - text.sections[1].value = format!( - "Shutter speed: 1/{:.0}s\n", - 1.0 / exposure_settings.shutter_speed_s - ); + parameters.shutter_speed_s *= 0.5; } if key_input.just_pressed(KeyCode::Key6) { - exposure_settings.sensitivity_iso += 100.0; - text.sections[2].value = format!( - "Sensitivity: ISO {:.0}\n", - exposure_settings.sensitivity_iso - ); + parameters.sensitivity_iso += 100.0; } else if key_input.just_pressed(KeyCode::Key5) { - exposure_settings.sensitivity_iso -= 100.0; - text.sections[2].value = format!( - "Sensitivity: ISO {:.0}\n", - exposure_settings.sensitivity_iso - ); + parameters.sensitivity_iso -= 100.0; } - if key_input.just_pressed(KeyCode::D) { - *exposure_settings = ExposureSettings::default(); + if key_input.just_pressed(KeyCode::R) { + *parameters = Parameters::default(); } + + text.sections[0].value = format!("Aperture: f/{:.0}\n", parameters.aperture_f_stops); + text.sections[1].value = format!( + "Shutter speed: 1/{:.0}s\n", + 1.0 / parameters.shutter_speed_s + ); + text.sections[2].value = format!("Sensitivity: ISO {:.0}\n", parameters.sensitivity_iso); + + *query.single_mut() = ExposureSettings::from_physical_camera(**parameters); } fn animate_light_direction( From f5c4166c4c025dd24ea737244d76739b398d1a55 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Mon, 21 Aug 2023 21:51:27 -0700 Subject: [PATCH 05/46] Misc --- crates/bevy_pbr/src/render/light.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index 2d0d980e7522c..fb53f0bd13767 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -865,6 +865,7 @@ pub fn prepare_lights( gpu_directional_lights[index] = GpuDirectionalLight { // Filled in later. cascades: [GpuDirectionalCascade::default(); MAX_CASCADES_PER_LIGHT], + // TODO: Is the below comment still valid? // premultiply color by intensity // we don't use the alpha at all, so no reason to multiply only [0..3] color: Vec4::from_slice(&light.color.as_linear_rgba_f32()) * light.illuminance, From ce69ab2363fd2fa72f744c6b4cbf59ffc96b5c9c Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Tue, 22 Aug 2023 19:16:35 -0700 Subject: [PATCH 06/46] Apply PR feedback --- crates/bevy_render/src/camera/camera.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index 175aa9d5fd553..0fdf9af27b883 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -85,11 +85,13 @@ pub struct ExposureSettings { } impl ExposureSettings { + pub const EV100_SUNLIGHT: f32 = 15.0; + pub const EV100_OVERCAST: f32 = 12.0; + pub const EV100_INDOOR: f32 = 7.0; + pub fn from_physical_camera(physical_camera_parameters: PhysicalCameraParameters) -> Self { - let p = physical_camera_parameters; Self { - ev100: (p.aperture_f_stops * p.aperture_f_stops / p.shutter_speed_s).log2() - - (p.sensitivity_iso / 100.0).log2(), + ev100: physical_camera_parameters.ev100(), } } @@ -102,7 +104,9 @@ impl ExposureSettings { impl Default for ExposureSettings { fn default() -> Self { - Self::from_physical_camera(PhysicalCameraParameters::default()) + Self { + ev100: Self::EV100_OVERCAST, + } } } @@ -117,6 +121,14 @@ pub struct PhysicalCameraParameters { pub sensitivity_iso: f32, } +impl PhysicalCameraParameters { + /// Calculate the [EV100](https://en.wikipedia.org/wiki/Exposure_value). + pub fn ev100(&self) -> f32 { + (self.aperture_f_stops * self.aperture_f_stops / self.shutter_speed_s).log2() + - (self.sensitivity_iso / 100.0).log2() + } +} + impl Default for PhysicalCameraParameters { fn default() -> Self { Self { From e1448158155a4c379ddb3f94b544dc83a94913ec Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Tue, 22 Aug 2023 19:38:10 -0700 Subject: [PATCH 07/46] Add brightness control to Skybox --- .../src/core_3d/main_opaque_pass_3d_node.rs | 8 +- crates/bevy_core_pipeline/src/skybox/mod.rs | 73 ++++++++++++++++--- .../bevy_core_pipeline/src/skybox/skybox.wgsl | 4 +- examples/3d/skybox.rs | 7 +- 4 files changed, 75 insertions(+), 17 deletions(-) diff --git a/crates/bevy_core_pipeline/src/core_3d/main_opaque_pass_3d_node.rs b/crates/bevy_core_pipeline/src/core_3d/main_opaque_pass_3d_node.rs index 34d8c299c94c9..db951d2cd5556 100644 --- a/crates/bevy_core_pipeline/src/core_3d/main_opaque_pass_3d_node.rs +++ b/crates/bevy_core_pipeline/src/core_3d/main_opaque_pass_3d_node.rs @@ -116,13 +116,17 @@ impl ViewNode for MainOpaquePass3dNode { } // Draw the skybox using a fullscreen triangle - if let (Some(skybox_pipeline), Some(skybox_bind_group)) = + if let (Some(skybox_pipeline), Some(SkyboxBindGroup(skybox_bind_group))) = (skybox_pipeline, skybox_bind_group) { let pipeline_cache = world.resource::(); if let Some(pipeline) = pipeline_cache.get_render_pipeline(skybox_pipeline.0) { render_pass.set_render_pipeline(pipeline); - render_pass.set_bind_group(0, &skybox_bind_group.0, &[view_uniform_offset.offset]); + render_pass.set_bind_group( + 0, + &skybox_bind_group.0, + &[view_uniform_offset.offset, skybox_bind_group.1], + ); render_pass.draw(0..3, 0..1); } } diff --git a/crates/bevy_core_pipeline/src/skybox/mod.rs b/crates/bevy_core_pipeline/src/skybox/mod.rs index ccf21334aa10a..f3cdf9b024f10 100644 --- a/crates/bevy_core_pipeline/src/skybox/mod.rs +++ b/crates/bevy_core_pipeline/src/skybox/mod.rs @@ -2,13 +2,16 @@ use bevy_app::{App, Plugin}; use bevy_asset::{load_internal_asset, Handle, HandleUntyped}; use bevy_ecs::{ prelude::{Component, Entity}, - query::With, + query::{QueryItem, With}, schedule::IntoSystemConfigs, system::{Commands, Query, Res, ResMut, Resource}, }; use bevy_reflect::TypeUuid; use bevy_render::{ - extract_component::{ExtractComponent, ExtractComponentPlugin}, + extract_component::{ + ComponentUniforms, DynamicUniformIndex, ExtractComponent, ExtractComponentPlugin, + UniformComponentPlugin, + }, render_asset::RenderAssets, render_resource::{ BindGroup, BindGroupDescriptor, BindGroupEntry, BindGroupLayout, BindGroupLayoutDescriptor, @@ -34,7 +37,10 @@ impl Plugin for SkyboxPlugin { fn build(&self, app: &mut App) { load_internal_asset!(app, SKYBOX_SHADER_HANDLE, "skybox.wgsl", Shader::from_wgsl); - app.add_plugins(ExtractComponentPlugin::::default()); + app.add_plugins(( + ExtractComponentPlugin::::default(), + UniformComponentPlugin::::default(), + )); let render_app = match app.get_sub_app_mut(RenderApp) { Ok(render_app) => render_app, @@ -70,8 +76,32 @@ impl Plugin for SkyboxPlugin { /// To do so, use `EnvironmentMapLight` alongside this component. /// /// See also . -#[derive(Component, ExtractComponent, Clone)] -pub struct Skybox(pub Handle); +#[derive(Component, Clone)] +pub struct Skybox { + pub image: Handle, + /// TODO: Docs + pub brightness: f32, +} + +impl ExtractComponent for Skybox { + type Query = &'static Self; + type Filter = (); + type Out = (Self, SkyboxUniforms); + + fn extract_component(item: QueryItem<'_, Self::Query>) -> Option { + Some(( + item.clone(), + SkyboxUniforms { + brightness: item.brightness, + }, + )) + } +} + +#[derive(Component, ShaderType, Clone)] +pub struct SkyboxUniforms { + brightness: f32, +} #[derive(Resource)] struct SkyboxPipeline { @@ -109,6 +139,16 @@ impl SkyboxPipeline { }, count: None, }, + BindGroupLayoutEntry { + binding: 3, + visibility: ShaderStages::FRAGMENT, + ty: BindingType::Buffer { + ty: BufferBindingType::Uniform, + has_dynamic_offset: true, + min_binding_size: Some(SkyboxUniforms::min_size()), + }, + count: None, + }, ], }; @@ -207,20 +247,23 @@ fn prepare_skybox_pipelines( } #[derive(Component)] -pub struct SkyboxBindGroup(pub BindGroup); +pub struct SkyboxBindGroup(pub (BindGroup, u32)); fn queue_skybox_bind_groups( mut commands: Commands, pipeline: Res, view_uniforms: Res, + skybox_uniforms: Res>, images: Res>, render_device: Res, - views: Query<(Entity, &Skybox)>, + views: Query<(Entity, &Skybox, &DynamicUniformIndex)>, ) { - for (entity, skybox) in &views { - if let (Some(skybox), Some(view_uniforms)) = - (images.get(&skybox.0), view_uniforms.uniforms.binding()) - { + for (entity, skybox, skybox_uniform_index) in &views { + if let (Some(skybox), Some(view_uniforms), Some(skybox_uniforms)) = ( + images.get(&skybox.image), + view_uniforms.uniforms.binding(), + skybox_uniforms.binding(), + ) { let bind_group = render_device.create_bind_group(&BindGroupDescriptor { label: Some("skybox_bind_group"), layout: &pipeline.bind_group_layout, @@ -237,10 +280,16 @@ fn queue_skybox_bind_groups( binding: 2, resource: view_uniforms, }, + BindGroupEntry { + binding: 3, + resource: skybox_uniforms, + }, ], }); - commands.entity(entity).insert(SkyboxBindGroup(bind_group)); + commands + .entity(entity) + .insert(SkyboxBindGroup((bind_group, skybox_uniform_index.index()))); } } } diff --git a/crates/bevy_core_pipeline/src/skybox/skybox.wgsl b/crates/bevy_core_pipeline/src/skybox/skybox.wgsl index 5f31b753072ea..15034c38cf388 100644 --- a/crates/bevy_core_pipeline/src/skybox/skybox.wgsl +++ b/crates/bevy_core_pipeline/src/skybox/skybox.wgsl @@ -6,6 +6,8 @@ var skybox: texture_cube; var skybox_sampler: sampler; @group(0) @binding(2) var view: View; +@group(0) @binding(3) +var brightness: f32; struct VertexOutput { @builtin(position) clip_position: vec4, @@ -48,5 +50,5 @@ fn skybox_fragment(in: VertexOutput) -> @location(0) vec4 { // position, to the fragment world position on the near clipping plane let ray_direction = in.world_position - view.world_position; // cube maps are left-handed so we negate the z coordinate - return textureSample(skybox, skybox_sampler, ray_direction * vec3(1.0, 1.0, -1.0)); + return textureSample(skybox, skybox_sampler, ray_direction * vec3(1.0, 1.0, -1.0)) * brightness; } diff --git a/examples/3d/skybox.rs b/examples/3d/skybox.rs index 7cc6b91c4b5f6..cb65ece5a2b8a 100644 --- a/examples/3d/skybox.rs +++ b/examples/3d/skybox.rs @@ -76,7 +76,10 @@ fn setup(mut commands: Commands, asset_server: Res) { ..default() }, CameraController::default(), - Skybox(skybox_handle.clone()), + Skybox { + image: skybox_handle.clone(), + brightness: 1.0, + }, )); // ambient light @@ -159,7 +162,7 @@ fn asset_loaded( } for mut skybox in &mut skyboxes { - skybox.0 = cubemap.image_handle.clone(); + skybox.image = cubemap.image_handle.clone(); } cubemap.is_loaded = true; From 56bb844b6fd89b415375a49ed3a8d1bde0e47e69 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Tue, 22 Aug 2023 19:47:01 -0700 Subject: [PATCH 08/46] Apply exposure to skybox --- crates/bevy_core_pipeline/src/skybox/mod.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/crates/bevy_core_pipeline/src/skybox/mod.rs b/crates/bevy_core_pipeline/src/skybox/mod.rs index f3cdf9b024f10..5b6f403396e68 100644 --- a/crates/bevy_core_pipeline/src/skybox/mod.rs +++ b/crates/bevy_core_pipeline/src/skybox/mod.rs @@ -8,6 +8,7 @@ use bevy_ecs::{ }; use bevy_reflect::TypeUuid; use bevy_render::{ + camera::ExposureSettings, extract_component::{ ComponentUniforms, DynamicUniformIndex, ExtractComponent, ExtractComponentPlugin, UniformComponentPlugin, @@ -84,15 +85,21 @@ pub struct Skybox { } impl ExtractComponent for Skybox { - type Query = &'static Self; + type Query = (&'static Self, Option<&'static ExposureSettings>); type Filter = (); type Out = (Self, SkyboxUniforms); - fn extract_component(item: QueryItem<'_, Self::Query>) -> Option { + fn extract_component( + (skybox, exposure_settings): QueryItem<'_, Self::Query>, + ) -> Option { + let exposure = exposure_settings + .map(|e| e.exposure()) + .unwrap_or_else(|| ExposureSettings::default().exposure()); + Some(( - item.clone(), + skybox.clone(), SkyboxUniforms { - brightness: item.brightness, + brightness: skybox.brightness * exposure, }, )) } From 4dd2ede25e29cbe35c1b3dcff68cfa0349c1eb3c Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Tue, 22 Aug 2023 19:52:56 -0700 Subject: [PATCH 09/46] Add EnvironmentMapLight::brightness --- crates/bevy_pbr/src/environment_map/environment_map.wgsl | 4 ++-- crates/bevy_pbr/src/environment_map/mod.rs | 3 +++ crates/bevy_pbr/src/render/light.rs | 4 ++++ crates/bevy_pbr/src/render/mesh_view_types.wgsl | 1 + examples/3d/pbr.rs | 1 + 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/bevy_pbr/src/environment_map/environment_map.wgsl b/crates/bevy_pbr/src/environment_map/environment_map.wgsl index ed10e2d0ba894..95cabaa5f9c7a 100644 --- a/crates/bevy_pbr/src/environment_map/environment_map.wgsl +++ b/crates/bevy_pbr/src/environment_map/environment_map.wgsl @@ -39,7 +39,7 @@ fn environment_map_light( let kD = diffuse_color * Edss; var out: EnvironmentMapLight; - out.diffuse = (FmsEms + kD) * irradiance; - out.specular = FssEss * radiance; + out.diffuse = (FmsEms + kD) * irradiance * bindings::lights.environment_map_brightness; + out.specular = FssEss * radiance * bindings::lights.environment_map_brightness; return out; } diff --git a/crates/bevy_pbr/src/environment_map/mod.rs b/crates/bevy_pbr/src/environment_map/mod.rs index 7e6e8732028eb..6faa02de9d57a 100644 --- a/crates/bevy_pbr/src/environment_map/mod.rs +++ b/crates/bevy_pbr/src/environment_map/mod.rs @@ -50,6 +50,9 @@ impl Plugin for EnvironmentMapPlugin { pub struct EnvironmentMapLight { pub diffuse_map: Handle, pub specular_map: Handle, + /// TODO: Docs + // TODO: What to call this? + pub brightness: f32, } impl EnvironmentMapLight { diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index fb53f0bd13767..1d6996ba92746 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -212,6 +212,7 @@ pub struct GpuLights { // offset from spot light's light index to spot light's shadow map index spot_light_shadowmap_offset: i32, environment_map_smallest_specular_mip_level: u32, + environment_map_brightness: f32, } // NOTE: this must be kept in sync with the same constants in pbr.frag @@ -960,6 +961,9 @@ pub fn prepare_lights( .and_then(|env_map| images.get(&env_map.specular_map)) .map(|specular_map| specular_map.mip_level_count - 1) .unwrap_or(0), + environment_map_brightness: environment_map + .map(|env_map| env_map.brightness) + .unwrap_or(1.0), }; // 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 b944aa2792e2f..9c2164750a774 100644 --- a/crates/bevy_pbr/src/render/mesh_view_types.wgsl +++ b/crates/bevy_pbr/src/render/mesh_view_types.wgsl @@ -60,6 +60,7 @@ struct Lights { n_directional_lights: u32, spot_light_shadowmap_offset: i32, environment_map_smallest_specular_mip_level: u32, + environment_map_brightness: f32, }; struct Fog { diff --git a/examples/3d/pbr.rs b/examples/3d/pbr.rs index 2bbc62a5edc51..3e70789e3771c 100644 --- a/examples/3d/pbr.rs +++ b/examples/3d/pbr.rs @@ -140,6 +140,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"), + brightness: 1.0, }, )); } From 64bcfa8dbd9bc58a4547a2d09aa3a0fc174b8531 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Tue, 22 Aug 2023 19:56:02 -0700 Subject: [PATCH 10/46] Add misc todo --- crates/bevy_core_pipeline/src/skybox/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/bevy_core_pipeline/src/skybox/mod.rs b/crates/bevy_core_pipeline/src/skybox/mod.rs index 5b6f403396e68..0c2c5576b8f83 100644 --- a/crates/bevy_core_pipeline/src/skybox/mod.rs +++ b/crates/bevy_core_pipeline/src/skybox/mod.rs @@ -105,6 +105,7 @@ impl ExtractComponent for Skybox { } } +// TODO: Replace with a push constant once WebGPU gets support for that #[derive(Component, ShaderType, Clone)] pub struct SkyboxUniforms { brightness: f32, From f9e07308324b26f04942067b3719e4ec04c5bb82 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Tue, 22 Aug 2023 20:22:47 -0700 Subject: [PATCH 11/46] Misc rename, example fixes --- .../bevy_pbr/src/environment_map/environment_map.wgsl | 10 +++++----- crates/bevy_pbr/src/environment_map/mod.rs | 3 +-- crates/bevy_pbr/src/render/light.rs | 6 +++--- crates/bevy_pbr/src/render/mesh_view_types.wgsl | 2 +- examples/3d/load_gltf.rs | 1 + examples/3d/pbr.rs | 2 +- examples/3d/tonemapping.rs | 1 + examples/tools/scene_viewer/main.rs | 1 + 8 files changed, 14 insertions(+), 12 deletions(-) diff --git a/crates/bevy_pbr/src/environment_map/environment_map.wgsl b/crates/bevy_pbr/src/environment_map/environment_map.wgsl index 95cabaa5f9c7a..e55e7ca3920ea 100644 --- a/crates/bevy_pbr/src/environment_map/environment_map.wgsl +++ b/crates/bevy_pbr/src/environment_map/environment_map.wgsl @@ -21,9 +21,9 @@ fn environment_map_light( // Split-sum approximation for image based lighting: https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf // Technically we could use textureNumLevels(environment_map_specular) - 1 here, but we use a uniform // because textureNumLevels() does not work on WebGL2 - let radiance_level = perceptual_roughness * f32(bindings::lights.environment_map_smallest_specular_mip_level); - let irradiance = textureSample(bindings::environment_map_diffuse, bindings::environment_map_sampler, vec3(N.xy, -N.z)).rgb; - let radiance = textureSampleLevel(bindings::environment_map_specular, bindings::environment_map_sampler, vec3(R.xy, -R.z), radiance_level).rgb; + let radiance_level = perceptual_roughness * f32(bindings,:: lights.environment_map_smallest_specular_mip_level); + let irradiance = textureSample(bindings,:: environment_map_diffuse, bindings,:: environment_map_sampler, vec3(N.xy, -N.z)).rgb; + let radiance = textureSampleLevel(bindings,:: environment_map_specular, bindings,:: environment_map_sampler, vec3(R.xy, -R.z), radiance_level).rgb; // Multiscattering approximation: https://www.jcgt.org/published/0008/01/03/paper.pdf // Useful reference: https://bruop.github.io/ibl @@ -39,7 +39,7 @@ fn environment_map_light( let kD = diffuse_color * Edss; var out: EnvironmentMapLight; - out.diffuse = (FmsEms + kD) * irradiance * bindings::lights.environment_map_brightness; - out.specular = FssEss * radiance * bindings::lights.environment_map_brightness; + out.diffuse = (FmsEms + kD) * irradiance * bindings::lights.environment_map_intensity; + out.specular = FssEss * radiance * bindings::lights.environment_map_intensity; return out; } diff --git a/crates/bevy_pbr/src/environment_map/mod.rs b/crates/bevy_pbr/src/environment_map/mod.rs index 6faa02de9d57a..e691017e67aeb 100644 --- a/crates/bevy_pbr/src/environment_map/mod.rs +++ b/crates/bevy_pbr/src/environment_map/mod.rs @@ -51,8 +51,7 @@ pub struct EnvironmentMapLight { pub diffuse_map: Handle, pub specular_map: Handle, /// TODO: Docs - // TODO: What to call this? - pub brightness: f32, + pub intensity: f32, } impl EnvironmentMapLight { diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index 1d6996ba92746..7ad233438123c 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -212,7 +212,7 @@ pub struct GpuLights { // offset from spot light's light index to spot light's shadow map index spot_light_shadowmap_offset: i32, environment_map_smallest_specular_mip_level: u32, - environment_map_brightness: f32, + environment_map_intensity: f32, } // NOTE: this must be kept in sync with the same constants in pbr.frag @@ -961,8 +961,8 @@ pub fn prepare_lights( .and_then(|env_map| images.get(&env_map.specular_map)) .map(|specular_map| specular_map.mip_level_count - 1) .unwrap_or(0), - environment_map_brightness: environment_map - .map(|env_map| env_map.brightness) + environment_map_intensity: environment_map + .map(|env_map| env_map.intensity) .unwrap_or(1.0), }; diff --git a/crates/bevy_pbr/src/render/mesh_view_types.wgsl b/crates/bevy_pbr/src/render/mesh_view_types.wgsl index 9c2164750a774..fe6fef99cb6a2 100644 --- a/crates/bevy_pbr/src/render/mesh_view_types.wgsl +++ b/crates/bevy_pbr/src/render/mesh_view_types.wgsl @@ -60,7 +60,7 @@ struct Lights { n_directional_lights: u32, spot_light_shadowmap_offset: i32, environment_map_smallest_specular_mip_level: u32, - environment_map_brightness: f32, + environment_map_intensity: f32, }; struct Fog { diff --git a/examples/3d/load_gltf.rs b/examples/3d/load_gltf.rs index 33b1559907f0f..0b85e5a190ad9 100644 --- a/examples/3d/load_gltf.rs +++ b/examples/3d/load_gltf.rs @@ -30,6 +30,7 @@ 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: 1.0, }, )); diff --git a/examples/3d/pbr.rs b/examples/3d/pbr.rs index 3e70789e3771c..7334d65a90597 100644 --- a/examples/3d/pbr.rs +++ b/examples/3d/pbr.rs @@ -140,7 +140,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"), - brightness: 1.0, + intensity: 1.0, }, )); } diff --git a/examples/3d/tonemapping.rs b/examples/3d/tonemapping.rs index d2f87b079a257..4d316eb61729f 100644 --- a/examples/3d/tonemapping.rs +++ b/examples/3d/tonemapping.rs @@ -69,6 +69,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: 1.0, }, )); diff --git a/examples/tools/scene_viewer/main.rs b/examples/tools/scene_viewer/main.rs index 69df243382648..f1be1ac372d7e 100644 --- a/examples/tools/scene_viewer/main.rs +++ b/examples/tools/scene_viewer/main.rs @@ -143,6 +143,7 @@ fn setup_scene_after_load( .load("assets/environment_maps/pisa_diffuse_rgb9e5_zstd.ktx2"), specular_map: asset_server .load("assets/environment_maps/pisa_specular_rgb9e5_zstd.ktx2"), + intensity: 1.0, }, camera_controller, )); From c42824e3e01fe7c222c737301f47e0b5f76618ed Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Wed, 23 Aug 2023 16:54:21 -0700 Subject: [PATCH 12/46] Docs --- crates/bevy_core_pipeline/src/skybox/mod.rs | 4 +++- crates/bevy_pbr/src/environment_map/mod.rs | 4 +++- crates/bevy_pbr/src/render/light.rs | 3 +-- crates/bevy_render/src/camera/camera.rs | 5 +++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/bevy_core_pipeline/src/skybox/mod.rs b/crates/bevy_core_pipeline/src/skybox/mod.rs index 0c2c5576b8f83..acb123017fab2 100644 --- a/crates/bevy_core_pipeline/src/skybox/mod.rs +++ b/crates/bevy_core_pipeline/src/skybox/mod.rs @@ -80,7 +80,9 @@ impl Plugin for SkyboxPlugin { #[derive(Component, Clone)] pub struct Skybox { pub image: Handle, - /// TODO: Docs + /// Scale factor applied to the skybox image. + /// After applying this multiplier to the image samples, the resulting values should + /// be in units of [cd/m^2](https://en.wikipedia.org/wiki/Candela_per_square_metre). pub brightness: f32, } diff --git a/crates/bevy_pbr/src/environment_map/mod.rs b/crates/bevy_pbr/src/environment_map/mod.rs index e691017e67aeb..953b30344d8cc 100644 --- a/crates/bevy_pbr/src/environment_map/mod.rs +++ b/crates/bevy_pbr/src/environment_map/mod.rs @@ -50,7 +50,9 @@ impl Plugin for EnvironmentMapPlugin { pub struct EnvironmentMapLight { pub diffuse_map: Handle, pub specular_map: Handle, - /// TODO: Docs + /// Scale factor applied to both the diffuse and specular cubemap. + /// After applying this multiplier to the image samples, the resulting values should + /// be in units of [cd/m^2](https://en.wikipedia.org/wiki/Candela_per_square_metre). pub intensity: f32, } diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index 7ad233438123c..32d56b8fba1ac 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -866,8 +866,7 @@ pub fn prepare_lights( gpu_directional_lights[index] = GpuDirectionalLight { // Filled in later. cascades: [GpuDirectionalCascade::default(); MAX_CASCADES_PER_LIGHT], - // TODO: Is the below comment still valid? - // premultiply color by intensity + // premultiply color by illuminance // we don't use the alpha at all, so no reason to multiply only [0..3] color: Vec4::from_slice(&light.color.as_linear_rgba_f32()) * light.illuminance, // direction is negated to be ready for N.L diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index 0fdf9af27b883..ba5c2cd5f30cb 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -95,7 +95,7 @@ impl ExposureSettings { } } - /// TODO: Docs + /// Converts EV100 values to exposure values. #[inline] pub fn exposure(&self) -> f32 { 1.0 / (2.0f32.powf(self.ev100) * 1.2) @@ -110,7 +110,8 @@ impl Default for ExposureSettings { } } -/// TODO: Docs (and double check these links / find better links) +/// Parameters based on physical camera characteristics for calculating +/// EV100 values for use with [`ExposureSettings`]. #[derive(Clone, Copy)] pub struct PhysicalCameraParameters { /// From 71860bbac40606a91512ef6a87790b6c44da29b9 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Sat, 26 Aug 2023 14:00:40 -0700 Subject: [PATCH 13/46] Fix shader --- crates/bevy_pbr/src/environment_map/environment_map.wgsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/bevy_pbr/src/environment_map/environment_map.wgsl b/crates/bevy_pbr/src/environment_map/environment_map.wgsl index e55e7ca3920ea..7b5f88d609937 100644 --- a/crates/bevy_pbr/src/environment_map/environment_map.wgsl +++ b/crates/bevy_pbr/src/environment_map/environment_map.wgsl @@ -21,9 +21,9 @@ fn environment_map_light( // Split-sum approximation for image based lighting: https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf // Technically we could use textureNumLevels(environment_map_specular) - 1 here, but we use a uniform // because textureNumLevels() does not work on WebGL2 - let radiance_level = perceptual_roughness * f32(bindings,:: lights.environment_map_smallest_specular_mip_level); - let irradiance = textureSample(bindings,:: environment_map_diffuse, bindings,:: environment_map_sampler, vec3(N.xy, -N.z)).rgb; - let radiance = textureSampleLevel(bindings,:: environment_map_specular, bindings,:: environment_map_sampler, vec3(R.xy, -R.z), radiance_level).rgb; + let radiance_level = perceptual_roughness * f32(bindings::lights.environment_map_smallest_specular_mip_level); + let irradiance = textureSample(bindings::environment_map_diffuse, bindings::environment_map_sampler, vec3(N.xy, -N.z)).rgb; + let radiance = textureSampleLevel(bindings::environment_map_specular, bindings::environment_map_sampler, vec3(R.xy, -R.z), radiance_level).rgb; // Multiscattering approximation: https://www.jcgt.org/published/0008/01/03/paper.pdf // Useful reference: https://bruop.github.io/ibl From e325da3c314342bd69ff5e2c0db756f6f27504ca Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Fri, 15 Dec 2023 14:15:56 -0800 Subject: [PATCH 14/46] Rebase fixes --- crates/bevy_core_pipeline/src/skybox/mod.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/crates/bevy_core_pipeline/src/skybox/mod.rs b/crates/bevy_core_pipeline/src/skybox/mod.rs index 746c8d16bb1a7..c12b25351968c 100644 --- a/crates/bevy_core_pipeline/src/skybox/mod.rs +++ b/crates/bevy_core_pipeline/src/skybox/mod.rs @@ -15,12 +15,7 @@ use bevy_render::{ render_asset::RenderAssets, render_resource::{ binding_types::{sampler, texture_cube, uniform_buffer}, - BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutEntries, - CachedRenderPipelineId, ColorTargetState, ColorWrites, CompareFunction, DepthBiasState, - DepthStencilState, FragmentState, MultisampleState, PipelineCache, PrimitiveState, - RenderPipelineDescriptor, SamplerBindingType, Shader, ShaderStages, - SpecializedRenderPipeline, SpecializedRenderPipelines, StencilFaceState, StencilState, - TextureFormat, TextureSampleType, VertexState, + *, }, renderer::RenderDevice, texture::{BevyDefault, Image}, @@ -85,12 +80,12 @@ pub struct Skybox { } impl ExtractComponent for Skybox { - type Query = (&'static Self, Option<&'static ExposureSettings>); + type Data = (&'static Self, Option<&'static ExposureSettings>); type Filter = (); type Out = (Self, SkyboxUniforms); fn extract_component( - (skybox, exposure_settings): QueryItem<'_, Self::Query>, + (skybox, exposure_settings): QueryItem<'_, Self::Data>, ) -> Option { let exposure = exposure_settings .map(|e| e.exposure()) From ac2c148a7b4d98baf46e9ee9795ada5b5e3d3648 Mon Sep 17 00:00:00 2001 From: GitGhillie Date: Sat, 16 Dec 2023 10:50:41 +0100 Subject: [PATCH 15/46] Input -> ButtonInput --- 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 2bee6c9e53401..b5a250f06692e 100644 --- a/examples/3d/lighting.rs +++ b/examples/3d/lighting.rs @@ -287,7 +287,7 @@ fn setup( } fn update_exposure( - key_input: Res>, + key_input: Res>, mut parameters: ResMut, mut query: Query<&mut ExposureSettings>, mut text: Query<&mut Text>, From b1c0ddd7461cccfff5c4a42ea07efa8b435887b4 Mon Sep 17 00:00:00 2001 From: GitGhillie Date: Sat, 16 Dec 2023 22:12:56 +0100 Subject: [PATCH 16/46] Change default exposure to indoor --- crates/bevy_render/src/camera/camera.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index f25c129693974..9c96d09bf5351 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -110,7 +110,7 @@ impl ExposureSettings { impl Default for ExposureSettings { fn default() -> Self { Self { - ev100: Self::EV100_OVERCAST, + ev100: Self::EV100_INDOOR, } } } From 540ab66602f2603bfd43af2c23e0eacbd70ae35d Mon Sep 17 00:00:00 2001 From: GitGhillie Date: Sat, 16 Dec 2023 22:38:19 +0100 Subject: [PATCH 17/46] Adjust a few examples --- examples/3d/3d_scene.rs | 2 +- examples/3d/load_gltf.rs | 3 ++- examples/3d/skybox.rs | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/3d/3d_scene.rs b/examples/3d/3d_scene.rs index ca142616fdb53..6780ba13de67e 100644 --- a/examples/3d/3d_scene.rs +++ b/examples/3d/3d_scene.rs @@ -32,7 +32,7 @@ fn setup( // light commands.spawn(PointLightBundle { point_light: PointLight { - intensity: 1500.0, + intensity: 250000.0, shadows_enabled: true, ..default() }, diff --git a/examples/3d/load_gltf.rs b/examples/3d/load_gltf.rs index e1f18f6246f0a..954c78426b573 100644 --- a/examples/3d/load_gltf.rs +++ b/examples/3d/load_gltf.rs @@ -25,12 +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: 1.0, + intensity: 150.0, }, )); commands.spawn(DirectionalLightBundle { directional_light: DirectionalLight { + illuminance: 2000.0, shadows_enabled: true, ..default() }, diff --git a/examples/3d/skybox.rs b/examples/3d/skybox.rs index e1204d9310aa8..e279b225fb7d3 100644 --- a/examples/3d/skybox.rs +++ b/examples/3d/skybox.rs @@ -77,7 +77,7 @@ fn setup(mut commands: Commands, asset_server: Res) { CameraController::default(), Skybox { image: skybox_handle.clone(), - brightness: 1.0, + brightness: 150.0, }, )); From d04ad9a68004185f7805f8befb5f66002dd88156 Mon Sep 17 00:00:00 2001 From: GitGhillie Date: Sat, 16 Dec 2023 23:09:47 +0100 Subject: [PATCH 18/46] Adjust PhysicalCameraParameters to an exposure of roughly 7 as well --- crates/bevy_render/src/camera/camera.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index 9c96d09bf5351..c7835496b247a 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -138,8 +138,8 @@ impl PhysicalCameraParameters { impl Default for PhysicalCameraParameters { fn default() -> Self { Self { - aperture_f_stops: 4.0, - shutter_speed_s: 1.0 / 250.0, + aperture_f_stops: 1.0, + shutter_speed_s: 1.0 / 125.0, sensitivity_iso: 100.0, } } From dc61b42a9e15e0e7367c398ac82a39f8d34356e5 Mon Sep 17 00:00:00 2001 From: GitGhillie Date: Sat, 16 Dec 2023 23:49:00 +0100 Subject: [PATCH 19/46] adjust lighting example by changing the initial exposure --- examples/3d/lighting.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/3d/lighting.rs b/examples/3d/lighting.rs index b5a250f06692e..ad0d55bf1529a 100644 --- a/examples/3d/lighting.rs +++ b/examples/3d/lighting.rs @@ -12,7 +12,11 @@ use bevy::{ fn main() { App::new() .add_plugins(DefaultPlugins) - .init_resource::() + .insert_resource(Parameters(PhysicalCameraParameters { + aperture_f_stops: 1.0, + shutter_speed_s: 1.0 / 15.0, + sensitivity_iso: 400.0, + })) .add_systems(Startup, setup) .add_systems(Update, (update_exposure, movement, animate_light_direction)) .run(); @@ -216,7 +220,7 @@ fn setup( // directional 'sun' light commands.spawn(DirectionalLightBundle { directional_light: DirectionalLight { - illuminance: 1000.0, + illuminance: 100.0, shadows_enabled: true, ..default() }, From 479223abbbd78f30da3f5d0a84d82438e573acc4 Mon Sep 17 00:00:00 2001 From: GitGhillie Date: Sun, 17 Dec 2023 12:37:20 +0100 Subject: [PATCH 20/46] increase point light intensity in 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 ad0d55bf1529a..981ac55ebbd59 100644 --- a/examples/3d/lighting.rs +++ b/examples/3d/lighting.rs @@ -135,7 +135,7 @@ fn setup( // transform: Transform::from_xyz(5.0, 8.0, 2.0), transform: Transform::from_xyz(1.0, 2.0, 0.0), point_light: PointLight { - intensity: 1600.0, // lumens - roughly a 100W non-halogen incandescent bulb + intensity: 4000.0, // lumens - roughly a 300W non-halogen incandescent bulb color: Color::RED, shadows_enabled: true, ..default() @@ -163,7 +163,7 @@ fn setup( transform: Transform::from_xyz(-1.0, 2.0, 0.0) .looking_at(Vec3::new(-1.0, 0.0, 0.0), Vec3::Z), spot_light: SpotLight { - intensity: 1600.0, // lumens - roughly a 100W non-halogen incandescent bulb + intensity: 4000.0, // lumens - roughly a 300W non-halogen incandescent bulb color: Color::GREEN, shadows_enabled: true, inner_angle: 0.6, @@ -195,7 +195,7 @@ fn setup( // transform: Transform::from_xyz(5.0, 8.0, 2.0), transform: Transform::from_xyz(0.0, 4.0, 0.0), point_light: PointLight { - intensity: 1600.0, // lumens - roughly a 100W non-halogen incandescent bulb + intensity: 4000.0, // lumens - roughly a 300W non-halogen incandescent bulb color: Color::BLUE, shadows_enabled: true, ..default() From 6cf04238c866df211f5dbd7a41b30df1e2a1a536 Mon Sep 17 00:00:00 2001 From: GitGhillie Date: Mon, 18 Dec 2023 20:53:39 +0100 Subject: [PATCH 21/46] Adjust default ambient light --- crates/bevy_pbr/src/light.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_pbr/src/light.rs b/crates/bevy_pbr/src/light.rs index bcded3f475fc1..ec77250fd52fd 100644 --- a/crates/bevy_pbr/src/light.rs +++ b/crates/bevy_pbr/src/light.rs @@ -555,7 +555,7 @@ fn calculate_cascade( /// # use bevy_ecs::system::ResMut; /// # use bevy_pbr::AmbientLight; /// fn setup_ambient_light(mut ambient_light: ResMut) { -/// ambient_light.brightness = 0.3; +/// ambient_light.brightness = 20.0; /// } /// ``` #[derive(Resource, Clone, Debug, ExtractResource, Reflect)] @@ -570,7 +570,7 @@ impl Default for AmbientLight { fn default() -> Self { Self { color: Color::rgb(1.0, 1.0, 1.0), - brightness: 0.05, + brightness: 8.0, } } } From f67e704bbd3d7f09b3e4e715743b310f6ca1f7e6 Mon Sep 17 00:00:00 2001 From: GitGhillie Date: Mon, 18 Dec 2023 21:00:25 +0100 Subject: [PATCH 22/46] Adjust 3d examples --- examples/3d/3d_gizmos.rs | 2 +- examples/3d/3d_shapes.rs | 2 +- examples/3d/3d_viewport_to_world.rs | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/3d/3d_gizmos.rs b/examples/3d/3d_gizmos.rs index ecee465e07b10..1ab106ac73930 100644 --- a/examples/3d/3d_gizmos.rs +++ b/examples/3d/3d_gizmos.rs @@ -37,7 +37,7 @@ fn setup( // light commands.spawn(PointLightBundle { point_light: PointLight { - intensity: 1500.0, + intensity: 250000.0, shadows_enabled: true, ..default() }, diff --git a/examples/3d/3d_shapes.rs b/examples/3d/3d_shapes.rs index 999d11a74c878..0413f1d91b8ff 100644 --- a/examples/3d/3d_shapes.rs +++ b/examples/3d/3d_shapes.rs @@ -64,7 +64,7 @@ fn setup( commands.spawn(PointLightBundle { point_light: PointLight { - intensity: 9000.0, + intensity: 1500000.0, range: 100., shadows_enabled: true, ..default() diff --git a/examples/3d/3d_viewport_to_world.rs b/examples/3d/3d_viewport_to_world.rs index 308e379a4e113..2a69c304f5e70 100644 --- a/examples/3d/3d_viewport_to_world.rs +++ b/examples/3d/3d_viewport_to_world.rs @@ -61,6 +61,10 @@ 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() + }, ..default() }); From 2d2f95d21908ceedae1871faac25f4440234c453 Mon Sep 17 00:00:00 2001 From: GitGhillie Date: Tue, 19 Dec 2023 21:15:49 +0100 Subject: [PATCH 23/46] Adjust some more 3d examples --- examples/3d/anti_aliasing.rs | 2 ++ examples/3d/atmospheric_fog.rs | 1 + examples/3d/bloom_3d.rs | 6 +++--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/3d/anti_aliasing.rs b/examples/3d/anti_aliasing.rs index 849bdbbc93a83..7faeb21cc0955 100644 --- a/examples/3d/anti_aliasing.rs +++ b/examples/3d/anti_aliasing.rs @@ -288,6 +288,7 @@ fn setup( // Light commands.spawn(DirectionalLightBundle { directional_light: DirectionalLight { + illuminance: 3000.0, shadows_enabled: true, ..default() }, @@ -324,6 +325,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, }, FogSettings { color: Color::rgba_u8(43, 44, 47, 255), diff --git a/examples/3d/atmospheric_fog.rs b/examples/3d/atmospheric_fog.rs index 60071e2dd9554..e1e5849dd1da6 100644 --- a/examples/3d/atmospheric_fog.rs +++ b/examples/3d/atmospheric_fog.rs @@ -61,6 +61,7 @@ fn setup_terrain_scene( commands.spawn(DirectionalLightBundle { directional_light: DirectionalLight { color: Color::rgb(0.98, 0.95, 0.82), + illuminance: 3000.0, shadows_enabled: true, ..default() }, diff --git a/examples/3d/bloom_3d.rs b/examples/3d/bloom_3d.rs index b67f1d3909a93..65635860aa282 100644 --- a/examples/3d/bloom_3d.rs +++ b/examples/3d/bloom_3d.rs @@ -39,15 +39,15 @@ fn setup_scene( )); let material_emissive1 = materials.add(StandardMaterial { - emissive: Color::rgb_linear(13.99, 5.32, 2.0), // 4. Put something bright in a dark environment to see the effect + emissive: Color::rgb_linear(2300.0, 900.0, 300.0), // 4. Put something bright in a dark environment to see the effect ..default() }); let material_emissive2 = materials.add(StandardMaterial { - emissive: Color::rgb_linear(2.0, 13.99, 5.32), + emissive: Color::rgb_linear(300.0, 2300.0, 900.0), ..default() }); let material_emissive3 = materials.add(StandardMaterial { - emissive: Color::rgb_linear(5.32, 2.0, 13.99), + emissive: Color::rgb_linear(900.0, 300.0, 2300.0), ..default() }); let material_non_emissive = materials.add(StandardMaterial { From 81e7c255d8386f8e468bc2b9e1b1797262123571 Mon Sep 17 00:00:00 2001 From: GitGhillie Date: Wed, 20 Dec 2023 20:55:14 +0100 Subject: [PATCH 24/46] Adjust some more 3d examples part 3 --- examples/3d/deferred_rendering.rs | 4 +++- examples/3d/fog.rs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/3d/deferred_rendering.rs b/examples/3d/deferred_rendering.rs index 6b39e3fd4f160..7bfa660580e2c 100644 --- a/examples/3d/deferred_rendering.rs +++ b/examples/3d/deferred_rendering.rs @@ -62,6 +62,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, }, DepthPrepass, MotionVectorPrepass, @@ -71,6 +72,7 @@ fn setup( commands.spawn(DirectionalLightBundle { directional_light: DirectionalLight { + illuminance: 4000.0, shadows_enabled: true, ..default() }, @@ -145,7 +147,7 @@ fn setup( // Light commands.spawn(PointLightBundle { point_light: PointLight { - intensity: 1.0, + intensity: 150.0, radius: 0.125, shadows_enabled: true, color: sphere_color, diff --git a/examples/3d/fog.rs b/examples/3d/fog.rs index 253c2c8d567b5..5e43415813f99 100644 --- a/examples/3d/fog.rs +++ b/examples/3d/fog.rs @@ -128,7 +128,7 @@ fn setup_pyramid_scene( commands.spawn(PointLightBundle { transform: Transform::from_xyz(0.0, 1.0, 0.0), point_light: PointLight { - intensity: 1500., + intensity: 300_000., range: 100., shadows_enabled: true, ..default() From 418ec05e9b1443d3a1f0e5a052896b53d9784e18 Mon Sep 17 00:00:00 2001 From: GitGhillie Date: Mon, 25 Dec 2023 20:13:26 +0100 Subject: [PATCH 25/46] Adjust some more 3d examples part 4 --- examples/3d/generate_custom_mesh.rs | 2 +- examples/3d/orthographic.rs | 4 ++++ examples/3d/parallax_mapping.rs | 2 +- examples/3d/parenting.rs | 4 ++++ examples/3d/pbr.rs | 4 ++-- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/3d/generate_custom_mesh.rs b/examples/3d/generate_custom_mesh.rs index 89b054798c0ce..cee6a16abace0 100644 --- a/examples/3d/generate_custom_mesh.rs +++ b/examples/3d/generate_custom_mesh.rs @@ -56,7 +56,7 @@ fn setup( // Light up the scene. commands.spawn(PointLightBundle { point_light: PointLight { - intensity: 1000.0, + intensity: 100_000.0, range: 100.0, ..default() }, diff --git a/examples/3d/orthographic.rs b/examples/3d/orthographic.rs index c34e06a788513..bfc0d6474bb7f 100644 --- a/examples/3d/orthographic.rs +++ b/examples/3d/orthographic.rs @@ -61,6 +61,10 @@ fn setup( // light commands.spawn(PointLightBundle { transform: Transform::from_xyz(3.0, 8.0, 5.0), + point_light: PointLight { + intensity: 150_000.0, + ..default() + }, ..default() }); } diff --git a/examples/3d/parallax_mapping.rs b/examples/3d/parallax_mapping.rs index 37098494ee2eb..91669edbc632d 100644 --- a/examples/3d/parallax_mapping.rs +++ b/examples/3d/parallax_mapping.rs @@ -225,7 +225,7 @@ fn setup( .spawn(PointLightBundle { transform: Transform::from_xyz(1.8, 0.7, -1.1), point_light: PointLight { - intensity: 226.0, + intensity: 50_000.0, shadows_enabled: true, ..default() }, diff --git a/examples/3d/parenting.rs b/examples/3d/parenting.rs index 827d8ffbec782..202fdeffeffc8 100644 --- a/examples/3d/parenting.rs +++ b/examples/3d/parenting.rs @@ -57,6 +57,10 @@ fn setup( // light commands.spawn(PointLightBundle { transform: Transform::from_xyz(4.0, 5.0, -4.0), + point_light: PointLight { + intensity: 150_000.0, + ..default() + }, ..default() }); // camera diff --git a/examples/3d/pbr.rs b/examples/3d/pbr.rs index f0888d486ca6e..1195c46f9c611 100644 --- a/examples/3d/pbr.rs +++ b/examples/3d/pbr.rs @@ -61,7 +61,7 @@ fn setup( commands.spawn(PointLightBundle { transform: Transform::from_xyz(50.0, 50.0, 50.0), point_light: PointLight { - intensity: 600000., + intensity: 100_000_000., range: 100., ..default() }, @@ -138,7 +138,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: 1.0, + intensity: 150.0, }, )); } From ec1ddfb799ce93598d21eb2737d1685eab823bbb Mon Sep 17 00:00:00 2001 From: GitGhillie Date: Tue, 26 Dec 2023 11:51:43 +0100 Subject: [PATCH 26/46] Adjust some more 3d examples part 5 --- examples/3d/render_to_texture.rs | 4 ++++ examples/3d/shadow_biases.rs | 6 +++--- examples/3d/shadow_caster_receiver.rs | 6 +++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/examples/3d/render_to_texture.rs b/examples/3d/render_to_texture.rs index a319e7d6e4e03..62d7495b47a6b 100644 --- a/examples/3d/render_to_texture.rs +++ b/examples/3d/render_to_texture.rs @@ -93,6 +93,10 @@ fn setup( 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(), diff --git a/examples/3d/shadow_biases.rs b/examples/3d/shadow_biases.rs index 8900b75517f55..aa5acb1e87009 100644 --- a/examples/3d/shadow_biases.rs +++ b/examples/3d/shadow_biases.rs @@ -72,7 +72,7 @@ fn setup( }); builder.spawn(DirectionalLightBundle { directional_light: DirectionalLight { - illuminance: 100000.0, + illuminance: 1500.0, shadow_depth_bias: 0.0, shadow_normal_bias: 0.0, shadows_enabled: true, @@ -196,7 +196,7 @@ fn toggle_light( for mut light in &mut point_lights { light.intensity = if light.intensity == 0.0 { example_text.single_mut().sections[5].value = "PointLight".to_string(); - 100000000.0 + 500_000.0 } else { 0.0 }; @@ -204,7 +204,7 @@ fn toggle_light( for mut light in &mut directional_lights { light.illuminance = if light.illuminance == 0.0 { example_text.single_mut().sections[5].value = "DirectionalLight".to_string(); - 100000.0 + 1500.0 } else { 0.0 }; diff --git a/examples/3d/shadow_caster_receiver.rs b/examples/3d/shadow_caster_receiver.rs index b94144d8dfab4..9b88ef3ce730d 100644 --- a/examples/3d/shadow_caster_receiver.rs +++ b/examples/3d/shadow_caster_receiver.rs @@ -98,7 +98,7 @@ fn setup( commands.spawn(DirectionalLightBundle { directional_light: DirectionalLight { - illuminance: 100000.0, + illuminance: 1500.0, shadows_enabled: true, ..default() }, @@ -134,7 +134,7 @@ fn toggle_light( for mut light in &mut point_lights { light.intensity = if light.intensity == 0.0 { println!("Using PointLight"); - 100000000.0 + 500_000.0 } else { 0.0 }; @@ -142,7 +142,7 @@ fn toggle_light( for mut light in &mut directional_lights { light.illuminance = if light.illuminance == 0.0 { println!("Using DirectionalLight"); - 100000.0 + 1500.0 } else { 0.0 }; From a7e0831710a3a36f23a7396a18ce96cd3ccebc2a Mon Sep 17 00:00:00 2001 From: GitGhillie Date: Tue, 26 Dec 2023 18:31:15 +0100 Subject: [PATCH 27/46] Adjust some more 3d examples part 6 --- examples/3d/spherical_area_lights.rs | 10 +++++----- examples/3d/split_screen.rs | 1 + examples/3d/spotlight.rs | 8 ++++---- examples/3d/ssao.rs | 3 ++- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/examples/3d/spherical_area_lights.rs b/examples/3d/spherical_area_lights.rs index 99dfc14d09eeb..612c658831d9c 100644 --- a/examples/3d/spherical_area_lights.rs +++ b/examples/3d/spherical_area_lights.rs @@ -16,7 +16,7 @@ fn setup( ) { // camera commands.spawn(Camera3dBundle { - transform: Transform::from_xyz(1.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), + transform: Transform::from_xyz(0.2, 1.5, 2.5).looking_at(Vec3::ZERO, Vec3::Y), ..default() }); @@ -32,8 +32,8 @@ fn setup( }); const COUNT: usize = 6; - let position_range = -4.0..4.0; - let radius_range = 0.0..0.8; + let position_range = -2.0..2.0; + let radius_range = 0.0..0.4; let pos_len = position_range.end - position_range.start; let radius_len = radius_range.end - radius_range.start; let mesh = meshes.add(Mesh::from(shape::UVSphere { @@ -55,14 +55,14 @@ fn setup( unlit: true, ..default() }), - transform: Transform::from_xyz(position_range.start + percent * pos_len, 0.6, 0.0) + transform: Transform::from_xyz(position_range.start + percent * pos_len, 0.3, 0.0) .with_scale(Vec3::splat(radius)), ..default() }) .with_children(|children| { children.spawn(PointLightBundle { point_light: PointLight { - intensity: 1500.0, + intensity: 100_000.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 1a0f215d6464f..282e5c83335ec 100644 --- a/examples/3d/split_screen.rs +++ b/examples/3d/split_screen.rs @@ -38,6 +38,7 @@ 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 db1ba40172817..d7706fe7b1c26 100644 --- a/examples/3d/spotlight.rs +++ b/examples/3d/spotlight.rs @@ -10,7 +10,7 @@ use rand::{rngs::StdRng, Rng, SeedableRng}; fn main() { App::new() .insert_resource(AmbientLight { - brightness: 0.02, + brightness: 4.0, ..default() }) .add_plugins(( @@ -69,12 +69,12 @@ fn setup( })); let red_emissive = materials.add(StandardMaterial { base_color: Color::RED, - emissive: Color::rgba_linear(1.0, 0.0, 0.0, 0.0), + emissive: Color::rgba_linear(100.0, 0.0, 0.0, 0.0), ..default() }); let maroon_emissive = materials.add(StandardMaterial { base_color: Color::MAROON, - emissive: Color::rgba_linear(0.369, 0.0, 0.0, 0.0), + emissive: Color::rgba_linear(50.0, 0.0, 0.0, 0.0), ..default() }); for x in 0..4 { @@ -87,7 +87,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: 200.0, // lumens + intensity: 100_000.0, // lumens color: Color::WHITE, shadows_enabled: true, inner_angle: PI / 4.0 * 0.85, diff --git a/examples/3d/ssao.rs b/examples/3d/ssao.rs index 61e1ef31953d7..d5aff0dbd651c 100644 --- a/examples/3d/ssao.rs +++ b/examples/3d/ssao.rs @@ -14,7 +14,7 @@ use std::f32::consts::PI; fn main() { App::new() .insert_resource(AmbientLight { - brightness: 5.0, + brightness: 750.0, ..default() }) .add_plugins((DefaultPlugins, TemporalAntiAliasPlugin)) @@ -85,6 +85,7 @@ fn setup( commands.spawn(DirectionalLightBundle { directional_light: DirectionalLight { + illuminance: 3000.0, shadows_enabled: true, ..default() }, From e969d5e6eb8eb3dff32450fd9d6ceb453c4ba16a Mon Sep 17 00:00:00 2001 From: Marco Buono Date: Fri, 29 Dec 2023 00:25:57 -0300 Subject: [PATCH 28/46] Compensate for exposure after fetching transmission background color --- crates/bevy_pbr/src/render/pbr_transmission.wgsl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/bevy_pbr/src/render/pbr_transmission.wgsl b/crates/bevy_pbr/src/render/pbr_transmission.wgsl index f13e09920d4d7..65f84c86bbcab 100644 --- a/crates/bevy_pbr/src/render/pbr_transmission.wgsl +++ b/crates/bevy_pbr/src/render/pbr_transmission.wgsl @@ -42,6 +42,9 @@ fn specular_transmissive_light(world_position: vec4, frag_coord: vec3, background_color = fetch_transmissive_background(offset_position, frag_coord, view_z, perceptual_roughness); } + // Compensate for exposure, since the background color is coming from an already exposure-adjusted texture + background_color = vec4(background_color.rgb / view_bindings::view.exposure, background_color.a); + // Dot product of the refracted direction with the exit normal (Note: We assume the exit normal is the entry normal but inverted) let MinusNdotT = dot(-N, T); From f743dcec8592fffe20b7c6e0c157665ea481ad27 Mon Sep 17 00:00:00 2001 From: Marco Buono Date: Fri, 29 Dec 2023 00:28:12 -0300 Subject: [PATCH 29/46] Adjust transmission example --- examples/3d/transmission.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/3d/transmission.rs b/examples/3d/transmission.rs index 591e4e7bc4311..cc611d8991025 100644 --- a/examples/3d/transmission.rs +++ b/examples/3d/transmission.rs @@ -328,7 +328,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: 1600.0, + intensity: 240_000.0, radius: 0.2, range: 5.0, shadows_enabled: true, @@ -358,6 +358,7 @@ fn setup( #[cfg(not(all(feature = "webgl2", target_arch = "wasm32")))] TemporalAntiAliasBundle::default(), EnvironmentMapLight { + intensity: 100.0, diffuse_map: asset_server.load("environment_maps/pisa_diffuse_rgb9e5_zstd.ktx2"), specular_map: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"), }, @@ -651,7 +652,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 = 1600.0 + 3000.0 * (a + b + c); + light.intensity = 240_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)); From 874ea8cfd6895e038117a2e4aa3ad5db7f091612 Mon Sep 17 00:00:00 2001 From: Marco Buono Date: Fri, 29 Dec 2023 00:31:19 -0300 Subject: [PATCH 30/46] Remove `ColorGrading` exposure as a workaround for `EnvironmentMapLight` intensity --- examples/3d/transmission.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/3d/transmission.rs b/examples/3d/transmission.rs index cc611d8991025..8f36f09257ecf 100644 --- a/examples/3d/transmission.rs +++ b/examples/3d/transmission.rs @@ -328,7 +328,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: 240_000.0, + intensity: 60_000.0, radius: 0.2, range: 5.0, shadows_enabled: true, @@ -348,7 +348,6 @@ fn setup( }, transform: Transform::from_xyz(1.0, 1.8, 7.0).looking_at(Vec3::ZERO, Vec3::Y), color_grading: ColorGrading { - exposure: -2.0, post_saturation: 1.2, ..default() }, @@ -358,7 +357,7 @@ fn setup( #[cfg(not(all(feature = "webgl2", target_arch = "wasm32")))] TemporalAntiAliasBundle::default(), EnvironmentMapLight { - intensity: 100.0, + intensity: 25.0, diffuse_map: asset_server.load("environment_maps/pisa_diffuse_rgb9e5_zstd.ktx2"), specular_map: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"), }, @@ -652,7 +651,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 = 240_000.0 + 3000.0 * (a + b + c); + light.intensity = 60_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)); From 0d4006e8d9800f66a46a100995806ebaf9f52159 Mon Sep 17 00:00:00 2001 From: Marco Buono Date: Fri, 29 Dec 2023 00:38:33 -0300 Subject: [PATCH 31/46] Also tweak look of emissive flame in transmission example --- examples/3d/transmission.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/3d/transmission.rs b/examples/3d/transmission.rs index 8f36f09257ecf..05f6f2640d2eb 100644 --- a/examples/3d/transmission.rs +++ b/examples/3d/transmission.rs @@ -156,7 +156,7 @@ fn setup( PbrBundle { mesh: icosphere_mesh.clone(), material: materials.add(StandardMaterial { - emissive: Color::ANTIQUE_WHITE * 20.0 + Color::ORANGE_RED * 4.0, + emissive: Color::ANTIQUE_WHITE * 80.0 + Color::ORANGE_RED * 16.0, diffuse_transmission: 1.0, ..default() }), From edfb7214e7a1222c948632f98cf74a9f3a9147ee Mon Sep 17 00:00:00 2001 From: GitGhillie Date: Sat, 30 Dec 2023 22:04:22 +0100 Subject: [PATCH 32/46] Adjust some more 3d examples part 7 --- examples/3d/tonemapping.rs | 4 ++-- examples/3d/transparency_3d.rs | 2 +- examples/3d/two_passes.rs | 2 +- examples/3d/update_gltf_scene.rs | 2 ++ examples/3d/vertex_colors.rs | 2 +- examples/3d/wireframe.rs | 4 ++++ examples/animation/animated_fox.rs | 3 ++- examples/animation/animated_transform.rs | 2 +- examples/animation/cubic_curve.rs | 2 +- examples/animation/custom_skinned_mesh.rs | 2 +- examples/animation/gltf_skinned_mesh.rs | 2 +- examples/animation/morph_targets.rs | 4 ++-- 12 files changed, 19 insertions(+), 12 deletions(-) diff --git a/examples/3d/tonemapping.rs b/examples/3d/tonemapping.rs index 95601e7e26f5f..80cc1f3f602a4 100644 --- a/examples/3d/tonemapping.rs +++ b/examples/3d/tonemapping.rs @@ -75,7 +75,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: 1.0, + intensity: 150.0, }, )); @@ -194,7 +194,7 @@ fn setup_basic_scene( DirectionalLightBundle { directional_light: DirectionalLight { shadows_enabled: true, - illuminance: 50000.0, + illuminance: 3000.0, ..default() }, transform: Transform::from_rotation(Quat::from_euler( diff --git a/examples/3d/transparency_3d.rs b/examples/3d/transparency_3d.rs index f048f959423d2..5b2f3a7e99a0b 100644 --- a/examples/3d/transparency_3d.rs +++ b/examples/3d/transparency_3d.rs @@ -91,7 +91,7 @@ fn setup( // light commands.spawn(PointLightBundle { point_light: PointLight { - intensity: 1500.0, + intensity: 1_000_000.0, shadows_enabled: true, ..default() }, diff --git a/examples/3d/two_passes.rs b/examples/3d/two_passes.rs index eded9674964da..b33739d716fb8 100644 --- a/examples/3d/two_passes.rs +++ b/examples/3d/two_passes.rs @@ -31,7 +31,7 @@ fn setup( // light commands.spawn(PointLightBundle { point_light: PointLight { - intensity: 1500.0, + intensity: 500_000.0, shadows_enabled: true, ..default() }, diff --git a/examples/3d/update_gltf_scene.rs b/examples/3d/update_gltf_scene.rs index 27b9edb9b0f66..84578cbefa4af 100644 --- a/examples/3d/update_gltf_scene.rs +++ b/examples/3d/update_gltf_scene.rs @@ -19,6 +19,7 @@ fn setup(mut commands: Commands, asset_server: Res) { commands.spawn(DirectionalLightBundle { transform: Transform::from_xyz(4.0, 25.0, 8.0).looking_at(Vec3::ZERO, Vec3::Y), directional_light: DirectionalLight { + illuminance: 2000.0, shadows_enabled: true, ..default() }, @@ -33,6 +34,7 @@ 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, }, )); diff --git a/examples/3d/vertex_colors.rs b/examples/3d/vertex_colors.rs index 93d05882b76d5..ca89bdce1b832 100644 --- a/examples/3d/vertex_colors.rs +++ b/examples/3d/vertex_colors.rs @@ -45,7 +45,7 @@ fn setup( // light commands.spawn(PointLightBundle { point_light: PointLight { - intensity: 1500.0, + intensity: 500_000.0, shadows_enabled: true, ..default() }, diff --git a/examples/3d/wireframe.rs b/examples/3d/wireframe.rs index 058ba18f6c108..a2f6acb48e84f 100644 --- a/examples/3d/wireframe.rs +++ b/examples/3d/wireframe.rs @@ -95,6 +95,10 @@ fn setup( // light commands.spawn(PointLightBundle { transform: Transform::from_xyz(4.0, 8.0, 4.0), + point_light: PointLight { + intensity: 150_000.0, + ..default() + }, ..default() }); diff --git a/examples/animation/animated_fox.rs b/examples/animation/animated_fox.rs index cf695d81aa1f6..5506a78aa0ae6 100644 --- a/examples/animation/animated_fox.rs +++ b/examples/animation/animated_fox.rs @@ -10,7 +10,7 @@ fn main() { .add_plugins(DefaultPlugins) .insert_resource(AmbientLight { color: Color::WHITE, - brightness: 1.0, + brightness: 150.0, }) .add_systems(Startup, setup) .add_systems( @@ -54,6 +54,7 @@ fn setup( commands.spawn(DirectionalLightBundle { transform: Transform::from_rotation(Quat::from_euler(EulerRot::ZYX, 0.0, 1.0, -PI / 4.)), directional_light: DirectionalLight { + illuminance: 2000.0, shadows_enabled: true, ..default() }, diff --git a/examples/animation/animated_transform.rs b/examples/animation/animated_transform.rs index 0a3aa023986c6..60a9777205956 100644 --- a/examples/animation/animated_transform.rs +++ b/examples/animation/animated_transform.rs @@ -9,7 +9,7 @@ fn main() { .add_plugins(DefaultPlugins) .insert_resource(AmbientLight { color: Color::WHITE, - brightness: 1.0, + brightness: 150.0, }) .add_systems(Startup, setup) .run(); diff --git a/examples/animation/cubic_curve.rs b/examples/animation/cubic_curve.rs index 92a003edaa723..642fb66c079a9 100644 --- a/examples/animation/cubic_curve.rs +++ b/examples/animation/cubic_curve.rs @@ -49,7 +49,7 @@ fn setup( // Some light to see something commands.spawn(PointLightBundle { point_light: PointLight { - intensity: 9000., + intensity: 1_500_000., range: 100., shadows_enabled: true, ..default() diff --git a/examples/animation/custom_skinned_mesh.rs b/examples/animation/custom_skinned_mesh.rs index 7f349e2846100..38b0b61646092 100644 --- a/examples/animation/custom_skinned_mesh.rs +++ b/examples/animation/custom_skinned_mesh.rs @@ -17,7 +17,7 @@ fn main() { App::new() .add_plugins(DefaultPlugins) .insert_resource(AmbientLight { - brightness: 1.0, + brightness: 150.0, ..default() }) .add_systems(Startup, setup) diff --git a/examples/animation/gltf_skinned_mesh.rs b/examples/animation/gltf_skinned_mesh.rs index 8183a91349372..81f80c1e04a01 100644 --- a/examples/animation/gltf_skinned_mesh.rs +++ b/examples/animation/gltf_skinned_mesh.rs @@ -9,7 +9,7 @@ fn main() { App::new() .add_plugins(DefaultPlugins) .insert_resource(AmbientLight { - brightness: 1.0, + brightness: 150.0, ..default() }) .add_systems(Startup, setup) diff --git a/examples/animation/morph_targets.rs b/examples/animation/morph_targets.rs index 960cb0866baa8..282a68d0e10ab 100644 --- a/examples/animation/morph_targets.rs +++ b/examples/animation/morph_targets.rs @@ -20,7 +20,7 @@ fn main() { ..default() })) .insert_resource(AmbientLight { - brightness: 1.0, + brightness: 150.0, ..default() }) .add_systems(Startup, setup) @@ -46,7 +46,7 @@ fn setup(asset_server: Res, mut commands: Commands) { commands.spawn(DirectionalLightBundle { directional_light: DirectionalLight { color: Color::WHITE, - illuminance: 19350.0, + illuminance: 1000.0, ..default() }, transform: Transform::from_rotation(Quat::from_rotation_z(PI / 2.0)), From 5f92b4478e6784d71661058a927e9d804bf81a60 Mon Sep 17 00:00:00 2001 From: GitGhillie Date: Thu, 4 Jan 2024 14:05:21 +0100 Subject: [PATCH 33/46] Adjust some more 3d examples part 8 --- examples/audio/spatial_audio_3d.rs | 2 +- examples/ecs/iter_combinations.rs | 4 ++-- examples/games/alien_cake_addict.rs | 4 ++-- examples/mobile/src/lib.rs | 2 +- examples/stress_tests/many_foxes.rs | 5 +++-- examples/stress_tests/many_lights.rs | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/examples/audio/spatial_audio_3d.rs b/examples/audio/spatial_audio_3d.rs index 22a2537468685..3901c6cd757d8 100644 --- a/examples/audio/spatial_audio_3d.rs +++ b/examples/audio/spatial_audio_3d.rs @@ -61,7 +61,7 @@ fn setup( // light commands.spawn(PointLightBundle { point_light: PointLight { - intensity: 1500.0, + intensity: 1_000_000.0, shadows_enabled: true, ..default() }, diff --git a/examples/ecs/iter_combinations.rs b/examples/ecs/iter_combinations.rs index 363dfc726c768..11a96b8a8ee10 100644 --- a/examples/ecs/iter_combinations.rs +++ b/examples/ecs/iter_combinations.rs @@ -115,7 +115,7 @@ fn generate_bodies( ), material: materials.add(StandardMaterial { base_color: Color::ORANGE_RED, - emissive: (Color::ORANGE_RED * 2.), + emissive: (Color::ORANGE_RED * 18.), ..default() }), ..default() @@ -129,7 +129,7 @@ fn generate_bodies( p.spawn(PointLightBundle { point_light: PointLight { color: Color::WHITE, - intensity: 400.0, + intensity: 100_000.0, range: 100.0, radius: star_radius, ..default() diff --git a/examples/games/alien_cake_addict.rs b/examples/games/alien_cake_addict.rs index ee66a39120ca1..6c057af380f07 100644 --- a/examples/games/alien_cake_addict.rs +++ b/examples/games/alien_cake_addict.rs @@ -115,7 +115,7 @@ fn setup(mut commands: Commands, asset_server: Res, mut game: ResMu commands.spawn(PointLightBundle { transform: Transform::from_xyz(4.0, 10.0, 4.0), point_light: PointLight { - intensity: 3000.0, + intensity: 500_000.0, shadows_enabled: true, range: 30.0, ..default() @@ -344,7 +344,7 @@ fn spawn_bonus( children.spawn(PointLightBundle { point_light: PointLight { color: Color::rgb(1.0, 1.0, 0.0), - intensity: 1000.0, + intensity: 100_000.0, range: 10.0, ..default() }, diff --git a/examples/mobile/src/lib.rs b/examples/mobile/src/lib.rs index d0ce7c2f9bcd2..ed6a12c1045e2 100644 --- a/examples/mobile/src/lib.rs +++ b/examples/mobile/src/lib.rs @@ -90,7 +90,7 @@ fn setup_scene( commands.spawn(PointLightBundle { transform: Transform::from_xyz(4.0, 8.0, 4.0), point_light: PointLight { - intensity: 5000.0, + intensity: 1_000_000.0, // Shadows makes some Android devices segfault, this is under investigation // https://github.com/bevyengine/bevy/issues/8214 #[cfg(not(target_os = "android"))] diff --git a/examples/stress_tests/many_foxes.rs b/examples/stress_tests/many_foxes.rs index 896b601e4cd5b..0e14b6e8b1920 100644 --- a/examples/stress_tests/many_foxes.rs +++ b/examples/stress_tests/many_foxes.rs @@ -15,7 +15,7 @@ use bevy::{ #[derive(FromArgs, Resource)] /// `many_foxes` stress test struct Args { - /// wether all foxes run in sync. + /// whether all foxes run in sync. #[argh(switch)] sync: bool, @@ -58,7 +58,7 @@ fn main() { }) .insert_resource(AmbientLight { color: Color::WHITE, - brightness: 1.0, + brightness: 100.0, }) .add_systems(Startup, setup) .add_systems( @@ -194,6 +194,7 @@ fn setup( commands.spawn(DirectionalLightBundle { transform: Transform::from_rotation(Quat::from_euler(EulerRot::ZYX, 0.0, 1.0, -PI / 4.)), directional_light: DirectionalLight { + illuminance: 3000.0, shadows_enabled: true, ..default() }, diff --git a/examples/stress_tests/many_lights.rs b/examples/stress_tests/many_lights.rs index c36a04920c792..fb6cebd1ba7d7 100644 --- a/examples/stress_tests/many_lights.rs +++ b/examples/stress_tests/many_lights.rs @@ -43,7 +43,7 @@ fn setup( warn!(include_str!("warning_string.txt")); const LIGHT_RADIUS: f32 = 0.3; - const LIGHT_INTENSITY: f32 = 5.0; + const LIGHT_INTENSITY: f32 = 1000.0; const RADIUS: f32 = 50.0; const N_LIGHTS: usize = 100_000; From 996817328203bfdf068211e00a361d5d680cb566 Mon Sep 17 00:00:00 2001 From: GitGhillie Date: Thu, 4 Jan 2024 15:31:00 +0100 Subject: [PATCH 34/46] Adjust some more 3d examples part 9 (fin) --- examples/3d/3d_scene.rs | 2 +- examples/3d/blend_modes.rs | 4 ++++ examples/shader/array_texture.rs | 4 ++-- examples/shader/extended_material.rs | 8 +++++++- examples/shader/post_processing.rs | 4 ++++ examples/shader/shader_material_screenspace_texture.rs | 4 ++++ examples/shader/shader_prepass.rs | 2 +- examples/stress_tests/many_lights.rs | 2 +- examples/tools/scene_viewer/main.rs | 9 +++------ examples/transforms/3d_rotation.rs | 4 ++++ examples/transforms/scale.rs | 4 ++++ examples/transforms/transform.rs | 4 ++++ examples/transforms/translation.rs | 4 ++++ examples/window/low_power.rs | 2 +- examples/window/multiple_windows.rs | 4 ++++ examples/window/screenshot.rs | 2 +- 16 files changed, 49 insertions(+), 14 deletions(-) diff --git a/examples/3d/3d_scene.rs b/examples/3d/3d_scene.rs index 6780ba13de67e..bca53966525ae 100644 --- a/examples/3d/3d_scene.rs +++ b/examples/3d/3d_scene.rs @@ -32,7 +32,7 @@ fn setup( // light commands.spawn(PointLightBundle { point_light: PointLight { - intensity: 250000.0, + intensity: 250_000.0, shadows_enabled: true, ..default() }, diff --git a/examples/3d/blend_modes.rs b/examples/3d/blend_modes.rs index d378a713ec82e..f5c0c9a334df3 100644 --- a/examples/3d/blend_modes.rs +++ b/examples/3d/blend_modes.rs @@ -174,6 +174,10 @@ fn setup( // Light commands.spawn(PointLightBundle { + point_light: PointLight { + intensity: 150_000.0, + ..default() + }, transform: Transform::from_xyz(4.0, 8.0, 4.0), ..default() }); diff --git a/examples/shader/array_texture.rs b/examples/shader/array_texture.rs index 478119cfa9c57..4d64dbf5e257d 100644 --- a/examples/shader/array_texture.rs +++ b/examples/shader/array_texture.rs @@ -34,7 +34,7 @@ fn setup(mut commands: Commands, asset_server: Res) { // light commands.spawn(PointLightBundle { point_light: PointLight { - intensity: 3000.0, + intensity: 150_000.0, ..Default::default() }, transform: Transform::from_xyz(-3.0, 2.0, -1.0), @@ -42,7 +42,7 @@ fn setup(mut commands: Commands, asset_server: Res) { }); commands.spawn(PointLightBundle { point_light: PointLight { - intensity: 3000.0, + intensity: 150_000.0, ..Default::default() }, transform: Transform::from_xyz(3.0, 2.0, 1.0), diff --git a/examples/shader/extended_material.rs b/examples/shader/extended_material.rs index 7f055a9bef860..c6080aa276229 100644 --- a/examples/shader/extended_material.rs +++ b/examples/shader/extended_material.rs @@ -50,7 +50,13 @@ fn setup( }); // light - commands.spawn((PointLightBundle::default(), Rotate)); + commands.spawn((PointLightBundle { + point_light: PointLight { + intensity: 150_000.0, + ..default() + }, + ..default() + }, Rotate)); // camera commands.spawn(Camera3dBundle { diff --git a/examples/shader/post_processing.rs b/examples/shader/post_processing.rs index ad684675d806b..1b548b82a3ab9 100644 --- a/examples/shader/post_processing.rs +++ b/examples/shader/post_processing.rs @@ -331,6 +331,10 @@ fn setup( )); // light commands.spawn(PointLightBundle { + point_light: PointLight { + intensity: 150_000.0, + ..default() + }, transform: Transform::from_translation(Vec3::new(0.0, 0.0, 10.0)), ..default() }); diff --git a/examples/shader/shader_material_screenspace_texture.rs b/examples/shader/shader_material_screenspace_texture.rs index ddee9a68097e0..d854fcbd7fd4a 100644 --- a/examples/shader/shader_material_screenspace_texture.rs +++ b/examples/shader/shader_material_screenspace_texture.rs @@ -30,6 +30,10 @@ fn setup( ..default() }); commands.spawn(PointLightBundle { + point_light: PointLight { + intensity: 150_000.0, + ..default() + }, transform: Transform::from_xyz(4.0, 8.0, 4.0), ..default() }); diff --git a/examples/shader/shader_prepass.rs b/examples/shader/shader_prepass.rs index de17d4341fcfd..bf3d2adba784e 100644 --- a/examples/shader/shader_prepass.rs +++ b/examples/shader/shader_prepass.rs @@ -125,7 +125,7 @@ fn setup( // light commands.spawn(PointLightBundle { point_light: PointLight { - intensity: 1500.0, + intensity: 300_000.0, shadows_enabled: true, ..default() }, diff --git a/examples/stress_tests/many_lights.rs b/examples/stress_tests/many_lights.rs index fb6cebd1ba7d7..c36a04920c792 100644 --- a/examples/stress_tests/many_lights.rs +++ b/examples/stress_tests/many_lights.rs @@ -43,7 +43,7 @@ fn setup( warn!(include_str!("warning_string.txt")); const LIGHT_RADIUS: f32 = 0.3; - const LIGHT_INTENSITY: f32 = 1000.0; + const LIGHT_INTENSITY: f32 = 5.0; const RADIUS: f32 = 50.0; const N_LIGHTS: usize = 100_000; diff --git a/examples/tools/scene_viewer/main.rs b/examples/tools/scene_viewer/main.rs index 30cef1d57a83e..1abfa68545d85 100644 --- a/examples/tools/scene_viewer/main.rs +++ b/examples/tools/scene_viewer/main.rs @@ -26,11 +26,7 @@ use scene_viewer_plugin::{SceneHandle, SceneViewerPlugin}; fn main() { let mut app = App::new(); - app.insert_resource(AmbientLight { - color: Color::WHITE, - brightness: 1.0 / 5.0f32, - }) - .add_plugins(( + app.add_plugins(( DefaultPlugins .set(WindowPlugin { primary_window: Some(Window { @@ -142,7 +138,7 @@ fn setup_scene_after_load( .load("assets/environment_maps/pisa_diffuse_rgb9e5_zstd.ktx2"), specular_map: asset_server .load("assets/environment_maps/pisa_specular_rgb9e5_zstd.ktx2"), - intensity: 1.0, + intensity: 150.0, }, camera_controller, )); @@ -152,6 +148,7 @@ fn setup_scene_after_load( info!("Spawning a directional light"); commands.spawn(DirectionalLightBundle { directional_light: DirectionalLight { + illuminance: 3000.0, shadows_enabled: false, ..default() }, diff --git a/examples/transforms/3d_rotation.rs b/examples/transforms/3d_rotation.rs index ddedbbae859e9..82157c4f6a432 100644 --- a/examples/transforms/3d_rotation.rs +++ b/examples/transforms/3d_rotation.rs @@ -42,6 +42,10 @@ fn setup( // Add a light source so we can see clearly. commands.spawn(PointLightBundle { + point_light: PointLight { + intensity: 150_000.0, + ..default() + }, transform: Transform::from_translation(Vec3::ONE * 3.0), ..default() }); diff --git a/examples/transforms/scale.rs b/examples/transforms/scale.rs index bbae8b71b9be2..3728b984d06f2 100644 --- a/examples/transforms/scale.rs +++ b/examples/transforms/scale.rs @@ -58,6 +58,10 @@ fn setup( // Add a light source for better 3d visibility. commands.spawn(PointLightBundle { + point_light: PointLight { + intensity: 150_000.0, + ..default() + }, transform: Transform::from_translation(Vec3::ONE * 3.0), ..default() }); diff --git a/examples/transforms/transform.rs b/examples/transforms/transform.rs index 38bad31c4fa30..42c3048e68339 100644 --- a/examples/transforms/transform.rs +++ b/examples/transforms/transform.rs @@ -93,6 +93,10 @@ fn setup( // Add a light source for better 3d visibility. commands.spawn(PointLightBundle { + point_light: PointLight { + intensity: 150_000.0, + ..default() + }, transform: Transform::from_translation(Vec3::ONE * 3.0), ..default() }); diff --git a/examples/transforms/translation.rs b/examples/transforms/translation.rs index e8aaef4edfdd3..be7937fad34df 100644 --- a/examples/transforms/translation.rs +++ b/examples/transforms/translation.rs @@ -56,6 +56,10 @@ fn setup( // Add a light source for better 3d visibility. commands.spawn(PointLightBundle { + point_light: PointLight { + intensity: 150_000.0, + ..default() + }, transform: Transform::from_translation(Vec3::ONE * 3.0), ..default() }); diff --git a/examples/window/low_power.rs b/examples/window/low_power.rs index 8a1af9af3b2a4..2009501af6a10 100644 --- a/examples/window/low_power.rs +++ b/examples/window/low_power.rs @@ -159,7 +159,7 @@ pub(crate) mod test_setup { )); commands.spawn(PointLightBundle { point_light: PointLight { - intensity: 1500.0, + intensity: 1_000_000.0, shadows_enabled: true, ..default() }, diff --git a/examples/window/multiple_windows.rs b/examples/window/multiple_windows.rs index 8905d76ca9c6a..7d8e5ba2f2471 100644 --- a/examples/window/multiple_windows.rs +++ b/examples/window/multiple_windows.rs @@ -19,6 +19,10 @@ fn setup_scene(mut commands: Commands, asset_server: Res) { }); // light commands.spawn(PointLightBundle { + point_light: PointLight { + intensity: 150_000.0, + ..default() + }, transform: Transform::from_xyz(4.0, 5.0, 4.0), ..default() }); diff --git a/examples/window/screenshot.rs b/examples/window/screenshot.rs index 8ebfdaba5efec..2e3b37361bda2 100644 --- a/examples/window/screenshot.rs +++ b/examples/window/screenshot.rs @@ -49,7 +49,7 @@ fn setup( // light commands.spawn(PointLightBundle { point_light: PointLight { - intensity: 1500.0, + intensity: 500_000.0, shadows_enabled: true, ..default() }, From bbd65326cac26b5f2fcf1389c8984efa44c16619 Mon Sep 17 00:00:00 2001 From: GitGhillie Date: Thu, 4 Jan 2024 15:31:33 +0100 Subject: [PATCH 35/46] fmt --- examples/shader/extended_material.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/shader/extended_material.rs b/examples/shader/extended_material.rs index c6080aa276229..a4422faad4307 100644 --- a/examples/shader/extended_material.rs +++ b/examples/shader/extended_material.rs @@ -50,13 +50,16 @@ fn setup( }); // light - commands.spawn((PointLightBundle { - point_light: PointLight { - intensity: 150_000.0, + commands.spawn(( + PointLightBundle { + point_light: PointLight { + intensity: 150_000.0, + ..default() + }, ..default() }, - ..default() - }, Rotate)); + Rotate, + )); // camera commands.spawn(Camera3dBundle { From a6d9076a1565eddc02d6efbd7ecc6901f3df5dc7 Mon Sep 17 00:00:00 2001 From: Marco Buono Date: Sat, 6 Jan 2024 01:00:50 -0300 Subject: [PATCH 36/46] Take exposure into account for directional light influence in fog --- crates/bevy_pbr/src/render/pbr_functions.wgsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_pbr/src/render/pbr_functions.wgsl b/crates/bevy_pbr/src/render/pbr_functions.wgsl index 1ce98bb0604ba..474cce572500b 100644 --- a/crates/bevy_pbr/src/render/pbr_functions.wgsl +++ b/crates/bevy_pbr/src/render/pbr_functions.wgsl @@ -418,7 +418,7 @@ fn apply_fog(fog_params: mesh_view_types::Fog, input_color: vec4, fragment_ 0.0 ), fog_params.directional_light_exponent - ) * light.color.rgb; + ) * light.color.rgb * view_bindings::view.exposure; } } From e00f0ad252931f3c27030df173b680fc2a98ee50 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Sun, 14 Jan 2024 15:04:00 -0800 Subject: [PATCH 37/46] Fix doc --- crates/bevy_render/src/camera/camera.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index dee1a4bcf5deb..107312d42121d 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -83,7 +83,7 @@ pub struct ComputedCameraValues { old_viewport_size: Option, } -/// How much energy a [`Camera3d`] absorbs from incoming light. +/// How much energy a `Camera3d` absorbs from incoming light. /// /// #[derive(Component)] From 5cd197b83a211a85174d34c66a601ed28214e106 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Sun, 14 Jan 2024 15:09:03 -0800 Subject: [PATCH 38/46] Fix example keycodes --- examples/3d/lighting.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/3d/lighting.rs b/examples/3d/lighting.rs index 8bd56f3cf253e..9e68a4012c0d2 100644 --- a/examples/3d/lighting.rs +++ b/examples/3d/lighting.rs @@ -298,22 +298,22 @@ fn update_exposure( ) { // TODO: Clamp values to a reasonable range let mut text = text.single_mut(); - if key_input.just_pressed(KeyCode::Key2) { + if key_input.just_pressed(KeyCode::Digit2) { parameters.aperture_f_stops *= 2.0; - } else if key_input.just_pressed(KeyCode::Key1) { + } else if key_input.just_pressed(KeyCode::Digit1) { parameters.aperture_f_stops *= 0.5; } - if key_input.just_pressed(KeyCode::Key4) { + if key_input.just_pressed(KeyCode::Digit4) { parameters.shutter_speed_s *= 2.0; - } else if key_input.just_pressed(KeyCode::Key3) { + } else if key_input.just_pressed(KeyCode::Digit3) { parameters.shutter_speed_s *= 0.5; } - if key_input.just_pressed(KeyCode::Key6) { + if key_input.just_pressed(KeyCode::Digit6) { parameters.sensitivity_iso += 100.0; - } else if key_input.just_pressed(KeyCode::Key5) { + } else if key_input.just_pressed(KeyCode::Digit5) { parameters.sensitivity_iso -= 100.0; } - if key_input.just_pressed(KeyCode::R) { + if key_input.just_pressed(KeyCode::KeyR) { *parameters = Parameters::default(); } From d892d5dcdbf335ae08fecb0ca4989083965ab2f5 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Sun, 14 Jan 2024 15:42:41 -0800 Subject: [PATCH 39/46] Update crates/bevy_render/src/camera/camera.rs Co-authored-by: vero --- crates/bevy_render/src/camera/camera.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index 107312d42121d..e64b254daa191 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -133,8 +133,7 @@ pub struct PhysicalCameraParameters { impl PhysicalCameraParameters { /// Calculate the [EV100](https://en.wikipedia.org/wiki/Exposure_value). pub fn ev100(&self) -> f32 { - (self.aperture_f_stops * self.aperture_f_stops / self.shutter_speed_s).log2() - - (self.sensitivity_iso / 100.0).log2() + (self.aperture_f_stops * self.aperture_f_stops * 100.0 / (self.shutter_speed_s * self.sensitivity_iso)).log2() } } From 07ccccdc8996b0cb1da0019c81280e0ef3c29a22 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Sun, 14 Jan 2024 15:44:29 -0800 Subject: [PATCH 40/46] Format --- crates/bevy_render/src/camera/camera.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index e64b254daa191..8de5c04ac338a 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -133,7 +133,9 @@ pub struct PhysicalCameraParameters { impl PhysicalCameraParameters { /// Calculate the [EV100](https://en.wikipedia.org/wiki/Exposure_value). pub fn ev100(&self) -> f32 { - (self.aperture_f_stops * self.aperture_f_stops * 100.0 / (self.shutter_speed_s * self.sensitivity_iso)).log2() + (self.aperture_f_stops * self.aperture_f_stops * 100.0 + / (self.shutter_speed_s * self.sensitivity_iso)) + .log2() } } From 24c995350fe95a590c03d48ef8801943ebeb8387 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Mon, 15 Jan 2024 10:29:38 -0800 Subject: [PATCH 41/46] Update crates/bevy_render/src/camera/camera.rs Co-authored-by: vero --- crates/bevy_render/src/camera/camera.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index 8de5c04ac338a..537b1e68bc939 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -106,7 +106,7 @@ impl ExposureSettings { /// Converts EV100 values to exposure values. #[inline] pub fn exposure(&self) -> f32 { - 1.0 / (2.0f32.powf(self.ev100) * 1.2) + (-self.ev100).exp2() / 1.2 } } From 2a52b6a9961e52a24681def498fde9e084667fce Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Mon, 15 Jan 2024 15:22:10 -0800 Subject: [PATCH 42/46] Update crates/bevy_render/src/camera/camera.rs Co-authored-by: vero --- crates/bevy_render/src/camera/camera.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index 537b1e68bc939..4061785f678dc 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -104,6 +104,7 @@ impl ExposureSettings { } /// Converts EV100 values to exposure values. + /// #[inline] pub fn exposure(&self) -> f32 { (-self.ev100).exp2() / 1.2 From fab6f879b15c0a15c4b1a56c9f771944bc5b5fc0 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Mon, 15 Jan 2024 15:56:10 -0800 Subject: [PATCH 43/46] Improve doc comment --- crates/bevy_pbr/src/environment_map/mod.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/bevy_pbr/src/environment_map/mod.rs b/crates/bevy_pbr/src/environment_map/mod.rs index c5dc8e640e89b..ecba4f84fceb8 100644 --- a/crates/bevy_pbr/src/environment_map/mod.rs +++ b/crates/bevy_pbr/src/environment_map/mod.rs @@ -51,9 +51,12 @@ impl Plugin for EnvironmentMapPlugin { pub struct EnvironmentMapLight { pub diffuse_map: Handle, pub specular_map: Handle, - /// Scale factor applied to both the diffuse and specular cubemap. - /// After applying this multiplier to the image samples, the resulting values should + /// Scale factor applied to the diffuse and specular light generated by this component. + /// + /// After applying this multiplier, the resulting values should /// be in units of [cd/m^2](https://en.wikipedia.org/wiki/Candela_per_square_metre). + /// + /// See also . pub intensity: f32, } From fd91b5882cecd0022916fe52c56dd13a3aafee20 Mon Sep 17 00:00:00 2001 From: atlas dostal Date: Mon, 15 Jan 2024 20:32:46 -0800 Subject: [PATCH 44/46] Fix lightmaps example --- examples/3d/lightmaps.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/examples/3d/lightmaps.rs b/examples/3d/lightmaps.rs index ee4f0a1bbfd54..a033493fca0e1 100644 --- a/examples/3d/lightmaps.rs +++ b/examples/3d/lightmaps.rs @@ -30,10 +30,15 @@ fn setup(mut commands: Commands, asset_server: Res) { fn add_lightmaps_to_meshes( mut commands: Commands, asset_server: Res, - meshes: Query<(Entity, &Name), (With>, Without)>, + mut materials: ResMut>, + meshes: Query< + (Entity, &Name, &Handle), + (With>, Without), + >, ) { - for (entity, name) in meshes.iter() { + for (entity, name, material) in meshes.iter() { if &**name == "large_box" { + materials.get_mut(material).unwrap().lightmap_exposure = 120.0; commands.entity(entity).insert(Lightmap { image: asset_server.load("lightmaps/CornellBox-Large.zstd.ktx2"), ..default() @@ -42,6 +47,7 @@ fn add_lightmaps_to_meshes( } if &**name == "small_box" { + materials.get_mut(material).unwrap().lightmap_exposure = 120.0; commands.entity(entity).insert(Lightmap { image: asset_server.load("lightmaps/CornellBox-Small.zstd.ktx2"), ..default() @@ -50,6 +56,7 @@ fn add_lightmaps_to_meshes( } if name.starts_with("cornell_box") { + materials.get_mut(material).unwrap().lightmap_exposure = 120.0; commands.entity(entity).insert(Lightmap { image: asset_server.load("lightmaps/CornellBox-Box.zstd.ktx2"), ..default() From e0f3e9c313324a15ebc2ed0a896e74149d4d6e8c Mon Sep 17 00:00:00 2001 From: atlas dostal Date: Mon, 15 Jan 2024 20:58:50 -0800 Subject: [PATCH 45/46] more fixing ... --- examples/3d/lightmaps.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/3d/lightmaps.rs b/examples/3d/lightmaps.rs index a033493fca0e1..8a9a448bf0c64 100644 --- a/examples/3d/lightmaps.rs +++ b/examples/3d/lightmaps.rs @@ -37,8 +37,13 @@ fn add_lightmaps_to_meshes( >, ) { for (entity, name, material) in meshes.iter() { + if &**name == "Light" { + materials.get_mut(material).unwrap().emissive = Color::WHITE * 100.0; + continue; + } + if &**name == "large_box" { - materials.get_mut(material).unwrap().lightmap_exposure = 120.0; + materials.get_mut(material).unwrap().lightmap_exposure = 150.0; commands.entity(entity).insert(Lightmap { image: asset_server.load("lightmaps/CornellBox-Large.zstd.ktx2"), ..default() @@ -47,7 +52,7 @@ fn add_lightmaps_to_meshes( } if &**name == "small_box" { - materials.get_mut(material).unwrap().lightmap_exposure = 120.0; + materials.get_mut(material).unwrap().lightmap_exposure = 150.0; commands.entity(entity).insert(Lightmap { image: asset_server.load("lightmaps/CornellBox-Small.zstd.ktx2"), ..default() @@ -56,7 +61,7 @@ fn add_lightmaps_to_meshes( } if name.starts_with("cornell_box") { - materials.get_mut(material).unwrap().lightmap_exposure = 120.0; + materials.get_mut(material).unwrap().lightmap_exposure = 150.0; commands.entity(entity).insert(Lightmap { image: asset_server.load("lightmaps/CornellBox-Box.zstd.ktx2"), ..default() From 55444b463e03b9eb4c8b50176730fcdcbbf8e640 Mon Sep 17 00:00:00 2001 From: atlas dostal Date: Mon, 15 Jan 2024 21:08:31 -0800 Subject: [PATCH 46/46] Fix fix fix --- examples/3d/lightmaps.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/3d/lightmaps.rs b/examples/3d/lightmaps.rs index 8a9a448bf0c64..7601acc86c8bd 100644 --- a/examples/3d/lightmaps.rs +++ b/examples/3d/lightmaps.rs @@ -8,7 +8,7 @@ fn main() { .add_plugins(DefaultPlugins) .insert_resource(AmbientLight { color: Color::WHITE, - brightness: 0.2, + brightness: 0.0, }) .add_systems(Startup, setup) .add_systems(Update, add_lightmaps_to_meshes) @@ -36,14 +36,15 @@ fn add_lightmaps_to_meshes( (With>, Without), >, ) { + let exposure = 250.0; for (entity, name, material) in meshes.iter() { if &**name == "Light" { - materials.get_mut(material).unwrap().emissive = Color::WHITE * 100.0; + materials.get_mut(material).unwrap().emissive = Color::WHITE * exposure; continue; } if &**name == "large_box" { - materials.get_mut(material).unwrap().lightmap_exposure = 150.0; + materials.get_mut(material).unwrap().lightmap_exposure = exposure; commands.entity(entity).insert(Lightmap { image: asset_server.load("lightmaps/CornellBox-Large.zstd.ktx2"), ..default() @@ -52,7 +53,7 @@ fn add_lightmaps_to_meshes( } if &**name == "small_box" { - materials.get_mut(material).unwrap().lightmap_exposure = 150.0; + materials.get_mut(material).unwrap().lightmap_exposure = exposure; commands.entity(entity).insert(Lightmap { image: asset_server.load("lightmaps/CornellBox-Small.zstd.ktx2"), ..default() @@ -61,7 +62,7 @@ fn add_lightmaps_to_meshes( } if name.starts_with("cornell_box") { - materials.get_mut(material).unwrap().lightmap_exposure = 150.0; + materials.get_mut(material).unwrap().lightmap_exposure = exposure; commands.entity(entity).insert(Lightmap { image: asset_server.load("lightmaps/CornellBox-Box.zstd.ktx2"), ..default()