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; }