Skip to content

Commit

Permalink
fix example lightmaps after color migration (#12265)
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed Mar 3, 2024
1 parent e8ae0d6 commit faa2ce4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
44 changes: 44 additions & 0 deletions 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;
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
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

0 comments on commit faa2ce4

Please sign in to comment.