Remove ambiguous Color math implementations#3925
Remove ambiguous Color math implementations#3925Sliman4 wants to merge 1 commit intobevyengine:mainfrom
Conversation
Quick note, haven't read the code here just yet. How would this translate for HDR colors? Or is this strictly talking about HSLA? This was briefly discussed regarding setting up linear interpolation for color for animation, where these operations across color spaces is ill-defined and lossy. See #1870. |
alice-i-cecile
left a comment
There was a problem hiding this comment.
I would very much like a proper color interpolation solution. These impls however are inconsistent and largely incorrect. I agree that these should be removed to avoid confusing users.
I'm not very familiar with how HDR is implemented in bevy, but I made no logic changes to |
|
Values > 1.0 are allowed for linear colours and there is tonemapping code in the shaders that handles mapping HDR values where the colour value is > 1.0 to within 0.0 to 1.0. The bloom PR also specifically benefits from values > 1.0 and it will be common to set emissive values > 1.0 I think, in order for the light to bloom to the surroundings. That is to say that I've used the Mul implementation for Color at least. |
|
Thanks for the context. Closing this out, in favor of a new issue. |
Objective
The implementations are very ambiguous, and it's easy to make bugs using them, especially Hsla variant. They treat
ColorasVec4, which isn't quite right. Color values should be clamped to[0.0,1.0], but there are no checks. It adds/multiplies the first 3 values, regardless of the color's variant (There's no reason why you should multiply 3 values ofHslat once). Also, I (and maybe some other people) initially thoughtColor::GREEN * 0.5would result in semi-transparent green, but it makes it darker instead, so it makes it hard to read.Mul<f32>example (but the same errors apply to every other implementation):Solution
Remove it! It's only used by 1 example (btw it's multiplying ORANGE_RED by 2 making .r() == 2.0, which is a bug, but the renderer somehow handles it).