@@ -7,7 +7,7 @@ use core::{
7
7
use super :: shader_flags:: BORDER_ALL ;
8
8
use crate :: * ;
9
9
use bevy_asset:: * ;
10
- use bevy_color:: { ColorToComponents , LinearRgba } ;
10
+ use bevy_color:: { ColorToComponents , Hsla , Hsva , LinearRgba , Oklaba , Oklcha , Srgba } ;
11
11
use bevy_ecs:: {
12
12
prelude:: Component ,
13
13
system:: {
@@ -654,6 +654,36 @@ struct UiGradientVertex {
654
654
hint : f32 ,
655
655
}
656
656
657
+ fn convert_color_to_space ( color : LinearRgba , space : InterpolationColorSpace ) -> [ f32 ; 4 ] {
658
+ match space {
659
+ InterpolationColorSpace :: OkLab => {
660
+ let oklaba: Oklaba = color. into ( ) ;
661
+ [ oklaba. lightness , oklaba. a , oklaba. b , oklaba. alpha ]
662
+ }
663
+ InterpolationColorSpace :: OkLch | InterpolationColorSpace :: OkLchLong => {
664
+ let oklcha: Oklcha = color. into ( ) ;
665
+ [ oklcha. lightness , oklcha. chroma , oklcha. hue . to_radians ( ) , oklcha. alpha ]
666
+ }
667
+ InterpolationColorSpace :: Srgb => {
668
+ let srgba: Srgba = color. into ( ) ;
669
+ [ srgba. red , srgba. green , srgba. blue , srgba. alpha ]
670
+ }
671
+ InterpolationColorSpace :: LinearRgb => {
672
+ color. to_f32_array ( )
673
+ }
674
+ InterpolationColorSpace :: Hsl | InterpolationColorSpace :: HslLong => {
675
+ let hsla: Hsla = color. into ( ) ;
676
+ // Normalize hue to 0..1 range for shader
677
+ [ hsla. hue / 360.0 , hsla. saturation , hsla. lightness , hsla. alpha ]
678
+ }
679
+ InterpolationColorSpace :: Hsv | InterpolationColorSpace :: HsvLong => {
680
+ let hsva: Hsva = color. into ( ) ;
681
+ // Normalize hue to 0..1 range for shader
682
+ [ hsva. hue / 360.0 , hsva. saturation , hsva. value , hsva. alpha ]
683
+ }
684
+ }
685
+ }
686
+
657
687
pub fn prepare_gradient (
658
688
mut commands : Commands ,
659
689
render_device : Res < RenderDevice > ,
@@ -804,8 +834,8 @@ pub fn prepare_gradient(
804
834
continue ;
805
835
}
806
836
}
807
- let start_color = start_stop. 0 . to_f32_array ( ) ;
808
- let end_color = end_stop. 0 . to_f32_array ( ) ;
837
+ let start_color = convert_color_to_space ( start_stop. 0 , gradient . color_space ) ;
838
+ let end_color = convert_color_to_space ( end_stop. 0 , gradient . color_space ) ;
809
839
let mut stop_flags = flags;
810
840
if 0. < start_stop. 1
811
841
&& ( stop_index == gradient. stops_range . start || segment_count == 0 )
0 commit comments