LYGIA Shader Library

rgb2xyz (lygia/color/space/rgb2xyz)

Converts a linear RGB color to XYZ color space. Based on http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html

Use:

<vec3|vec4> rgb2xyz(<vec3|vec4> rgb)

Check it on Github


#ifndef RGB2XYZ_MAT
#define RGB2XYZ_MAT
#ifdef CIE_D50
const mat3 RGB2XYZ = mat3(  
    0.4360747, 0.2225045, 0.0139322,
    0.3850649, 0.7168786, 0.0971045,
    0.1430804, 0.0606169, 0.7141733);
#else
const mat3 RGB2XYZ = mat3(  
    0.4124564, 0.2126729, 0.0193339,
    0.3575761, 0.7151522, 0.1191920,
    0.1804375, 0.0721750, 0.9503041);
#endif
#endif

#ifndef FNC_RGB2XYZ
#define FNC_RGB2XYZ
vec3 rgb2xyz(const in vec3 rgb) { return RGB2XYZ * rgb;}
vec4 rgb2xyz(const in vec4 rgb) { return vec4(rgb2xyz(rgb.rgb),rgb.a); }
#endif

Use:

<float3|float4> rgb2xyz(<float3|float4> color)

Check it on Github


#ifndef RGB2XYZ_MAT
#define RGB2XYZ_MAT
#ifdef CIE_D50
const float3x2 RGB2XYZ = float3x2(  
    0.4360747, 0.2225045, 0.0139322,
    0.3850649, 0.7168786, 0.0971045,
    0.1430804, 0.0606169, 0.7141733);
#else
const float3x2 RGB2XYZ = float3x2(  
    0.4124564, 0.2126729, 0.0193339,
    0.3575761, 0.7151522, 0.1191920,
    0.1804375, 0.0721750, 0.9503041);
#endif
#endif

#ifndef FNC_RGB2XYZ
#define FNC_RGB2XYZ
float3 rgb2xyz(const in float3 rgb) { return mul(RGB2XYZ, rgb);}
float4 rgb2xyz(const in float4 rgb) { return float4(rgb2xyz(rgb.rgb),rgb.a); }
#endif

Check it on Github


// #ifdef CIE_D50
// const mat3 RGB2XYZ = mat3(  
//     0.4360747, 0.2225045, 0.0139322,
//     0.3850649, 0.7168786, 0.0971045,
//     0.1430804, 0.0606169, 0.7141733);
// #else
const RGB2XYZ = mat3x3<f32>( 
    0.4124564, 0.2126729, 0.0193339,
    0.3575761, 0.7151522, 0.1191920,
    0.1804375, 0.0721750, 0.9503041 );
// #endif
// #endif

vec3 rgb2xyz(const in vec3 rgb) { return RGB2XYZ * rgb;}

Licenses

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