LYGIA Shader Library

softLight (lygia/v1.1.6/color/blend/softLight)

Photoshop Soft Light blend mode mplementations sourced from this article on https://mouaif.wordpress.com/2009/01/05/photoshop-math-with-glsl-shaders/

Use:

blendSoftLight(<float|vec3> base, <float|vec3> blend [, <float> opacity])

Check it on Github


#ifndef FNC_BLENDSOFTLIGHT
#define FNC_BLENDSOFTLIGHT
float blendSoftLight(in float base, in float blend) {
    return (blend < .5)? (2. * base * blend + base * base * (1. - 2.*blend)): (sqrt(base) * (2. * blend - 1.) + 2. * base * (1. - blend));
}

vec3 blendSoftLight(in vec3 base, in vec3 blend) {
    return vec3(blendSoftLight(base.r, blend.r),
                blendSoftLight(base.g, blend.g),
                blendSoftLight(base.b, blend.b));
}

vec4 blendSoftLight(in vec4 base, in vec4 blend) {
    return vec4(blendSoftLight( base.r, blend.r ),
                blendSoftLight( base.g, blend.g ),
                blendSoftLight( base.b, blend.b ),
                blendSoftLight( base.a, blend.a )
    );
}

vec3 blendSoftLight(in vec3 base, in vec3 blend, in float opacity) {
    return (blendSoftLight(base, blend) * opacity + base * (1. - opacity));
}
#endif

Use:

blendSoftLight(<float|float3|float4> base, <float|float3|float4> blend [, <float> opacity])

Check it on Github


#ifndef FNC_BLENDSOFTLIGHT
#define FNC_BLENDSOFTLIGHT
float blendSoftLight(in float base, in float blend) {
    return (blend < .5)? (2. * base * blend + base * base * (1. - 2.*blend)): (sqrt(base) * (2. * blend - 1.) + 2. * base * (1. - blend));
}

float3 blendSoftLight(in float3 base, in float3 blend) {
    return float3(  blendSoftLight(base.r, blend.r),
                    blendSoftLight(base.g, blend.g),
                    blendSoftLight(base.b, blend.b) );
}

float4 blendSoftLight(in float4 base, in float4 blend) {
    return float4(  blendSoftLight( base.r, blend.r ),
                    blendSoftLight( base.g, blend.g ),
                    blendSoftLight( base.b, blend.b ),
                    blendSoftLight( base.a, blend.a )
    );
}

float3 blendSoftLight(in float3 base, in float3 blend, in float opacity) {
    return (blendSoftLight(base, blend) * opacity + base * (1. - opacity));
}
#endif

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