Skip to content

More UI gradients fixes #20035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

ickshonpe
Copy link
Contributor

@ickshonpe ickshonpe commented Jul 8, 2025

Objective

Improve the gradients implementation further.

Solution

More UI gradients improvements:

  • Use the more accurate gamma correction function from Shader color conversion #12939.
  • Fixed hsl and hsv conversion functions.
  • Ignore hues and don't interpolate if the chroma or saturation is close to zero.

before:
colors

after:
image

Testing

The testbed_ui and gradients examples can be used for testing.

@ickshonpe ickshonpe requested a review from viridia July 8, 2025 16:57
@alice-i-cecile alice-i-cecile added this to the 0.17 milestone Jul 8, 2025
@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen A-UI Graphical user interfaces, styles, layouts, and widgets labels Jul 8, 2025
@alice-i-cecile alice-i-cecile requested a review from tychedelia July 8, 2025 16:57
@alice-i-cecile alice-i-cecile added the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Jul 8, 2025
Copy link
Contributor

github-actions bot commented Jul 8, 2025

Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-20035

If it's expected, please add the M-Deliberate-Rendering-Change label.

If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it.

@ickshonpe ickshonpe added the M-Deliberate-Rendering-Change An intentional change to how tests and examples are rendered label Jul 8, 2025
@viridia
Copy link
Contributor

viridia commented Jul 8, 2025

It occurs to me that the Long variants wouldn't be necessary if we allowed negative hues, or more broadly, hues outside of the range of 0..360. So for example if I wanted to interpolate the shortest path from purple to red, I could go from a hue of -10 to positive 10.

This is a lot like the way animation keyframes work: If I have a rotating sub-mesh, and I want to set up a keyframe where it rotates 3 times, I will set a rotation of PI * 2 * 3.

I recognize that there are some problems with this, as it might be less intuitive; but the upside is that the results would be more predictable.

@ickshonpe
Copy link
Contributor Author

ickshonpe commented Jul 8, 2025

It occurs to me that the Long variants wouldn't be necessary if we allowed negative hues, or more broadly, hues outside of the range of 0..360. So for example if I wanted to interpolate the shortest path from purple to red, I could go from a hue of -10 to positive 10.

This is a lot like the way animation keyframes work: If I have a rotating sub-mesh, and I want to set up a keyframe where it rotates 3 times, I will set a rotation of PI * 2 * 3.

I recognize that there are some problems with this, as it might be less intuitive; but the upside is that the results would be more predictable.

Positive values are reduced modulo 360, so you can use:

vec![
    ColorStop::auto(Hsla::new(480., 1., 0.5, 1.)),
    ColorStop::auto(Hsla::new(960., 1., 0.5, 1.)),
]

to define a gradient from green to blue, it's just negative values that seem to be clamped from below to zero. I'm not sure why, it might not even be intentional.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior M-Deliberate-Rendering-Change An intentional change to how tests and examples are rendered S-Needs-Review Needs reviewer attention (from anyone!) to move forward
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants