LYGIA Shader Library

yuv2rgb (lygia/color/space/yuv2rgb)

Pass a color in YUB and get RGB color

Use:

yuv2rgb(<vec3|vec4> color)

Check it on Github


#ifndef MAT_YUV2RGB
#define MAT_YUV2RGB
#ifdef YUV_SDTV
const mat3 YUV2RGB = mat3(
    1.0,       1.0,      1.0,
    0.0,      -0.39465,  2.03211,
    1.13983,  -0.58060,  0.0
);
#else
const mat3 YUV2RGB = mat3(
    1.0,       1.0,      1.0,
    0.0,      -0.21482,  2.12798,
    1.28033,  -0.38059,  0.0
);
#endif
#endif

#ifndef FNC_YUV2RGB
#define FNC_YUV2RGB
vec3 yuv2rgb(const in vec3 yuv) { return YUV2RGB * yuv; }
vec4 yuv2rgb(const in vec4 yuv) { return vec4(yuv2rgb(yuv.rgb), yuv.a); }
#endif

Use:

yuv2rgb(<float3|float4> color)

Check it on Github


#ifndef MAT_YUV2RGB
#define MAT_YUV2RGB
#ifdef YUV_SDTV
const float3x3 YUV2RGB = float3x3(
    1.0,       1.0,      1.0,
    0.0,      -0.39465,  2.03211,
    1.13983,  -0.58060,  0.0
);
#else
const float3x3 YUV2RGB = float3x3(
    1.0,       1.0,      1.0,
    0.0,      -0.21482,  2.12798,
    1.28033,  -0.38059,  0.0
);
#endif
#endif

#ifndef FNC_YUV2RGB
#define FNC_YUV2RGB
float3 yuv2rgb(in float3 yuv) { return mul(YUV2RGB, yuv); }
float4 yuv2rgb(in float4 yuv) { return float4(yuv2rgb(yuv.rgb), yuv.a); }
#endif

Check it on Github



// #ifdef YUV_SDTV
// const YUV2RGB = mat3x3<f32>(
//     vec3f(1.0,       1.0,      1.0),
//     vec3f(0.0,      -0.39465,  2.03211),
//     vec3f(1.13983,  -0.58060,  0.0)
// );
// #else
const YUV2RGB = mat3x3<f32>(
    vec3f(1.0,       1.0,      1.0),
    vec3f(0.0,      -0.21482,  2.12798),
    vec3f(1.28033,  -0.38059,  0.0)
);
// #endif
fn yuv2rgb(yuv: vec3f) -> vec3f { return YUV2RGB * yuv; }


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