Add separate brightness field to AmbientLight (#1605)

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.
This commit is contained in:
Jonas Matser 2021-03-12 18:59:24 +00:00
parent 8a9f475edb
commit 32af4b7dc3
2 changed files with 7 additions and 2 deletions

View file

@ -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,
}
}
}

View file

@ -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>();