Skip to content

Commit

Permalink
Add separate brightness field to AmbientLight (#1605)
Browse files Browse the repository at this point in the history
Idea being this would be easier to grasp for end-users. Problem with the logical defaults is this breaks current setups, because light will become 20 times less bright. But most folks won't have customized this resource or will not have used `..Default::default()` due to lack of other fields.
  • Loading branch information
mtsr committed Mar 12, 2021
1 parent 8a9f475 commit 32af4b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion crates/bevy_pbr/src/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,15 @@ impl LightRaw {
#[derive(Debug)]
pub struct AmbientLight {
pub color: Color,
/// Color is premultiplied by brightness before being passed to the shader
pub brightness: f32,
}

impl Default for AmbientLight {
fn default() -> Self {
Self {
color: Color::rgb(0.05, 0.05, 0.05),
color: Color::rgb(1.0, 1.0, 1.0),
brightness: 0.05,
}
}
}
4 changes: 3 additions & 1 deletion crates/bevy_pbr/src/render_graph/lights_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ pub fn lights_node_system(
let state = &mut state;
let render_resource_context = &**render_resource_context;

let ambient_light: [f32; 4] = ambient_light_resource.color.into();
// premultiply ambient brightness
let ambient_light: [f32; 4] =
(ambient_light_resource.color * ambient_light_resource.brightness).into();
let ambient_light_size = std::mem::size_of::<[f32; 4]>();
let light_count = query.iter().count();
let size = std::mem::size_of::<LightRaw>();
Expand Down

0 comments on commit 32af4b7

Please sign in to comment.