-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Add Color::lerp()
convenience method for interpolating/mixing colors
#10332
Conversation
You often don't want a "mathematically correct" interpolation between colors, but a "perceptually correct" one: https://raphlinus.github.io/color/2021/01/18/oklab-critique.html Marking as controversial, as lerping colors as been a hot topic for a while (#1402 #8189 or many discutions on discord) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A doc example/test could be nice here, otherwise LGTM :)
Perhaps, the function should take colorspace as 4th parameter? That would decide how much user would care about performance (sRGB) vs perceptual correctness (Oklab). |
#9698 also adds ability to lerp colors |
/// | ||
/// **Note:** To ensure mathematically correct results, interpolation takes place in linear RGB | ||
/// colorspace. Both `self` and `rhs` will be converted as necessary, before the operation. | ||
#[doc(alias = "mix")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add multiple doc aliases? If so, we should add "blend" as well.
/// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly | ||
/// extrapolated. | ||
/// | ||
/// **Note:** To ensure mathematically correct results, interpolation takes place in linear RGB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// **Note:** To ensure mathematically correct results, interpolation takes place in linear RGB | |
/// Interpolation takes place in linear RGB |
This should be fixed now, with the addition of bevy_color. |
🎃🦇🎃🦇🎃🦇🎃🦇🎃🦇🎃🦇
Objective
Color::AQUAMARINE * 0.6 + Color::DARK_GREEN * 0.4
;Solution
Color::lerp()
method.Changelog
Color::lerp()
convenience method for interpolating colors. Colors are interpolated in linear RGB space for mathematically correct results.