LYGIA Shader Library

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

convert CMYK to RGB

Dependencies:

Use:

rgb2cmyk(<vec3|vec4> rgba)

Check it on Github



#ifndef FNC_RGB2CMYK
#define FNC_RGB2CMYK
vec4 rgb2cmyk(vec3 rgb) {
    float k = mmin(1.0 - rgb);
    float invK = 1.0 - k;
    vec3 cmy = (1.0 - rgb - k) / invK;
    cmy *= step(0.0, invK);
    return saturate(vec4(cmy, k));
}
#endif

Dependencies:

Use:

rgb2cmyk(<float3|float4> rgba)

Check it on Github



#ifndef FNC_RGB2CMYK
#define FNC_RGB2CMYK
float4 rgb2cmyk(float3 rgb) {
    float k = mmin(1.0 - rgb);
    float invK = 1.0 - k;
    float3 cmy = (1.0 - rgb - k) / invK;
    cmy *= step(0.0, invK);
    return saturate(float4(cmy, k));
}
#endif

Check it on Github

fn rgb2cmyk(rgb: vec3<f32>) -> vec4<f32> {
    let k = min(1.0 - rgb.r, min(1.0 - rgb.g, 1.0 - rgb.b));
    let invK = 1.0 - k;
    var cmy = (1.0 - rgb - k) / invK;
    cmy *= step(0.0, invK);
    return saturate(vec4<f32>(cmy, k));
}

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