Replies: 2 comments 11 replies
-
Currently, all operations happen in the space of the left hand side color Some thoughts:
|
Beta Was this translation helpful? Give feedback.
-
My opinion is that color spaces should not be types, they should be data. I wrote the following in Discord, which should be somewhat relevant but also slightly off-topic. ... I've been diving deep into color management for game engines recently, and more specifically on how to handle wide-color gamuts and HDR.
let srgb = Color::new(r, g, b, spaces::SRGB);
let oklab = srgb.to(spaces::OKLAB);
let srgb_again = oklab.to(spaces::SRGB); if you want to use your own storage type: let conversion = ColorConversion::new(spaces::SRGB, spaces::OKLAB);
...
conversion.apply(&mut my_vec3); It's still a bit of a draft crate but I think it already makes colors a lot easier than the alternatives in Rust. When you treat colors as 3-component coordinates instead of some typed structure, add/mul/lerp in a single color space are obvious, and When it comes to lerp of colors (gradients), you usually want to do it in a perceptual color space like Oklab. The great Ralph Levien has a nice interactive lerp visualization on his blog: https://raphlinus.github.io/color/2021/01/18/oklab-critique.html On another note: My opinion for how to deal with color management in an engine is that the engine should define a "RenderRgb" or "LinearRgb" (and *Rgba) that stores colors in the engine's linear rendering color space (linear sRGB right now, I'd propose P3 for WCG rendering). All colors in assets should be converted to the renderer's color space on import (even if sRGB gamma compensation is applied to textures after import, it'll end up correct when sampling), and all other color inputs should use proper color management such that when they end up on the GPU, they're in the correct space. The last part is fairly trivial if you use something like the |
Beta Was this translation helpful? Give feedback.
-
Operations like add, mul and lerp for
Color
in bevy 0.5 can't be properly defined.Here is the problem:
Gradient
andCurve<Color>
, can't mix and match keyframes in different color spaces because lerp operation doesn't know in witch space they should happen and will needHow I think this should be:
Using something like
Curve<OkLAB>
is much more telling and predictable;Further more
We care about the color space because of the operations inside each color space yield different results (that artistically impacts our game); At the end of the day every color will converted down to color space used by the renderer which is in our case is the linear RGB color space, so why not store it that way before sending to the GPU.
Have the ability of keep colors in HSL adds little value. Plus its possible to easely create a variant
ColorHSVMaterial
at the user level, it could use the same shaders, and should be a plug-in in an external crate.Color operations are now way more expensive that they should be,
match
is a language construct and is not for free (can't be always complied away);A gradient in any color space can be converted down to a sRGB texture or even other gradient and sampled from that;
Beta Was this translation helpful? Give feedback.
All reactions