bevy_light/
ambient_light.rs

1use bevy_camera::Camera;
2use bevy_color::Color;
3use bevy_ecs::prelude::*;
4use bevy_reflect::prelude::*;
5
6/// An ambient light, which lights the entire scene equally.
7///
8/// It can be added to a camera to override [`GlobalAmbientLight`], which is the default that is otherwise used.
9#[derive(Component, Clone, Debug, Reflect)]
10#[reflect(Component, Debug, Default, Clone)]
11#[require(Camera)]
12pub struct AmbientLight {
13    pub color: Color,
14
15    /// A direct scale factor multiplied with `color` before being passed to the shader.
16    ///
17    /// After applying this multiplier, the resulting value should be in units of [cd/m^2].
18    ///
19    /// [cd/m^2]: https://en.wikipedia.org/wiki/Candela_per_square_metre
20    pub brightness: f32,
21
22    /// Whether this ambient light has an effect on meshes with lightmaps.
23    ///
24    /// Set this to false if your lightmap baking tool bakes the ambient light
25    /// into the lightmaps, to avoid rendering that light twice.
26    ///
27    /// By default, this is set to true.
28    pub affects_lightmapped_meshes: bool,
29}
30
31impl Default for AmbientLight {
32    fn default() -> Self {
33        Self {
34            color: Color::WHITE,
35            brightness: 80.0,
36            affects_lightmapped_meshes: true,
37        }
38    }
39}
40
41/// The global ambient light, which lights the entire scene equally.
42///
43/// This resource is inserted by the [`LightPlugin`] and by default it is set to a low ambient light.
44/// Inserting an [`AmbientLight`] on a camera will override this default.
45///
46/// # Examples
47///
48/// Make ambient light slightly brighter:
49///
50/// ```
51/// # use bevy_ecs::system::ResMut;
52/// # use bevy_light::GlobalAmbientLight;
53/// fn setup_ambient_light(mut ambient_light: ResMut<GlobalAmbientLight>) {
54///    ambient_light.brightness = 100.0;
55/// }
56/// ```
57///
58/// [`LightPlugin`]: crate::LightPlugin
59#[derive(Resource, Clone, Debug, Reflect)]
60#[reflect(Resource, Debug, Default, Clone)]
61pub struct GlobalAmbientLight {
62    pub color: Color,
63
64    /// A direct scale factor multiplied with `color` before being passed to the shader.
65    ///
66    /// After applying this multiplier, the resulting value should be in units of [cd/m^2].
67    ///
68    /// [cd/m^2]: https://en.wikipedia.org/wiki/Candela_per_square_metre
69    pub brightness: f32,
70
71    /// Whether this ambient light has an effect on meshes with lightmaps.
72    ///
73    /// Set this to false if your lightmap baking tool bakes the ambient light
74    /// into the lightmaps, to avoid rendering that light twice.
75    ///
76    /// By default, this is set to true.
77    pub affects_lightmapped_meshes: bool,
78}
79
80impl Default for GlobalAmbientLight {
81    fn default() -> Self {
82        Self {
83            color: Color::WHITE,
84            brightness: 80.0,
85            affects_lightmapped_meshes: true,
86        }
87    }
88}
89
90impl GlobalAmbientLight {
91    pub const NONE: GlobalAmbientLight = GlobalAmbientLight {
92        color: Color::WHITE,
93        brightness: 0.0,
94        affects_lightmapped_meshes: true,
95    };
96}