lygia
/v1.1.6
/color
/space
/lab2xyz
)Converts a Lab color to XYZ color space.
Use:
rgb2xyz(<vec3|vec4> color)
#ifndef FNC_LAB2XYZ
#define FNC_LAB2XYZ
vec3 lab2xyz(in vec3 c) {
vec3 f = vec3(0.0);
f.y = (c.x + 16.0) / 116.0;
f.x = c.y / 500.0 + f.y;
f.z = f.y - c.z / 200.0;
vec3 c0 = f * f * f;
vec3 c1 = (f - 16.0 / 116.0) / 7.787;
return vec3(95.047, 100.000, 108.883) * mix(c0, c1, step(f, vec3(0.206897)));
}
vec4 lab2xyz(in vec4 c) { return vec4(lab2xyz(c.xyz), c.w); }
#endif
Use:
rgb2xyz(<float3|float4> color)
#ifndef FNC_LAB2XYZ
#define FNC_LAB2XYZ
float3 lab2xyz(in float3 c) {
float3 f = float3(0.0, 0.0, 0.0);
f.y = (c.x + 16.0) / 116.0;
f.x = c.y / 500.0 + f.y;
f.z = f.y - c.z / 200.0;
float3 c0 = f * f * f;
float3 c1 = (f - 16.0 / 116.0) / 7.787;
return float3(95.047, 100.000, 108.883) * lerp(c0, c1, step(f, float3(0.206897, 0.206897, 0.206897)));
}
float4 lab2xyz(in float4 c) { return float4(lab2xyz(c.xyz), c.w); }
#endif
fn lab2xyz(c : vec3<f32>) -> vec3<f32> {
var f = vec3<f32>(0.0);
f.y = (c.x + 16.0) / 116.0;
f.x = c.y / 500.0 + f.y;
f.z = f.y - c.z / 200.0;
let c0 = f * f * f;
let c1 = (f - 16.0 / 116.0) / 7.787;
return vec3<f32>(95.047, 100.000, 108.883) * mix(c0, c1, step(f, vec3<f32>(0.206897)));
}
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