From e282ee1a1ceaca865b841e7eaeeaffe9463d3501 Mon Sep 17 00:00:00 2001 From: Nathaniel Bielanski <122288484+nbielans@users.noreply.github.com> Date: Tue, 12 Mar 2024 21:24:00 -0400 Subject: [PATCH] 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 --- crates/bevy_pbr/src/light/ambient_light.rs | 39 +++++++++++++++++ .../bevy_pbr/src/{light.rs => light/mod.rs} | 42 ++----------------- 2 files changed, 42 insertions(+), 39 deletions(-) create mode 100644 crates/bevy_pbr/src/light/ambient_light.rs rename crates/bevy_pbr/src/{light.rs => light/mod.rs} (99%) diff --git a/crates/bevy_pbr/src/light/ambient_light.rs b/crates/bevy_pbr/src/light/ambient_light.rs new file mode 100644 index 0000000000..d3f7744bd4 --- /dev/null +++ b/crates/bevy_pbr/src/light/ambient_light.rs @@ -0,0 +1,39 @@ +use super::*; + +/// An ambient light, which lights the entire scene equally. +/// +/// This resource is inserted by the [`PbrPlugin`] and by default it is set to a low ambient light. +/// +/// # Examples +/// +/// Make ambient light slightly brighter: +/// +/// ``` +/// # use bevy_ecs::system::ResMut; +/// # use bevy_pbr::AmbientLight; +/// fn setup_ambient_light(mut ambient_light: ResMut) { +/// ambient_light.brightness = 100.0; +/// } +/// ``` +#[derive(Resource, Clone, Debug, ExtractResource, Reflect)] +#[reflect(Resource)] +pub struct AmbientLight { + pub color: Color, + /// A direct scale factor multiplied with `color` before being passed to the shader. + pub brightness: f32, +} + +impl Default for AmbientLight { + fn default() -> Self { + Self { + color: Color::WHITE, + brightness: 80.0, + } + } +} +impl AmbientLight { + pub const NONE: AmbientLight = AmbientLight { + color: Color::WHITE, + brightness: 0.0, + }; +} diff --git a/crates/bevy_pbr/src/light.rs b/crates/bevy_pbr/src/light/mod.rs similarity index 99% rename from crates/bevy_pbr/src/light.rs rename to crates/bevy_pbr/src/light/mod.rs index e131d92d2c..5d6be4fcf4 100644 --- a/crates/bevy_pbr/src/light.rs +++ b/crates/bevy_pbr/src/light/mod.rs @@ -20,6 +20,9 @@ use bevy_utils::tracing::warn; use crate::*; +mod ambient_light; +pub use ambient_light::AmbientLight; + /// Constants for operating with the light units: lumens, and lux. pub mod light_consts { /// Approximations for converting the wattage of lamps to lumens. @@ -616,45 +619,6 @@ fn calculate_cascade( texel_size: cascade_texel_size, } } - -/// An ambient light, which lights the entire scene equally. -/// -/// This resource is inserted by the [`PbrPlugin`] and by default it is set to a low ambient light. -/// -/// # Examples -/// -/// Make ambient light slightly brighter: -/// -/// ``` -/// # use bevy_ecs::system::ResMut; -/// # use bevy_pbr::AmbientLight; -/// fn setup_ambient_light(mut ambient_light: ResMut) { -/// ambient_light.brightness = 100.0; -/// } -/// ``` -#[derive(Resource, Clone, Debug, ExtractResource, Reflect)] -#[reflect(Resource)] -pub struct AmbientLight { - pub color: Color, - /// A direct scale factor multiplied with `color` before being passed to the shader. - pub brightness: f32, -} - -impl Default for AmbientLight { - fn default() -> Self { - Self { - color: Color::WHITE, - brightness: 80.0, - } - } -} -impl AmbientLight { - pub const NONE: AmbientLight = AmbientLight { - color: Color::WHITE, - brightness: 0.0, - }; -} - /// Add this component to make a [`Mesh`](bevy_render::mesh::Mesh) not cast shadows. #[derive(Component, Reflect, Default)] #[reflect(Component, Default)]