Shader color conversion
Objective
- Fixes #12201
Solution
- Adds
color_conversion.wgslcontaining methods for converting between allbevy_colorcolor types in shader code.- Please note that this shader is contained in the
bevy_rendercrate (notbevy_color), as this would introduce cyclic dependency. - All conversion methods are equivelant to their Rust versions in
bevy_color.
- Please note that this shader is contained in the
- Currently all colors can be converted from and to LinearRgb(a) and to all internediate steps according to the diagram in
bevy_color - The conversion methods can be imported in any WGSL shader using e.g.
#import bevy_render::color_conversion::linear_rgba_to_xyza
Additional information
I am not sure how discoverable WGSL imports are. The examples demonstrate some use cases, but if available WGSL imports are documented somewhere, I have missed that.
I'm not familiar enough with WGSL to comment on how good the exact implementation is, but is there a way you could add tests for these methods that compare to the Rust implementations in
bevy_color? Sincebevy_coloris already independently implemented and tested againstpalette, if the conversions here agree there, I'd say it's good to go.I believe it would be the first instance of such a testing setup, and would involve a decent bit of setup for the boilerplate of a test, so I'm not sure if you'd want to add that to this PR. I think there would be value in such a testing framework for other utility shaders as well, but again I'm not certain.
I like this idea, but I think, this is way beyond the scope of this PR. If it's fine with you, I would look into this and add such tests in a follow up PR
I think that's perfectly fine, I agree it's quite a bit of work!
Can you fix the conflicts?
Also, what's the use case for this? Shouldn't color conversion be done before it ends up on the gpu?