LYGIA Shader Library

rgb2lms (lygia/color/space/rgb2lms)

Convert rgb to LMS. LMS (long, medium, short), is a color space which represents the response of the three types of cones of the human eye, named for their responsivity (sensitivity) peaks at long, medium, and short wavelengths. Refs https://en.wikipedia.org/wiki/LMS_color_space https://arxiv.org/pdf/1711.10662

Use:

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

Check it on Github


#ifndef MAT_RGB2LMS
#define MAT_RGB2LMS
// const mat3 RGB2LMS = mat3(
//     3.90405e-1, 5.49941e-1, 8.92632e-3,
//     7.08416e-2, 9.63172e-1, 1.35775e-3,
//     2.31082e-2, 1.28021e-1, 9.36245e-1
// );
const mat3 RGB2LMS = mat3(
    17.8824,  3.45565,  0.0299566,
    43.5161, 27.1554,   0.184309,
    4.11935,  0.184309, 1.46709
);
#endif

#ifndef FNC_RGB2LMS
#define FNC_RGB2LMS
vec3 rgb2lms(const in vec3 rgb) {return RGB2LMS * rgb;}
vec4 rgb2lms(const in vec4 rgb) { return vec4(rgb.rgb, rgb.a); }
#endif

Use:

<float3|float4> rgb2lms(<float3|float4> rgb)

Check it on Github


#ifndef MAT_RGB2LMS
#define MAT_RGB2LMS
// const float3x3 RGB2LMS = float3x3(
//     3.90405e-1, 5.49941e-1, 8.92632e-3,
//     7.08416e-2, 9.63172e-1, 1.35775e-3,
//     2.31082e-2, 1.28021e-1, 9.36245e-1
// );

const float3x3 RGB2LMS = float3x3(
    17.8824,  3.45565,  0.0299566,
    43.5161, 27.1554,   0.184309,
    4.11935,  0.184309, 1.46709
);
#endif

#ifndef FNC_RGB2LMS
#define FNC_RGB2LMS
float3 rgb2lms(float3 rgb) { return mul(RGB2LMS, rgb); }
float4 rgb2lms(float4 rgb) { return float4( rgb2lms(rgb.rgb), rgb.a); }
#endif

Check it on Github

// const RGB2LMS = mat3x3<f32>(
//     vec3f(3.90405e-1, 5.49941e-1, 8.92632e-3),
//     vec3f(7.08416e-2, 9.63172e-1, 1.35775e-3),
//     vec3f(2.31082e-2, 1.28021e-1, 9.36245e-1)
// );

const RGB2LMS = mat3x3<f32>(
    vec3f(17.8824,  3.45565,  0.0299566),
    vec3f(43.5161, 27.1554,   0.184309),
    vec3f(4.11935,  0.184309, 1.46709)
);

fn rgb2lms(rgb: vec3f) -> vec3f { return RGB2LMS * rgb; }

License

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