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
This commit is contained in:
Nathaniel Bielanski 2024-03-12 21:24:00 -04:00 committed by GitHub
parent 55b786c2b7
commit e282ee1a1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 39 deletions

View File

@ -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<AmbientLight>) {
/// 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,
};
}

View File

@ -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<AmbientLight>) {
/// 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)]