From faa2ce4d55508ec4844aed18b5e95821d3f856bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Sun, 3 Mar 2024 22:36:11 +0100 Subject: [PATCH] fix example lightmaps after color migration (#12265) # Objective - Since #12163 example lightmaps is more dull Screenshot 2024-03-02 at 23 04 36 ## Solution - Use a srgba color, as it was before: https://github.com/bevyengine/bevy/blob/b24ab2e9fba5b81aba15da97b6551a4e99aad40c/examples/3d/lightmaps.rs#L39 https://github.com/bevyengine/bevy/blob/b24ab2e9fba5b81aba15da97b6551a4e99aad40c/crates/bevy_render/src/color/mod.rs#L132 Screenshot 2024-03-02 at 23 05 09 --- crates/bevy_color/src/srgba.rs | 44 ++++++++++++++++++++++++++++++++++ examples/3d/lightmaps.rs | 3 +-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/crates/bevy_color/src/srgba.rs b/crates/bevy_color/src/srgba.rs index e23beea2181f3..8479af4781daa 100644 --- a/crates/bevy_color/src/srgba.rs +++ b/crates/bevy_color/src/srgba.rs @@ -1,3 +1,5 @@ +use std::ops::{Div, Mul}; + use crate::color_difference::EuclideanDistance; use crate::{Alpha, LinearRgba, Luminance, Mix, StandardColor, Xyza}; use bevy_math::Vec4; @@ -369,6 +371,48 @@ pub enum HexColorError { Char(char), } +/// All color channels are scaled directly, +/// but alpha is unchanged. +/// +/// Values are not clamped. +impl Mul for Srgba { + type Output = Self; + + fn mul(self, rhs: f32) -> Self { + Self { + red: self.red * rhs, + green: self.green * rhs, + blue: self.blue * rhs, + alpha: self.alpha, + } + } +} + +impl Mul for f32 { + type Output = Srgba; + + fn mul(self, rhs: Srgba) -> Srgba { + rhs * self + } +} + +/// All color channels are scaled directly, +/// but alpha is unchanged. +/// +/// Values are not clamped. +impl Div for Srgba { + type Output = Self; + + fn div(self, rhs: f32) -> Self { + Self { + red: self.red / rhs, + green: self.green / rhs, + blue: self.blue / rhs, + alpha: self.alpha, + } + } +} + #[cfg(test)] mod tests { use crate::testing::assert_approx_eq; diff --git a/examples/3d/lightmaps.rs b/examples/3d/lightmaps.rs index cd08712436a5d..fe7f2a8c59f2a 100644 --- a/examples/3d/lightmaps.rs +++ b/examples/3d/lightmaps.rs @@ -36,8 +36,7 @@ fn add_lightmaps_to_meshes( let exposure = 250.0; for (entity, name, material) in meshes.iter() { if &**name == "Light" { - materials.get_mut(material).unwrap().emissive = - Color::LinearRgba(LinearRgba::WHITE * exposure); + materials.get_mut(material).unwrap().emissive = Color::Srgba(Srgba::WHITE * exposure); continue; }