Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions crates/bevy_color/src/srgba.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<f32> 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<Srgba> 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<f32> 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;
Expand Down
3 changes: 1 addition & 2 deletions examples/3d/lightmaps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down