LYGIA Shader Library

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

pass a color in RGB and get it in YUB

Use:

rgb2yuv(<vec3|vec4> color)

Check it on Github


#ifndef FNC_RGB2YUV
#define FNC_RGB2YUV

#ifdef YUV_SDTV
const mat3 rgb2yuv_mat = mat3(
    .299, -.14713,  .615,
    .587, -.28886, -.51499,
    .114,  .436,   -.10001
);
#else
const mat3 rgb2yuv_mat = mat3(
    .2126,  -.09991, .615,
    .7152,  -.33609,-.55861,
    .0722,   .426,  -.05639
);
#endif

vec3 rgb2yuv(in vec3 rgb) {
    return rgb2yuv_mat * rgb;
}

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

Use:

rgb2yuv(<float3|float4> color)

Check it on Github


#ifndef FNC_RGB2YUV
#define FNC_RGB2YUV

#ifdef YUV_SDTV
const float3x3 rgb2yuv_mat = float3x3(
    .299, -.14713,  .615,
    .587, -.28886, -.51499,
    .114,  .436,   -.10001
);
#else
const float3x3 rgb2yuv_mat = float3x3(
    .2126,  -.09991, .615,
    .7152,  -.33609,-.55861,
    .0722,   .426,  -.05639
);
#endif

float3 rgb2yuv(in float3 rgb) {
    return mul(rgb2yuv_mat, rgb);
}

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

Check it on Github

// #ifdef YUV_SDTV
// const rgb2yuv_mat = mat3x3<f32>(
//     vec3<f32>(0.299, -0.14713,  0.615),
//     vec3<f32>(0.587, -0.28886, -0.51499),
//     vec3<f32>(0.114,  0.436,   -0.10001)
// );
// #else
const rgb2yuv_mat = mat3x3<f32>(
    vec3<f32>(0.2126,  -.09991, .615),
    vec3<f32>(0.7152,  -.33609,-.55861),
    vec3<f32>(0.0722,   .426,  -.05639)
);
// #endif

fn rgb2yuv(rgb: vec3<f32>) -> vec3<f32> {
    return rgb2yuv_mat * rgb;
}

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