Relative luminance proposal. #4246
Replies: 2 comments 2 replies
-
The WCAG uses the same formula as Godot for luminance The difference you are seeing there comes from the fact that the WCAG recommends that all content be specified with sRGB encoding, so it needs to be converted to linear before calculating the luminance (see the page on relative luminance and the page on contrast which mentions using sRGB encoding vs other types of encoding). Godot does not assume you are using an sRGB encoding. It assumes that you are using linear encoding when you are working with Colors directly. That being said, in Godot you can quickly convert sRGB encoded colours into linear space using
Remember, there is a world of a difference between a game engine and the Web Content Accessibility Guidelines. A process that works for one may not work for the other. Importantly though, the WCAG does not recommend that linearization and luminance be packaged together in a single function. They say that if the value is in sRGB space, then you need to linearize before applying this formula. |
Beta Was this translation helpful? Give feedback.
-
I mentioned it as I use it often in the engine code, but looking closer now I can see that it is not exposed outside of the engine, which means my suggestion is pretty unhelpful!
This is only true if you assume that every Color is specified in sRGB space. If users are working in linear space already then I think that the best resolution may be to expose |
Beta Was this translation helpful? Give feedback.
-
Replace the
Color.get_luminance()
formula with the WCAG standard relative luminance formula. Or provide an additional function calledget_relative_luminance()
. This is a formula used for the WCAG contrast test. It just needs to be linearized.(Godot 4 Alpha 4)
Color.get_luminance()
https://github.com/godotengine/godot/blob/c8e62555f6005cdec1f2172478724ab4dc6f93ad/core/math/color.h#L97
Beta Was this translation helpful? Give feedback.
All reactions