Browse

OverlayBlend

by Mewatools

Blends 2 images using the overlay blend method.

Source Code
// https://en.wikipedia.org/wiki/Blend_modes#Overlay
// Brief: Blends 2 images using overlay blend method

shaderSource = "
    vec3 blend(vec3 a, vec3 b) {
        float light = (a.x + a.y + a.z) / 3.0;
        if( light < threshold ){
            return 2. * a * b;
        }
        return 1. - 2.*(1.-a)*(1. - b);
    }
    
    void mainImage( out vec4 fragColor, in vec2 fragCoordA, in vec2 fragCoordB ){	
	    vec3  a = texture2D(iChannel0, fragCoordA).rgb;
        vec3  b = texture2D(iChannel1, fragCoordB).rgb;   
        fragColor = vec4( blend(a,b), 1.0 );
    }";
    

node = ShaderNode( shaderSource, "OverlayBlend" );
node.addShaderInput( "iChannel0" );
node.addShaderInput( "iChannel1" );

uiControl = node.addFloatControl("threshold", 0.5);
uiControl.setName("Threshold");
uiControl.setStep(0.0001);
uiControl.setRange(0.0, 1.0);

node.finishAdding();
File Details
  • Last Update: November 29th, 2020
  • Category:
  • License: