12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- // https://bottosson.github.io/posts/oklab/
- float cbrtf(float x) {
- return pow(x, 1.0 / 3.0);
- }
- vec3 rgbToOklab(vec3 c)
- {
- float l = 0.4122214708 * c.r + 0.5363325363 * c.g + 0.0514459929 * c.b;
- float m = 0.2119034982 * c.r + 0.6806995451 * c.g + 0.1073969566 * c.b;
- float s = 0.0883024619 * c.r + 0.2817188376 * c.g + 0.6299787005 * c.b;
- float l_ = cbrtf(l);
- float m_ = cbrtf(m);
- float s_ = cbrtf(s);
- return vec3(
- 0.2104542553*l_ + 0.7936177850*m_ - 0.0040720468*s_,
- 1.9779984951*l_ - 2.4285922050*m_ + 0.4505937099*s_,
- 0.0259040371*l_ + 0.7827717662*m_ - 0.8086757660*s_
- );
- }
- vec3 oklabToRGB(vec3 c)
- {
- float l_ = c.x + 0.3963377774 * c.y + 0.2158037573 * c.z;
- float m_ = c.x - 0.1055613458 * c.y - 0.0638541728 * c.z;
- float s_ = c.x - 0.0894841775 * c.y - 1.2914855480 * c.z;
- float l = l_*l_*l_;
- float m = m_*m_*m_;
- float s = s_*s_*s_;
- return vec3(
- +4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
- -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
- -0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s
- );
- }
- #ifndef USE_OKLAB
- #define col3 vec3
- #else
- vec3 col3(float r, float g, float b) {
- return rgbToOklab(vec3(r, g, b));
- }
- vec3 col3(vec3 v) {
- return rgbToOklab(v);
- }
- vec3 col3(float v) {
- return rgbToOklab(vec3(v));
- }
- #endif
|