LYGIA Shader Library

rgb2xyz (lygia/v1.1.6/color/space/rgb2xyz)

Converts a RGB color to XYZ color space.

Dependencies:

Use:

rgb2xyz(<vec3|vec4> color)

Check it on Github



#ifndef FNC_RGB2XYZ
#define FNC_RGB2XYZ
vec3 rgb2xyz(in vec3 c) {
    const mat3 mat = mat3(  0.4124564, 0.2126729, 0.0193339,
                            0.3575761, 0.7151522, 0.1191920,
                            0.1804375, 0.0721750, 0.9503041);
    vec3 c0 = gamma2linear((c + 0.055) / 1.055);
    vec3 c1 = c / 12.92;
    vec3 tmp = mix(c0, c1, step(c, vec3(0.04045)));
    return mat * (100.0 * tmp);
}

vec4 rgb2xyz(in vec4 rgb) { return vec4(rgb2xyz(rgb.rgb),rgb.a); }
#endif

Dependencies:

Use:

rgb2xyz(<float3|float4> color)

Check it on Github



#ifndef FNC_RGB2XYZ
#define FNC_RGB2XYZ
float3 rgb2xyz(in float3 c) {
    const float3x3 mat = float3x3(  0.4124564, 0.2126729, 0.0193339,
                                    0.3575761, 0.7151522, 0.1191920,
                                    0.1804375, 0.0721750, 0.9503041);
    float3 c0 = gamma2linear((c + 0.055) / 1.055);
    float3 c1 = c / 12.92;
    float3 tmp = lerp(c0, c1, step(c, float3(0.04045)));
    return mul(mat, 100.0 * tmp);
}

float4 rgb2xyz(in float4 rgb) { return float4(rgb2xyz(rgb.rgb),rgb.a); }
#endif

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.

Get the latest news and releases

Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository