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