LYGIA Shader Library

xyz2rgb (lygia/color/space/xyz2rgb)

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

Use:

xyz2rgb(<vec3|vec4> color)

Check it on Github


#ifndef MAT_XYZ2RGB
#define MAT_XYZ2RGB
#ifdef CIE_D50
const mat3 XYZ2RGB = mat3(
     3.1338561,-0.9787684, 0.0719453,
    -1.6168667, 1.9161415,-0.2289914,
    -0.4906146, 0.0334540, 1.4052427
);
#else
// CIE D65
const mat3 XYZ2RGB = mat3(
     3.2404542,-0.9692660, 0.0556434,
    -1.5371385, 1.8760108,-0.2040259,
    -0.4985314, 0.0415560, 1.0572252
);
#endif
#endif

#ifndef FNC_XYZ2RGB
#define FNC_XYZ2RGB
vec3 xyz2rgb(const in vec3 xyz) { return XYZ2RGB * (xyz * 0.01); }
vec4 xyz2rgb(const in vec4 xyz) { return vec4(xyz2rgb(xyz.rgb), xyz.a); }
#endif

Use:

xyz2rgb(<float3|float4> color)

Check it on Github


#ifndef MAT_XYZ2RGB
#define MAT_XYZ2RGB
#ifdef CIE_D50
const float3x3 XYZ2RGB = float3x3(
     3.1338561,-0.9787684, 0.0719453,
    -1.6168667, 1.9161415,-0.2289914,
    -0.4906146, 0.0334540, 1.4052427
);
#else
// CIE D65
const float3x3 XYZ2RGB = float3x3(
     3.2404542,-0.9692660, 0.0556434,
    -1.5371385, 1.8760108,-0.2040259,
    -0.4985314, 0.0415560, 1.0572252
);
#endif
#endif

#ifndef FNC_XYZ2RGB
#define FNC_XYZ2RGB
float3 xyz2rgb(float3 xyz) { return mul(XYZ2RGB, xyz * 0.01); }
float4 xyz2rgb(float4 xyz) { return float4(xyz2rgb(xyz.rgb), xyz.a); }
#endif

Check it on Github


const XYZ2RGB = mat3x3<f32>(    vec3f( 3.2404542, -0.9692660,  0.0556434),
                                vec3f(-1.5371385,  1.8760108, -0.2040259),
                                vec3f(-0.4985314,  0.0415560,  1.0572252) );

fn xyz2rgb(xyz: vec3f) -> vec3f { return XYZ2RGB * (xyz * 0.01); }

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