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)
#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)
#ifndef RGB2XYZ_MAT
#define RGB2XYZ_MAT
#ifdef CIE_D50
static const float3x2 RGB2XYZ = float3x2(
0.4360747, 0.2225045, 0.0139322,
0.3850649, 0.7168786, 0.0971045,
0.1430804, 0.0606169, 0.7141733);
#else
static 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
Use:
<float3|float4> rgb2xyz(<float3|float4> rgb)
#ifndef RGB2XYZ_MAT
#define RGB2XYZ_MAT
#ifdef CIE_D50
constant matrix<float, 3, 3> RGB2XYZ = matrix<float, 3, 3>(
0.4360747, 0.2225045, 0.0139322,
0.3850649, 0.7168786, 0.0971045,
0.1430804, 0.0606169, 0.7141733);
#else
constant matrix<float, 3, 3> RGB2XYZ = matrix<float, 3, 3>(
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( float3 rgb) { return RGB2XYZ * rgb;}
float4 rgb2xyz( float4 rgb) { return float4(rgb2xyz(rgb.rgb),rgb.a); }
#endif
// #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;}
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