bevy_pbr/light/ambient_light.rs
1use super::*;
2
3/// An ambient light, which lights the entire scene equally.
4///
5/// This resource is inserted by the [`PbrPlugin`] and by default it is set to a low ambient light.
6///
7/// It can also be added to a camera to override the resource (or default) ambient for that camera only.
8///
9/// # Examples
10///
11/// Make ambient light slightly brighter:
12///
13/// ```
14/// # use bevy_ecs::system::ResMut;
15/// # use bevy_pbr::AmbientLight;
16/// fn setup_ambient_light(mut ambient_light: ResMut<AmbientLight>) {
17/// ambient_light.brightness = 100.0;
18/// }
19/// ```
20#[derive(Resource, Component, Clone, Debug, ExtractResource, ExtractComponent, Reflect)]
21#[reflect(Resource, Component, Debug, Default, Clone)]
22#[require(Camera)]
23pub struct AmbientLight {
24 pub color: Color,
25
26 /// A direct scale factor multiplied with `color` before being passed to the shader.
27 ///
28 /// After applying this multiplier, the resulting value should be in units of [cd/m^2].
29 ///
30 /// [cd/m^2]: https://en.wikipedia.org/wiki/Candela_per_square_metre
31 pub brightness: f32,
32
33 /// Whether this ambient light has an effect on meshes with lightmaps.
34 ///
35 /// Set this to false if your lightmap baking tool bakes the ambient light
36 /// into the lightmaps, to avoid rendering that light twice.
37 ///
38 /// By default, this is set to true.
39 pub affects_lightmapped_meshes: bool,
40}
41
42impl Default for AmbientLight {
43 fn default() -> Self {
44 Self {
45 color: Color::WHITE,
46 brightness: 80.0,
47 affects_lightmapped_meshes: true,
48 }
49 }
50}
51impl AmbientLight {
52 pub const NONE: AmbientLight = AmbientLight {
53 color: Color::WHITE,
54 brightness: 0.0,
55 affects_lightmapped_meshes: true,
56 };
57}