LYGIA Shader Library

desaturate (lygia/color/desaturate)

Change saturation of a color

Use:

desaturate(<float|vec3|vec4> color, float amount)

Check it on Github


#ifndef FNC_DESATURATE
#define FNC_DESATURATE
vec3 desaturate(in vec3 v, in float a ) {
    return mix(v, vec3(dot(vec3(.3, .59, .11), v)), a);
}

vec4 desaturate(in vec4 v, in float a ) {
    return vec4(desaturate(v.rgb, a), v.a);
}
#endif

Use:

desaturate(<float|float3|float4> color, float amount)

Check it on Github


#ifndef FNC_DESATURATE
#define FNC_DESATURATE
float3 desaturate(in float3 color, in float amount ) {
    float l = dot(float3(.3, .59, .11), color);
    return lerp(color, float3(l, l, l), amount);
}

float4 desaturate(in float4 color, in float amount ) {
    return float4(desaturate(color.rgb, amount), color.a);
}
#endif

Use:

desaturate(<float|float3|float4> color, float amount)

Check it on Github


#ifndef FNC_DESATURATE
#define FNC_DESATURATE
float3 desaturate(float3 v, float a ) {
    return mix(v, float3(dot(float3(.3, .59, .11), v)), a);
}

float4 desaturate(float4 v, float a ) {
    return float4(desaturate(v.rgb, a), v.a);
}
#endif

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