Add Color::lerp() convenience method for interpolating/mixing colors#10332
Add Color::lerp() convenience method for interpolating/mixing colors#10332coreh wants to merge 1 commit intobevyengine:mainfrom
Color::lerp() convenience method for interpolating/mixing colors#10332Conversation
|
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) |
TimJentzsch
left a comment
There was a problem hiding this comment.
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.
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.
| /// **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.