Skip to content

Commit 94ed750

Browse files
authored
More UI gradients fixes (#20035)
# Objective Improve the gradients implementation further. ## Solution More UI gradients improvements: * Use the more accurate gamma correction function from #12939. * Fixed hsl and hsv conversion functions. * Ignore hues and don't interpolate if the chroma or saturation is close to zero. before: <img width="239" alt="colors" src="https://github.com/user-attachments/assets/39443400-e550-49f5-a7de-4a07c5fe537a" /> after: <img width="194" alt="image" src="https://github.com/user-attachments/assets/a5977b97-aa1d-4254-9ef3-0d2355f2ab18" /> ## Testing The `testbed_ui` and `gradients` examples can be used for testing.
1 parent 647b071 commit 94ed750

File tree

3 files changed

+259
-131
lines changed

3 files changed

+259
-131
lines changed

crates/bevy_ui_render/src/gradient.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,8 @@ fn convert_color_to_space(color: LinearRgba, space: InterpolationColorSpace) ->
665665
[
666666
oklcha.lightness,
667667
oklcha.chroma,
668-
oklcha.hue.to_radians(),
668+
// The shader expects normalized hues
669+
oklcha.hue / 360.,
669670
oklcha.alpha,
670671
]
671672
}
@@ -676,18 +677,13 @@ fn convert_color_to_space(color: LinearRgba, space: InterpolationColorSpace) ->
676677
InterpolationColorSpace::LinearRgba => color.to_f32_array(),
677678
InterpolationColorSpace::Hsla | InterpolationColorSpace::HslaLong => {
678679
let hsla: Hsla = color.into();
679-
// Normalize hue to 0..1 range for shader
680-
[
681-
hsla.hue / 360.0,
682-
hsla.saturation,
683-
hsla.lightness,
684-
hsla.alpha,
685-
]
680+
// The shader expects normalized hues
681+
[hsla.hue / 360., hsla.saturation, hsla.lightness, hsla.alpha]
686682
}
687683
InterpolationColorSpace::Hsva | InterpolationColorSpace::HsvaLong => {
688684
let hsva: Hsva = color.into();
689-
// Normalize hue to 0..1 range for shader
690-
[hsva.hue / 360.0, hsva.saturation, hsva.value, hsva.alpha]
685+
// The shader expects normalized hues
686+
[hsva.hue / 360., hsva.saturation, hsva.value, hsva.alpha]
691687
}
692688
}
693689
}

0 commit comments

Comments
 (0)