Feature request: Use a fancy color library like Palette. #1797
Labels
A-Rendering
Drawing game state to the screen
C-Usability
A targeted quality-of-life change that makes Bevy easier to use
What problem does this solve or what need does it fill?
I often find myself doing adding materials like
materials.add(Color::rgb(0.2, 0.3, 0.3).into())
. This seems simple enough... or is it?Color::rgb(0.2, 0.3, 0.3)
is actually not an unambiguous description of a color, because it doesn't describe the color space. (I suspect Bevy assumes sRGB for the color space, but I haven't looked into the code to check.) One alternative to sRGB is Linear sRG, and the same "color values" can look substantially different in each:The apparent difference is caused by how our eyes work. Increasing the intensity of a light by 10% doesn't always make it look 10% brighter. sRGB has something called "gamma correction", where they stretch out the darks (where our eyes are more sensitive) and compress the lights.
Many people are familiar with this because they've played with the "linear color" setting in their game engine. Doing lighting calculations on gamma-corrected values leads to physically inaccurate results:
So when I write
Color::rgb(0.2, 0.3, 0.3)
, it's genuinely unclear to me what that represents (the docs don't say either). And ambiguities like that lead to extremely common bugs by people who should know better (MS Paint, Photoshop, Firefox) when people do calculations like blending gamma-corrected values.What solution would you like?
There are some libraries designed to make it easy to work with colors, and a good one is palette. Using the structs provided by palette, you would write
Srgb::new(0.2, 0.3, 0.3)
. It also comes with many usefulimpl
s on those structs. From the docs:The text was updated successfully, but these errors were encountered: