lygia
/v1.1.6
/color
/space
/xyz2rgb
)Converts a XYZ color to RGB color space.
Dependencies:
lygia
/v1.1.6
/color
/space
/linear2gamma
.glsl
Use:
xyz2rgb(<vec3|vec4> color)
#ifndef FNC_XYZ2RGB
#define FNC_XYZ2RGB
vec3 xyz2rgb(in vec3 c) {
const mat3 mat = mat3( 3.2404542, -0.9692660, 0.0556434,
-1.5371585, 1.8760108, -0.2040259,
-0.4985314, 0.0415560, 1.0572252);
vec3 v = mat * (c / 100.0);
vec3 c0 = (1.055 * linear2gamma(v)) - 0.055;
vec3 c1 = 12.92 * v;
vec3 r = mix(c0, c1, step(v, vec3(0.0031308)));
return r;
}
vec4 xyz2rgb(in vec4 xyz) { return vec4(xyz2rgb(xyz.rgb), xyz.a); }
#endif
Dependencies:
lygia
/v1.1.6
/color
/space
/linear2gamma
.glsl
Use:
xyz2rgb(<float3|float4> color)
#ifndef FNC_XYZ2RGB
#define FNC_XYZ2RGB
float3 xyz2rgb(in float3 c) {
const float3x3 mat = float3x3( 3.2404542, -0.9692660, 0.0556434,
-1.5371585, 1.8760108, -0.2040259,
-0.4985314, 0.0415560, 1.0572252);
float3 v = mul(mat, c / 100.0);
float3 c0 = (1.055 * linear2gamma(v)) - 0.055;
float3 c1 = 12.92 * v;
float3 r = lerp(c0, c1, step(v, float3(0.0031308)));
return r;
}
float4 xyz2rgb(in float4 xyz) { return float4(xyz2rgb(xyz.rgb), xyz.a); }
#endif
Dependencies:
lygia
/v1.1.6
/color
/space
/linear2gamma
.glsl
vec3 xyz2rgb(in vec3 c) {
const M = mat3x3<f32>( vec3<f32>(3.2404542, -0.9692660, 0.0556434),
vec3<f32>(-1.5371585, 1.8760108, -0.2040259),
vec3<f32>(-0.4985314, 0.0415560, 1.0572252));
let v = M * (c / 100.0);
let c0 = (1.055 * linear2gamma(v)) - 0.055;
let c1 = 12.92 * v;
return mix(c0, c1, step(v, vec3<f32>(0.0031308)));
}
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