lygia
/v1.1.6
/color
/space
/rgb2oklab
)linear rgb ot OKLab https://bottosson.github.io/posts/oklab/
Use:
<vec3\vec4> rgb2oklab(<vec3|vec4> srgb)
#ifndef FNC_RGB2OKLAB
#define FNC_RGB2OKLAB
const mat3 inv_oklab_A = mat3( 0.2104542553, 1.9779984951, 0.0259040371,
0.7936177850, -2.4285922050, 0.7827717662,
-0.0040720468, 0.4505937099, -0.8086757660);
const mat3 inv_oklab_B = mat3( 0.4121656120, 0.2118591070, 0.0883097947,
0.5362752080, 0.6807189584, 0.2818474174,
0.0514575653, 0.1074065790, 0.6302613616);
vec3 rgb2oklab(vec3 linear) {
vec3 lms = inv_oklab_B * linear;
return inv_oklab_A * (sign(lms)*pow(abs(lms), vec3(0.3333333333333)));
}
vec4 rgb2oklab(vec4 linear) {
return vec4(rgb2oklab(linear.rgb), linear.a);
}
#endif
Use:
<float3\float4> rgb2oklab(<float3|float4> srgb)
#ifndef FNC_RGB2OKLAB
#define FNC_RGB2OKLAB
const float3x3 inv_oklab_A = float3x3( 0.2104542553, 1.9779984951, 0.0259040371,
0.7936177850, -2.4285922050, 0.7827717662,
-0.0040720468, 0.4505937099, -0.8086757660);
const float3x3 inv_oklab_B = float3x3( 0.4121656120, 0.2118591070, 0.0883097947,
0.5362752080, 0.6807189584, 0.2818474174,
0.0514575653, 0.1074065790, 0.6302613616);
float3 rgb2oklab(float3 rgb) {
float3 lms = mul(inv_oklab_B, rgb);
return mul(inv_oklab_A, sign(lms)*pow(abs(lms), float3(0.3333333333333)));
}
float4 rgb2oklab(float4 rgb) {
return float4(rgb2oklab(rgb.rgb), rgb.a);
}
#endif
const inv_oklab_A : mat3x3<f32> = mat3x3<f32>( vec3<f32>(0.2104542553, 1.9779984951, 0.0259040371),
vec3<f32>(0.7936177850, -2.4285922050, 0.7827717662),
vec3<f32>(-0.0040720468, 0.4505937099, -0.8086757660) );
const inv_oklab_B : mat3x3<f32> = mat3x3<f32>( vec3<f32>(0.4121656120, 0.2118591070, 0.0883097947),
vec3<f32>(0.5362752080, 0.6807189584, 0.2818474174),
vec3<f32>(0.0514575653, 0.1074065790, 0.6302613616) );
fn rgb2oklab(linear: vec3<f32>) -> vec3<f32> {
let lms = inv_oklab_B * linear;
return inv_oklab_A * (sign(lms) * pow(abs(lms), vec3<f32>(0.3333333333333)));
}
LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.
Sponsors and contributors are automatically added to the Patron License and they can ignore the any non-commercial rule of the Prosperity Licensed software (please take a look to the exception).
It's also possible to get a permanent comercial license hook to a single and specific version of LYGIA.
Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository