LYGIA Shader Library

yuv2rgb (lygia/v1.1.6/color/space/yuv2rgb)

pass a color in YUB and get RGB color

Use:

yuv2rgb(<vec3|vec4> color)

Check it on Github


#ifndef FNC_YUV2RGB
#define FNC_YUV2RGB

#ifdef YUV_SDTV
const mat3 yuv2rgb_mat = mat3(
    1.,       1. ,      1.,
    0.,       -.39465,  2.03211,
    1.13983,  -.58060,  0.
);
#else
const mat3 yuv2rgb_mat = mat3(
    1.,       1. ,      1.,
    0.,       -.21482,  2.12798,
    1.28033,  -.38059,  0.
);
#endif

vec3 yuv2rgb(in vec3 yuv) {
    return yuv2rgb_mat * yuv;
}

vec4 yuv2rgb(in vec4 yuv) {
    return vec4(yuv2rgb(yuv.rgb), yuv.a);
}
#endif

Use:

yuv2rgb(<float3|float4> color)

Check it on Github


#ifndef FNC_YUV2RGB
#define FNC_YUV2RGB

#ifdef YUV_SDTV
const float3x3 yuv2rgb_mat = float3x3(
    1.,       1. ,      1.,
    0.,       -.39465,  2.03211,
    1.13983,  -.58060,  0.
);
#else
const float3x3 yuv2rgb_mat = float3x3(
    1.,       1. ,      1.,
    0.,       -.21482,  2.12798,
    1.28033,  -.38059,  0.
);
#endif

float3 yuv2rgb(in float3 yuv) {
    return mul(yuv2rgb_mat, yuv);
}

float4 yuv2rgb(in float4 yuv) {
    return float4(yuv2rgb(yuv.rgb), yuv.a);
}
#endif

Check it on Github


// #ifdef YUV_SDTV
// const yuv2rgb_mat = mat3x3<f32>(
//     vec3<f32>(1.0,       1.0,      1.0),
//     vec3<f32>(0.0,      -0.39465,  2.03211),
//     vec3<f32>(1.13983,  -0.58060,  0.0)
// );
// #else
const yuv2rgb_mat = mat3x3<f32>(
    vec3<f32>(1.0,       1.0,      1.0),
    vec3<f32>(0.0,      -0.21482,  2.12798),
    vec3<f32>(1.28033,  -0.38059,  0.0)
);
// #endif

fn yuv2rgb(yuv: vec3<f32>) -> vec3<f32> {
    return yuv2rgb_mat * yuv;
}


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