Skip to content

Commit dc9b486

Browse files
authored
Change light defaults & fix light examples (bevyengine#11581)
# Objective Fix bevyengine#11577. ## Solution Fix the examples, add a few constants to make setting light values easier, and change the default lighting settings to be more realistic. (Now designed for an overcast day instead of an indoor environment) --- I did not include any example-related changes in here. ## Changelogs (not including breaking changes) ### bevy_pbr - Added `light_consts` module (included in prelude), which contains common lux and lumen values for lights. - Added `AmbientLight::NONE` constant, which is an ambient light with a brightness of 0. - Added non-EV100 variants for `ExposureSettings`'s EV100 constants, which allow easier construction of an `ExposureSettings` from a EV100 constant. ## Breaking changes ### bevy_pbr The several default lighting values were changed: - `PointLight`'s default `intensity` is now `2000.0` - `SpotLight`'s default `intensity` is now `2000.0` - `DirectionalLight`'s default `illuminance` is now `light_consts::lux::OVERCAST_DAY` (`1000.`) - `AmbientLight`'s default `brightness` is now `20.0`
1 parent bc98333 commit dc9b486

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+261
-295
lines changed

crates/bevy_pbr/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub mod prelude {
4242
SpotLightBundle,
4343
},
4444
fog::{FogFalloff, FogSettings},
45-
light::{AmbientLight, DirectionalLight, PointLight, SpotLight},
45+
light::{light_consts, AmbientLight, DirectionalLight, PointLight, SpotLight},
4646
light_probe::{
4747
environment_map::{EnvironmentMapLight, ReflectionProbeBundle},
4848
LightProbe,

crates/bevy_pbr/src/light.rs

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,61 @@ use bevy_utils::tracing::warn;
2121

2222
use crate::*;
2323

24+
/// Constants for operating with the light units: lumens, and lux.
25+
pub mod light_consts {
26+
/// Approximations for converting the wattage of lamps to lumens.
27+
///
28+
/// The **lumen** (symbol: **lm**) is the unit of [luminous flux], a measure
29+
/// of the total quantity of [visible light] emitted by a source per unit of
30+
/// time, in the [International System of Units] (SI).
31+
///
32+
/// For more information, see [wikipedia](https://en.wikipedia.org/wiki/Lumen_(unit))
33+
///
34+
/// [luminous flux]: https://en.wikipedia.org/wiki/Luminous_flux
35+
/// [visible light]: https://en.wikipedia.org/wiki/Visible_light
36+
/// [International System of Units]: https://en.wikipedia.org/wiki/International_System_of_Units
37+
pub mod lumens {
38+
pub const LUMENS_PER_LED_WATTS: f32 = 90.0;
39+
pub const LUMENS_PER_INCANDESCENT_WATTS: f32 = 13.8;
40+
pub const LUMENS_PER_HALOGEN_WATTS: f32 = 19.8;
41+
}
42+
43+
/// Predefined for lux values in several locations.
44+
///
45+
/// The **lux** (symbol: **lx**) is the unit of [illuminance], or [luminous flux] per unit area,
46+
/// in the [International System of Units] (SI). It is equal to one lumen per square metre.
47+
///
48+
/// For more information, see [wikipedia](https://en.wikipedia.org/wiki/Lux)
49+
///
50+
/// [illuminance]: https://en.wikipedia.org/wiki/Illuminance
51+
/// [luminous flux]: https://en.wikipedia.org/wiki/Luminous_flux
52+
/// [International System of Units]: https://en.wikipedia.org/wiki/International_System_of_Units
53+
pub mod lux {
54+
/// The amount of light (lux) in a moonless, overcast night sky. (starlight)
55+
pub const MOONLESS_NIGHT: f32 = 0.0001;
56+
/// The amount of light (lux) during a full moon on a clear night.
57+
pub const FULL_MOON_NIGHT: f32 = 0.05;
58+
/// The amount of light (lux) during the dark limit of civil twilight under a clear sky.
59+
pub const CIVIL_TWILIGHT: f32 = 3.4;
60+
/// The amount of light (lux) in family living room lights.
61+
pub const LIVING_ROOM: f32 = 50.;
62+
/// The amount of light (lux) in an office building's hallway/toilet lighting.
63+
pub const HALLWAY: f32 = 80.;
64+
/// The amount of light (lux) in very dark overcast day
65+
pub const DARK_OVERCAST_DAY: f32 = 100.;
66+
/// The amount of light (lux) in an office.
67+
pub const OFFICE: f32 = 320.;
68+
/// The amount of light (lux) during sunrise or sunset on a clear day.
69+
pub const CLEAR_SUNRISE: f32 = 400.;
70+
/// The amount of light (lux) on a overcast day; typical TV studio lighting
71+
pub const OVERCAST_DAY: f32 = 1000.;
72+
/// The amount of light (lux) in full daylight (not direct sun).
73+
pub const FULL_DAYLIGHT: f32 = 10_000.;
74+
/// The amount of light (lux) in direct sunlight.
75+
pub const DIRECT_SUNLIGHT: f32 = 50_000.;
76+
}
77+
}
78+
2479
/// A light that emits light in all directions from a central point.
2580
///
2681
/// Real-world values for `intensity` (luminous power in lumens) based on the electrical power
@@ -58,7 +113,7 @@ impl Default for PointLight {
58113
fn default() -> Self {
59114
PointLight {
60115
color: Color::rgb(1.0, 1.0, 1.0),
61-
intensity: 800.0, // Roughly a 60W non-halogen incandescent bulb
116+
intensity: 2000.0, // Roughly a 20-watt LED bulb
62117
range: 20.0,
63118
radius: 0.0,
64119
shadows_enabled: false,
@@ -126,7 +181,7 @@ impl Default for SpotLight {
126181
// a quarter arc attenuating from the center
127182
Self {
128183
color: Color::rgb(1.0, 1.0, 1.0),
129-
intensity: 800.0, // Roughly a 60W non-halogen incandescent bulb
184+
intensity: 2000.0, // Roughly a 20-watt LED bulb
130185
range: 20.0,
131186
radius: 0.0,
132187
shadows_enabled: false,
@@ -207,7 +262,7 @@ impl Default for DirectionalLight {
207262
fn default() -> Self {
208263
DirectionalLight {
209264
color: Color::rgb(1.0, 1.0, 1.0),
210-
illuminance: 100000.0,
265+
illuminance: light_consts::lux::OVERCAST_DAY,
211266
shadows_enabled: false,
212267
shadow_depth_bias: Self::DEFAULT_SHADOW_DEPTH_BIAS,
213268
shadow_normal_bias: Self::DEFAULT_SHADOW_NORMAL_BIAS,
@@ -567,7 +622,7 @@ fn calculate_cascade(
567622
/// # use bevy_ecs::system::ResMut;
568623
/// # use bevy_pbr::AmbientLight;
569624
/// fn setup_ambient_light(mut ambient_light: ResMut<AmbientLight>) {
570-
/// ambient_light.brightness = 20.0;
625+
/// ambient_light.brightness = 100.0;
571626
/// }
572627
/// ```
573628
#[derive(Resource, Clone, Debug, ExtractResource, Reflect)]
@@ -581,11 +636,17 @@ pub struct AmbientLight {
581636
impl Default for AmbientLight {
582637
fn default() -> Self {
583638
Self {
584-
color: Color::rgb(1.0, 1.0, 1.0),
585-
brightness: 8.0,
639+
color: Color::WHITE,
640+
brightness: 20.0,
586641
}
587642
}
588643
}
644+
impl AmbientLight {
645+
pub const NONE: AmbientLight = AmbientLight {
646+
color: Color::WHITE,
647+
brightness: 0.0,
648+
};
649+
}
589650

590651
/// Add this component to make a [`Mesh`](bevy_render::mesh::Mesh) not cast shadows.
591652
#[derive(Component, Reflect, Default)]

crates/bevy_render/src/camera/camera.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ pub struct ExposureSettings {
9696
}
9797

9898
impl ExposureSettings {
99+
pub const SUNLIGHT: Self = Self {
100+
ev100: Self::EV100_SUNLIGHT,
101+
};
102+
pub const OVERCAST: Self = Self {
103+
ev100: Self::EV100_OVERCAST,
104+
};
105+
pub const INDOOR: Self = Self {
106+
ev100: Self::EV100_INDOOR,
107+
};
108+
99109
pub const EV100_SUNLIGHT: f32 = 15.0;
100110
pub const EV100_OVERCAST: f32 = 12.0;
101111
pub const EV100_INDOOR: f32 = 7.0;
@@ -116,9 +126,7 @@ impl ExposureSettings {
116126

117127
impl Default for ExposureSettings {
118128
fn default() -> Self {
119-
Self {
120-
ev100: Self::EV100_INDOOR,
121-
}
129+
Self::INDOOR
122130
}
123131
}
124132

examples/3d/3d_gizmos.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ fn setup(
4141
..default()
4242
});
4343
// light
44-
commands.spawn(PointLightBundle {
45-
point_light: PointLight {
46-
intensity: 250000.0,
44+
commands.spawn(DirectionalLightBundle {
45+
directional_light: DirectionalLight {
46+
illuminance: light_consts::lux::OVERCAST_DAY,
4747
shadows_enabled: true,
4848
..default()
4949
},
50-
transform: Transform::from_xyz(4.0, 8.0, 4.0),
50+
transform: Transform::from_xyz(4.0, 8.0, 4.0).looking_at(Vec3::ZERO, Vec3::Y),
5151
..default()
5252
});
5353

examples/3d/3d_scene.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ fn setup(
3030
..default()
3131
});
3232
// light
33-
commands.spawn(PointLightBundle {
34-
point_light: PointLight {
35-
intensity: 250_000.0,
33+
commands.spawn(DirectionalLightBundle {
34+
directional_light: DirectionalLight {
35+
illuminance: light_consts::lux::OVERCAST_DAY,
3636
shadows_enabled: true,
3737
..default()
3838
},
39-
transform: Transform::from_xyz(4.0, 8.0, 4.0),
39+
transform: Transform::from_xyz(4.0, 8.0, 4.0).looking_at(Vec3::ZERO, Vec3::Y),
4040
..default()
4141
});
4242
// camera

examples/3d/3d_shapes.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,13 @@ fn setup(
6464
));
6565
}
6666

67-
commands.spawn(PointLightBundle {
68-
point_light: PointLight {
69-
intensity: 1500000.0,
70-
range: 100.,
67+
commands.spawn(DirectionalLightBundle {
68+
directional_light: DirectionalLight {
69+
illuminance: light_consts::lux::OVERCAST_DAY,
7170
shadows_enabled: true,
7271
..default()
7372
},
74-
transform: Transform::from_xyz(8.0, 16.0, 8.0),
73+
transform: Transform::from_xyz(8.0, 16.0, 8.0).looking_at(Vec3::ZERO, Vec3::Y),
7574
..default()
7675
});
7776

examples/3d/3d_viewport_to_world.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ fn setup(
6666
// light
6767
commands.spawn(DirectionalLightBundle {
6868
transform: Transform::from_translation(Vec3::ONE).looking_at(Vec3::ZERO, Vec3::Y),
69-
directional_light: DirectionalLight {
70-
illuminance: 2000.0,
71-
..default()
72-
},
69+
directional_light: DirectionalLight::default(),
7370
..default()
7471
});
7572

examples/3d/animated_material.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn setup(
2525
EnvironmentMapLight {
2626
diffuse_map: asset_server.load("environment_maps/pisa_diffuse_rgb9e5_zstd.ktx2"),
2727
specular_map: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"),
28-
intensity: 1500.0,
28+
intensity: 1_000.0,
2929
},
3030
));
3131

examples/3d/anti_aliasing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ fn setup(
289289
// Light
290290
commands.spawn(DirectionalLightBundle {
291291
directional_light: DirectionalLight {
292-
illuminance: 3000.0,
292+
illuminance: light_consts::lux::OVERCAST_DAY,
293293
shadows_enabled: true,
294294
..default()
295295
},

examples/3d/atmospheric_fog.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn setup_terrain_scene(
6161
commands.spawn(DirectionalLightBundle {
6262
directional_light: DirectionalLight {
6363
color: Color::rgb(0.98, 0.95, 0.82),
64-
illuminance: 3000.0,
64+
illuminance: light_consts::lux::OVERCAST_DAY,
6565
shadows_enabled: true,
6666
..default()
6767
},

0 commit comments

Comments
 (0)