LYGIA Shader Library

lms2rgb (lygia/color/space/lms2rgb)

Convert LST to RGB. 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> lms2rgb(<vec3|vec4> lms)

Check it on Github


#ifndef MAT_LMS2RGB
#define MAT_LMS2RGB
// const mat3 LMS2RGB = mat3(
//     2.85847e+0, -1.62879e+0, -2.48910e-2,
//     -2.10182e-1,  1.15820e+0,  3.24281e-4,
//     -4.18120e-2, -1.18169e-1,  1.06867e+0
// );
const mat3 LMS2RGB = mat3(
    0.0809444479,  -0.0102485335,  -0.000365296938,
    -0.13050440,     0.0540193266,  -0.00412161469,
    0.116721066,   -0.113614708,    0.693511405
);
#endif

#ifndef FNC_LMS2RGB
#define FNC_LMS2RGB
vec3 lms2rgb(const in vec3 lms) { return LMS2RGB * lms; }
vec4 lms2rgb(const in vec4 lms) { return vec4( lms2rgb(lms.xyz), lms.a ); }
#endif

Use:

<float3\float4> lms2rgb(<float3|float4> lms)

Check it on Github


#ifndef MAT_LMS2RGB
#define MAT_LMS2RGB
// static const float3x3 LMS2RGB = float3x3(
//     2.85847e+0, -1.62879e+0, -2.48910e-2,
//     -2.10182e-1,  1.15820e+0,  3.24281e-4,
//     -4.18120e-2, -1.18169e-1,  1.06867e+0
// );
static const float3x3 LMS2RGB = float3x3(
        0.0809444479,  -0.0102485335,  -0.000365296938,
    -0.13050440,     0.0540193266,  -0.00412161469,
        0.116721066,   -0.113614708,    0.693511405
);
#endif


#ifndef FNC_LMS2RGB
#define FNC_LMS2RGB
float3 lms2rgb(float3 lms) { return mul(LMS2RGB, lms); }
float4 lms2rgb(float4 lms) { return float4( lms2rgb(lms.xyz), lms.a ); }
#endif

Use:

<float3\float4> lms2rgb(<float3|float4> lms)

Check it on Github


#ifndef MAT_LMS2RGB
#define MAT_LMS2RGB
// constant matrix<float, 3, 3> LMS2RGB = matrix<float, 3, 3>(
//     2.85847e+0, -1.62879e+0, -2.48910e-2,
//     -2.10182e-1,  1.15820e+0,  3.24281e-4,
//     -4.18120e-2, -1.18169e-1,  1.06867e+0
// );
constant matrix<float, 3, 3> LMS2RGB = matrix<float, 3, 3>(
    0.0809444479,  -0.0102485335,  -0.000365296938,
    -0.13050440,     0.0540193266,  -0.00412161469,
    0.116721066,   -0.113614708,    0.693511405
);
#endif

#ifndef FNC_LMS2RGB
#define FNC_LMS2RGB
float3 lms2rgb( float3 lms) { return LMS2RGB * lms; }
float4 lms2rgb( float4 lms) { return float4( lms2rgb(lms.xyz), lms.a ); }
#endif

Check it on Github


// const LMS2RGB = mat3x3<f32>(
//     vec3f(2.85847e+0, -1.62879e+0, -2.48910e-2),
//     vec3f(-2.10182e-1,  1.15820e+0,  3.24281e-4),
//     vec3f(-4.18120e-2, -1.18169e-1,  1.06867e+0)
// );

const LMS2RGB = mat3x3<f32>(
    vec3f( 0.0809444479,  -0.0102485335,  -0.000365296938),
    vec3f(-0.13050440,     0.0540193266,  -0.00412161469),
    vec3f( 0.116721066,   -0.113614708,    0.693511405)
);

fn lms2rgb(lms : vec3f) -> vec3f { return LMS2RGB * lms; }

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