diff --git a/crates/bevy_color/src/color_ops.rs b/crates/bevy_color/src/color_ops.rs index 1f39f3254c..0441d11e9c 100644 --- a/crates/bevy_color/src/color_ops.rs +++ b/crates/bevy_color/src/color_ops.rs @@ -1,3 +1,5 @@ +use bevy_math::{Vec3, Vec4}; + /// Methods for changing the luminance of a color. Note that these methods are not /// guaranteed to produce consistent results across color spaces, /// but will be within a given space. @@ -97,6 +99,26 @@ pub trait ClampColor: Sized { fn is_within_bounds(&self) -> bool; } +/// Trait with methods for converting colors to non-color types +pub trait ColorToComponents { + /// Convert to an f32 array + fn to_f32_array(self) -> [f32; 4]; + /// Convert to an f32 array without the alpha value + fn to_f32_array_no_alpha(self) -> [f32; 3]; + /// Convert to a Vec4 + fn to_vec4(self) -> Vec4; + /// Convert to a Vec3 + fn to_vec3(self) -> Vec3; + /// Convert from an f32 array + fn from_f32_array(color: [f32; 4]) -> Self; + /// Convert from an f32 array without the alpha value + fn from_f32_array_no_alpha(color: [f32; 3]) -> Self; + /// Convert from a Vec4 + fn from_vec4(color: Vec4) -> Self; + /// Convert from a Vec3 + fn from_vec3(color: Vec3) -> Self; +} + /// Utility function for interpolating hue values. This ensures that the interpolation /// takes the shortest path around the color wheel, and that the result is always between /// 0 and 360. diff --git a/crates/bevy_color/src/hsla.rs b/crates/bevy_color/src/hsla.rs index 3c225b369d..0d0531750a 100644 --- a/crates/bevy_color/src/hsla.rs +++ b/crates/bevy_color/src/hsla.rs @@ -1,7 +1,8 @@ use crate::{ - Alpha, ClampColor, Hsva, Hue, Hwba, Lcha, LinearRgba, Luminance, Mix, Srgba, StandardColor, - Xyza, + Alpha, ClampColor, ColorToComponents, Hsva, Hue, Hwba, Lcha, LinearRgba, Luminance, Mix, Srgba, + StandardColor, Xyza, }; +use bevy_math::{Vec3, Vec4}; use bevy_reflect::prelude::*; /// Color in Hue-Saturation-Lightness (HSL) color space with alpha. @@ -195,6 +196,60 @@ impl ClampColor for Hsla { } } +impl ColorToComponents for Hsla { + fn to_f32_array(self) -> [f32; 4] { + [self.hue, self.saturation, self.lightness, self.alpha] + } + + fn to_f32_array_no_alpha(self) -> [f32; 3] { + [self.hue, self.saturation, self.lightness] + } + + fn to_vec4(self) -> Vec4 { + Vec4::new(self.hue, self.saturation, self.lightness, self.alpha) + } + + fn to_vec3(self) -> Vec3 { + Vec3::new(self.hue, self.saturation, self.lightness) + } + + fn from_f32_array(color: [f32; 4]) -> Self { + Self { + hue: color[0], + saturation: color[1], + lightness: color[2], + alpha: color[3], + } + } + + fn from_f32_array_no_alpha(color: [f32; 3]) -> Self { + Self { + hue: color[0], + saturation: color[1], + lightness: color[2], + alpha: 1.0, + } + } + + fn from_vec4(color: Vec4) -> Self { + Self { + hue: color[0], + saturation: color[1], + lightness: color[2], + alpha: color[3], + } + } + + fn from_vec3(color: Vec3) -> Self { + Self { + hue: color[0], + saturation: color[1], + lightness: color[2], + alpha: 1.0, + } + } +} + impl From for Hsva { fn from( Hsla { diff --git a/crates/bevy_color/src/hsva.rs b/crates/bevy_color/src/hsva.rs index f58cdefac5..760cad6419 100644 --- a/crates/bevy_color/src/hsva.rs +++ b/crates/bevy_color/src/hsva.rs @@ -1,4 +1,8 @@ -use crate::{Alpha, ClampColor, Hue, Hwba, Lcha, LinearRgba, Mix, Srgba, StandardColor, Xyza}; +use crate::{ + Alpha, ClampColor, ColorToComponents, Hue, Hwba, Lcha, LinearRgba, Mix, Srgba, StandardColor, + Xyza, +}; +use bevy_math::{Vec3, Vec4}; use bevy_reflect::prelude::*; /// Color in Hue-Saturation-Value (HSV) color space with alpha. @@ -172,6 +176,60 @@ impl From for Hsva { } } +impl ColorToComponents for Hsva { + fn to_f32_array(self) -> [f32; 4] { + [self.hue, self.saturation, self.value, self.alpha] + } + + fn to_f32_array_no_alpha(self) -> [f32; 3] { + [self.hue, self.saturation, self.value] + } + + fn to_vec4(self) -> Vec4 { + Vec4::new(self.hue, self.saturation, self.value, self.alpha) + } + + fn to_vec3(self) -> Vec3 { + Vec3::new(self.hue, self.saturation, self.value) + } + + fn from_f32_array(color: [f32; 4]) -> Self { + Self { + hue: color[0], + saturation: color[1], + value: color[2], + alpha: color[3], + } + } + + fn from_f32_array_no_alpha(color: [f32; 3]) -> Self { + Self { + hue: color[0], + saturation: color[1], + value: color[2], + alpha: 1.0, + } + } + + fn from_vec4(color: Vec4) -> Self { + Self { + hue: color[0], + saturation: color[1], + value: color[2], + alpha: color[3], + } + } + + fn from_vec3(color: Vec3) -> Self { + Self { + hue: color[0], + saturation: color[1], + value: color[2], + alpha: 1.0, + } + } +} + // Derived Conversions impl From for Hsva { diff --git a/crates/bevy_color/src/hwba.rs b/crates/bevy_color/src/hwba.rs index f5e7cf3a93..65b6b67e09 100644 --- a/crates/bevy_color/src/hwba.rs +++ b/crates/bevy_color/src/hwba.rs @@ -2,7 +2,10 @@ //! in [_HWB - A More Intuitive Hue-Based Color Model_] by _Smith et al_. //! //! [_HWB - A More Intuitive Hue-Based Color Model_]: https://web.archive.org/web/20240226005220/http://alvyray.com/Papers/CG/HWB_JGTv208.pdf -use crate::{Alpha, ClampColor, Hue, Lcha, LinearRgba, Mix, Srgba, StandardColor, Xyza}; +use crate::{ + Alpha, ClampColor, ColorToComponents, Hue, Lcha, LinearRgba, Mix, Srgba, StandardColor, Xyza, +}; +use bevy_math::{Vec3, Vec4}; use bevy_reflect::prelude::*; /// Color in Hue-Whiteness-Blackness (HWB) color space with alpha. @@ -142,6 +145,60 @@ impl ClampColor for Hwba { } } +impl ColorToComponents for Hwba { + fn to_f32_array(self) -> [f32; 4] { + [self.hue, self.whiteness, self.blackness, self.alpha] + } + + fn to_f32_array_no_alpha(self) -> [f32; 3] { + [self.hue, self.whiteness, self.blackness] + } + + fn to_vec4(self) -> Vec4 { + Vec4::new(self.hue, self.whiteness, self.blackness, self.alpha) + } + + fn to_vec3(self) -> Vec3 { + Vec3::new(self.hue, self.whiteness, self.blackness) + } + + fn from_f32_array(color: [f32; 4]) -> Self { + Self { + hue: color[0], + whiteness: color[1], + blackness: color[2], + alpha: color[3], + } + } + + fn from_f32_array_no_alpha(color: [f32; 3]) -> Self { + Self { + hue: color[0], + whiteness: color[1], + blackness: color[2], + alpha: 1.0, + } + } + + fn from_vec4(color: Vec4) -> Self { + Self { + hue: color[0], + whiteness: color[1], + blackness: color[2], + alpha: color[3], + } + } + + fn from_vec3(color: Vec3) -> Self { + Self { + hue: color[0], + whiteness: color[1], + blackness: color[2], + alpha: 1.0, + } + } +} + impl From for Hwba { fn from( Srgba { diff --git a/crates/bevy_color/src/laba.rs b/crates/bevy_color/src/laba.rs index 2ce9b55b72..cd0684e16f 100644 --- a/crates/bevy_color/src/laba.rs +++ b/crates/bevy_color/src/laba.rs @@ -1,7 +1,8 @@ use crate::{ - impl_componentwise_vector_space, Alpha, ClampColor, Hsla, Hsva, Hwba, LinearRgba, Luminance, - Mix, Oklaba, Srgba, StandardColor, Xyza, + impl_componentwise_vector_space, Alpha, ClampColor, ColorToComponents, Hsla, Hsva, Hwba, + LinearRgba, Luminance, Mix, Oklaba, Srgba, StandardColor, Xyza, }; +use bevy_math::{Vec3, Vec4}; use bevy_reflect::prelude::*; /// Color in LAB color space, with alpha @@ -164,6 +165,60 @@ impl Luminance for Laba { } } +impl ColorToComponents for Laba { + fn to_f32_array(self) -> [f32; 4] { + [self.lightness, self.a, self.b, self.alpha] + } + + fn to_f32_array_no_alpha(self) -> [f32; 3] { + [self.lightness, self.a, self.b] + } + + fn to_vec4(self) -> Vec4 { + Vec4::new(self.lightness, self.a, self.b, self.alpha) + } + + fn to_vec3(self) -> Vec3 { + Vec3::new(self.lightness, self.a, self.b) + } + + fn from_f32_array(color: [f32; 4]) -> Self { + Self { + lightness: color[0], + a: color[1], + b: color[2], + alpha: color[3], + } + } + + fn from_f32_array_no_alpha(color: [f32; 3]) -> Self { + Self { + lightness: color[0], + a: color[1], + b: color[2], + alpha: 1.0, + } + } + + fn from_vec4(color: Vec4) -> Self { + Self { + lightness: color[0], + a: color[1], + b: color[2], + alpha: color[3], + } + } + + fn from_vec3(color: Vec3) -> Self { + Self { + lightness: color[0], + a: color[1], + b: color[2], + alpha: 1.0, + } + } +} + impl From for Xyza { fn from( Laba { diff --git a/crates/bevy_color/src/lcha.rs b/crates/bevy_color/src/lcha.rs index b33236d6f1..437ca5d6d7 100644 --- a/crates/bevy_color/src/lcha.rs +++ b/crates/bevy_color/src/lcha.rs @@ -1,4 +1,8 @@ -use crate::{Alpha, ClampColor, Hue, Laba, LinearRgba, Luminance, Mix, Srgba, StandardColor, Xyza}; +use crate::{ + Alpha, ClampColor, ColorToComponents, Hue, Laba, LinearRgba, Luminance, Mix, Srgba, + StandardColor, Xyza, +}; +use bevy_math::{Vec3, Vec4}; use bevy_reflect::prelude::*; /// Color in LCH color space, with alpha @@ -200,6 +204,60 @@ impl ClampColor for Lcha { } } +impl ColorToComponents for Lcha { + fn to_f32_array(self) -> [f32; 4] { + [self.lightness, self.chroma, self.hue, self.alpha] + } + + fn to_f32_array_no_alpha(self) -> [f32; 3] { + [self.lightness, self.chroma, self.hue] + } + + fn to_vec4(self) -> Vec4 { + Vec4::new(self.lightness, self.chroma, self.hue, self.alpha) + } + + fn to_vec3(self) -> Vec3 { + Vec3::new(self.lightness, self.chroma, self.hue) + } + + fn from_f32_array(color: [f32; 4]) -> Self { + Self { + lightness: color[0], + chroma: color[1], + hue: color[2], + alpha: color[3], + } + } + + fn from_f32_array_no_alpha(color: [f32; 3]) -> Self { + Self { + lightness: color[0], + chroma: color[1], + hue: color[2], + alpha: 1.0, + } + } + + fn from_vec4(color: Vec4) -> Self { + Self { + lightness: color[0], + chroma: color[1], + hue: color[2], + alpha: color[3], + } + } + + fn from_vec3(color: Vec3) -> Self { + Self { + lightness: color[0], + chroma: color[1], + hue: color[2], + alpha: 1.0, + } + } +} + impl From for Laba { fn from( Lcha { diff --git a/crates/bevy_color/src/linear_rgba.rs b/crates/bevy_color/src/linear_rgba.rs index 3eb0646ff0..0ef33ce37e 100644 --- a/crates/bevy_color/src/linear_rgba.rs +++ b/crates/bevy_color/src/linear_rgba.rs @@ -1,8 +1,8 @@ use crate::{ color_difference::EuclideanDistance, impl_componentwise_vector_space, Alpha, ClampColor, - Luminance, Mix, StandardColor, + ColorToComponents, Luminance, Mix, StandardColor, }; -use bevy_math::Vec4; +use bevy_math::{Vec3, Vec4}; use bevy_reflect::prelude::*; use bytemuck::{Pod, Zeroable}; @@ -281,15 +281,57 @@ impl ClampColor for LinearRgba { } } -impl From for [f32; 4] { - fn from(color: LinearRgba) -> Self { - [color.red, color.green, color.blue, color.alpha] +impl ColorToComponents for LinearRgba { + fn to_f32_array(self) -> [f32; 4] { + [self.red, self.green, self.blue, self.alpha] } -} -impl From for Vec4 { - fn from(color: LinearRgba) -> Self { - Vec4::new(color.red, color.green, color.blue, color.alpha) + fn to_f32_array_no_alpha(self) -> [f32; 3] { + [self.red, self.green, self.blue] + } + + fn to_vec4(self) -> Vec4 { + Vec4::new(self.red, self.green, self.blue, self.alpha) + } + + fn to_vec3(self) -> Vec3 { + Vec3::new(self.red, self.green, self.blue) + } + + fn from_f32_array(color: [f32; 4]) -> Self { + Self { + red: color[0], + green: color[1], + blue: color[2], + alpha: color[3], + } + } + + fn from_f32_array_no_alpha(color: [f32; 3]) -> Self { + Self { + red: color[0], + green: color[1], + blue: color[2], + alpha: 1.0, + } + } + + fn from_vec4(color: Vec4) -> Self { + Self { + red: color[0], + green: color[1], + blue: color[2], + alpha: color[3], + } + } + + fn from_vec3(color: Vec3) -> Self { + Self { + red: color[0], + green: color[1], + blue: color[2], + alpha: 1.0, + } } } diff --git a/crates/bevy_color/src/oklaba.rs b/crates/bevy_color/src/oklaba.rs index 858091a719..46e23ff087 100644 --- a/crates/bevy_color/src/oklaba.rs +++ b/crates/bevy_color/src/oklaba.rs @@ -1,7 +1,9 @@ use crate::{ - color_difference::EuclideanDistance, impl_componentwise_vector_space, Alpha, ClampColor, Hsla, - Hsva, Hwba, Lcha, LinearRgba, Luminance, Mix, Srgba, StandardColor, Xyza, + color_difference::EuclideanDistance, impl_componentwise_vector_space, Alpha, ClampColor, + ColorToComponents, Hsla, Hsva, Hwba, Lcha, LinearRgba, Luminance, Mix, Srgba, StandardColor, + Xyza, }; +use bevy_math::{Vec3, Vec4}; use bevy_reflect::prelude::*; /// Color in Oklab color space, with alpha @@ -173,6 +175,60 @@ impl ClampColor for Oklaba { } } +impl ColorToComponents for Oklaba { + fn to_f32_array(self) -> [f32; 4] { + [self.lightness, self.a, self.b, self.alpha] + } + + fn to_f32_array_no_alpha(self) -> [f32; 3] { + [self.lightness, self.a, self.b] + } + + fn to_vec4(self) -> Vec4 { + Vec4::new(self.lightness, self.a, self.b, self.alpha) + } + + fn to_vec3(self) -> Vec3 { + Vec3::new(self.lightness, self.a, self.b) + } + + fn from_f32_array(color: [f32; 4]) -> Self { + Self { + lightness: color[0], + a: color[1], + b: color[2], + alpha: color[3], + } + } + + fn from_f32_array_no_alpha(color: [f32; 3]) -> Self { + Self { + lightness: color[0], + a: color[1], + b: color[2], + alpha: 1.0, + } + } + + fn from_vec4(color: Vec4) -> Self { + Self { + lightness: color[0], + a: color[1], + b: color[2], + alpha: color[3], + } + } + + fn from_vec3(color: Vec3) -> Self { + Self { + lightness: color[0], + a: color[1], + b: color[2], + alpha: 1.0, + } + } +} + #[allow(clippy::excessive_precision)] impl From for Oklaba { fn from(value: LinearRgba) -> Self { diff --git a/crates/bevy_color/src/oklcha.rs b/crates/bevy_color/src/oklcha.rs index 01b21b6780..3e748a1c94 100644 --- a/crates/bevy_color/src/oklcha.rs +++ b/crates/bevy_color/src/oklcha.rs @@ -1,7 +1,8 @@ use crate::{ - color_difference::EuclideanDistance, Alpha, ClampColor, Hsla, Hsva, Hue, Hwba, Laba, Lcha, - LinearRgba, Luminance, Mix, Oklaba, Srgba, StandardColor, Xyza, + color_difference::EuclideanDistance, Alpha, ClampColor, ColorToComponents, Hsla, Hsva, Hue, + Hwba, Laba, Lcha, LinearRgba, Luminance, Mix, Oklaba, Srgba, StandardColor, Xyza, }; +use bevy_math::{Vec3, Vec4}; use bevy_reflect::prelude::*; /// Color in Oklch color space, with alpha @@ -190,6 +191,60 @@ impl EuclideanDistance for Oklcha { } } +impl ColorToComponents for Oklcha { + fn to_f32_array(self) -> [f32; 4] { + [self.lightness, self.chroma, self.hue, self.alpha] + } + + fn to_f32_array_no_alpha(self) -> [f32; 3] { + [self.lightness, self.chroma, self.hue] + } + + fn to_vec4(self) -> Vec4 { + Vec4::new(self.lightness, self.chroma, self.hue, self.alpha) + } + + fn to_vec3(self) -> Vec3 { + Vec3::new(self.lightness, self.chroma, self.hue) + } + + fn from_f32_array(color: [f32; 4]) -> Self { + Self { + lightness: color[0], + chroma: color[1], + hue: color[2], + alpha: color[3], + } + } + + fn from_f32_array_no_alpha(color: [f32; 3]) -> Self { + Self { + lightness: color[0], + chroma: color[1], + hue: color[2], + alpha: 1.0, + } + } + + fn from_vec4(color: Vec4) -> Self { + Self { + lightness: color[0], + chroma: color[1], + hue: color[2], + alpha: color[3], + } + } + + fn from_vec3(color: Vec3) -> Self { + Self { + lightness: color[0], + chroma: color[1], + hue: color[2], + alpha: 1.0, + } + } +} + impl From for Oklcha { fn from( Oklaba { diff --git a/crates/bevy_color/src/srgba.rs b/crates/bevy_color/src/srgba.rs index 43c82fda25..def49cfca3 100644 --- a/crates/bevy_color/src/srgba.rs +++ b/crates/bevy_color/src/srgba.rs @@ -1,9 +1,9 @@ use crate::color_difference::EuclideanDistance; use crate::{ - impl_componentwise_vector_space, Alpha, ClampColor, LinearRgba, Luminance, Mix, StandardColor, - Xyza, + impl_componentwise_vector_space, Alpha, ClampColor, ColorToComponents, LinearRgba, Luminance, + Mix, StandardColor, Xyza, }; -use bevy_math::Vec4; +use bevy_math::{Vec3, Vec4}; use bevy_reflect::prelude::*; use thiserror::Error; @@ -332,6 +332,60 @@ impl ClampColor for Srgba { } } +impl ColorToComponents for Srgba { + fn to_f32_array(self) -> [f32; 4] { + [self.red, self.green, self.blue, self.alpha] + } + + fn to_f32_array_no_alpha(self) -> [f32; 3] { + [self.red, self.green, self.blue] + } + + fn to_vec4(self) -> Vec4 { + Vec4::new(self.red, self.green, self.blue, self.alpha) + } + + fn to_vec3(self) -> Vec3 { + Vec3::new(self.red, self.green, self.blue) + } + + fn from_f32_array(color: [f32; 4]) -> Self { + Self { + red: color[0], + green: color[1], + blue: color[2], + alpha: color[3], + } + } + + fn from_f32_array_no_alpha(color: [f32; 3]) -> Self { + Self { + red: color[0], + green: color[1], + blue: color[2], + alpha: 1.0, + } + } + + fn from_vec4(color: Vec4) -> Self { + Self { + red: color[0], + green: color[1], + blue: color[2], + alpha: color[3], + } + } + + fn from_vec3(color: Vec3) -> Self { + Self { + red: color[0], + green: color[1], + blue: color[2], + alpha: 1.0, + } + } +} + impl From for Srgba { #[inline] fn from(value: LinearRgba) -> Self { @@ -356,18 +410,6 @@ impl From for LinearRgba { } } -impl From for [f32; 4] { - fn from(color: Srgba) -> Self { - [color.red, color.green, color.blue, color.alpha] - } -} - -impl From for Vec4 { - fn from(color: Srgba) -> Self { - Vec4::new(color.red, color.green, color.blue, color.alpha) - } -} - // Derived Conversions impl From for Srgba { diff --git a/crates/bevy_color/src/xyza.rs b/crates/bevy_color/src/xyza.rs index d3baf464f4..6d46c85c92 100644 --- a/crates/bevy_color/src/xyza.rs +++ b/crates/bevy_color/src/xyza.rs @@ -1,6 +1,8 @@ use crate::{ - impl_componentwise_vector_space, Alpha, ClampColor, LinearRgba, Luminance, Mix, StandardColor, + impl_componentwise_vector_space, Alpha, ClampColor, ColorToComponents, LinearRgba, Luminance, + Mix, StandardColor, }; +use bevy_math::{Vec3, Vec4}; use bevy_reflect::prelude::*; /// [CIE 1931](https://en.wikipedia.org/wiki/CIE_1931_color_space) color space, also known as XYZ, with an alpha channel. @@ -160,6 +162,60 @@ impl ClampColor for Xyza { } } +impl ColorToComponents for Xyza { + fn to_f32_array(self) -> [f32; 4] { + [self.x, self.y, self.z, self.alpha] + } + + fn to_f32_array_no_alpha(self) -> [f32; 3] { + [self.x, self.y, self.z] + } + + fn to_vec4(self) -> Vec4 { + Vec4::new(self.x, self.y, self.z, self.alpha) + } + + fn to_vec3(self) -> Vec3 { + Vec3::new(self.x, self.y, self.z) + } + + fn from_f32_array(color: [f32; 4]) -> Self { + Self { + x: color[0], + y: color[1], + z: color[2], + alpha: color[3], + } + } + + fn from_f32_array_no_alpha(color: [f32; 3]) -> Self { + Self { + x: color[0], + y: color[1], + z: color[2], + alpha: 1.0, + } + } + + fn from_vec4(color: Vec4) -> Self { + Self { + x: color[0], + y: color[1], + z: color[2], + alpha: color[3], + } + } + + fn from_vec3(color: Vec3) -> Self { + Self { + x: color[0], + y: color[1], + z: color[2], + alpha: 1.0, + } + } +} + impl From for Xyza { fn from( LinearRgba { diff --git a/crates/bevy_ecs/src/event.rs b/crates/bevy_ecs/src/event.rs index 30835e62dd..5f5b7092f0 100644 --- a/crates/bevy_ecs/src/event.rs +++ b/crates/bevy_ecs/src/event.rs @@ -1509,7 +1509,7 @@ mod tests { ); } - #[cfg(feature = "multi-threaded")] + #[cfg(feature = "multi_threaded")] #[test] fn test_events_par_iter() { use std::{collections::HashSet, sync::mpsc}; diff --git a/crates/bevy_pbr/src/render/fog.rs b/crates/bevy_pbr/src/render/fog.rs index 16ae9a1007..1421ddcd6d 100644 --- a/crates/bevy_pbr/src/render/fog.rs +++ b/crates/bevy_pbr/src/render/fog.rs @@ -1,6 +1,6 @@ use bevy_app::{App, Plugin}; use bevy_asset::{load_internal_asset, Handle}; -use bevy_color::LinearRgba; +use bevy_color::{ColorToComponents, LinearRgba}; use bevy_ecs::prelude::*; use bevy_math::{Vec3, Vec4}; use bevy_render::{ @@ -66,24 +66,27 @@ pub fn prepare_fog( match &fog.falloff { FogFalloff::Linear { start, end } => GpuFog { mode: GPU_FOG_MODE_LINEAR, - base_color: LinearRgba::from(fog.color).into(), - directional_light_color: LinearRgba::from(fog.directional_light_color).into(), + base_color: LinearRgba::from(fog.color).to_vec4(), + directional_light_color: LinearRgba::from(fog.directional_light_color) + .to_vec4(), directional_light_exponent: fog.directional_light_exponent, be: Vec3::new(*start, *end, 0.0), ..Default::default() }, FogFalloff::Exponential { density } => GpuFog { mode: GPU_FOG_MODE_EXPONENTIAL, - base_color: LinearRgba::from(fog.color).into(), - directional_light_color: LinearRgba::from(fog.directional_light_color).into(), + base_color: LinearRgba::from(fog.color).to_vec4(), + directional_light_color: LinearRgba::from(fog.directional_light_color) + .to_vec4(), directional_light_exponent: fog.directional_light_exponent, be: Vec3::new(*density, 0.0, 0.0), ..Default::default() }, FogFalloff::ExponentialSquared { density } => GpuFog { mode: GPU_FOG_MODE_EXPONENTIAL_SQUARED, - base_color: LinearRgba::from(fog.color).into(), - directional_light_color: LinearRgba::from(fog.directional_light_color).into(), + base_color: LinearRgba::from(fog.color).to_vec4(), + directional_light_color: LinearRgba::from(fog.directional_light_color) + .to_vec4(), directional_light_exponent: fog.directional_light_exponent, be: Vec3::new(*density, 0.0, 0.0), ..Default::default() @@ -93,8 +96,9 @@ pub fn prepare_fog( inscattering, } => GpuFog { mode: GPU_FOG_MODE_ATMOSPHERIC, - base_color: LinearRgba::from(fog.color).into(), - directional_light_color: LinearRgba::from(fog.directional_light_color).into(), + base_color: LinearRgba::from(fog.color).to_vec4(), + directional_light_color: LinearRgba::from(fog.directional_light_color) + .to_vec4(), directional_light_exponent: fog.directional_light_exponent, be: *extinction, bi: *inscattering,