Skip to content

Commit e282ee1

Browse files
authored
Extracting ambient light from light.rs, and creating light directory (#12369)
# Objective Beginning of refactoring of light.rs in bevy_pbr, as per issue #12349 Create and move light.rs to its own directory, and extract AmbientLight struct. ## Solution - moved light.rs to light/mod.rs - extracted AmbientLight struct to light/ambient_light.rs
1 parent 55b786c commit e282ee1

File tree

2 files changed

+42
-39
lines changed

2 files changed

+42
-39
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use 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+
/// # Examples
8+
///
9+
/// Make ambient light slightly brighter:
10+
///
11+
/// ```
12+
/// # use bevy_ecs::system::ResMut;
13+
/// # use bevy_pbr::AmbientLight;
14+
/// fn setup_ambient_light(mut ambient_light: ResMut<AmbientLight>) {
15+
/// ambient_light.brightness = 100.0;
16+
/// }
17+
/// ```
18+
#[derive(Resource, Clone, Debug, ExtractResource, Reflect)]
19+
#[reflect(Resource)]
20+
pub struct AmbientLight {
21+
pub color: Color,
22+
/// A direct scale factor multiplied with `color` before being passed to the shader.
23+
pub brightness: f32,
24+
}
25+
26+
impl Default for AmbientLight {
27+
fn default() -> Self {
28+
Self {
29+
color: Color::WHITE,
30+
brightness: 80.0,
31+
}
32+
}
33+
}
34+
impl AmbientLight {
35+
pub const NONE: AmbientLight = AmbientLight {
36+
color: Color::WHITE,
37+
brightness: 0.0,
38+
};
39+
}

crates/bevy_pbr/src/light.rs renamed to crates/bevy_pbr/src/light/mod.rs

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ use bevy_utils::tracing::warn;
2020

2121
use crate::*;
2222

23+
mod ambient_light;
24+
pub use ambient_light::AmbientLight;
25+
2326
/// Constants for operating with the light units: lumens, and lux.
2427
pub mod light_consts {
2528
/// Approximations for converting the wattage of lamps to lumens.
@@ -616,45 +619,6 @@ fn calculate_cascade(
616619
texel_size: cascade_texel_size,
617620
}
618621
}
619-
620-
/// An ambient light, which lights the entire scene equally.
621-
///
622-
/// This resource is inserted by the [`PbrPlugin`] and by default it is set to a low ambient light.
623-
///
624-
/// # Examples
625-
///
626-
/// Make ambient light slightly brighter:
627-
///
628-
/// ```
629-
/// # use bevy_ecs::system::ResMut;
630-
/// # use bevy_pbr::AmbientLight;
631-
/// fn setup_ambient_light(mut ambient_light: ResMut<AmbientLight>) {
632-
/// ambient_light.brightness = 100.0;
633-
/// }
634-
/// ```
635-
#[derive(Resource, Clone, Debug, ExtractResource, Reflect)]
636-
#[reflect(Resource)]
637-
pub struct AmbientLight {
638-
pub color: Color,
639-
/// A direct scale factor multiplied with `color` before being passed to the shader.
640-
pub brightness: f32,
641-
}
642-
643-
impl Default for AmbientLight {
644-
fn default() -> Self {
645-
Self {
646-
color: Color::WHITE,
647-
brightness: 80.0,
648-
}
649-
}
650-
}
651-
impl AmbientLight {
652-
pub const NONE: AmbientLight = AmbientLight {
653-
color: Color::WHITE,
654-
brightness: 0.0,
655-
};
656-
}
657-
658622
/// Add this component to make a [`Mesh`](bevy_render::mesh::Mesh) not cast shadows.
659623
#[derive(Component, Reflect, Default)]
660624
#[reflect(Component, Default)]

0 commit comments

Comments
 (0)