Pixel-Composer/shaders/sh_mask/sh_mask.fsh

30 lines
710 B
Plaintext
Raw Normal View History

2022-01-13 05:24:03 +01:00
//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform sampler2D mask;
2023-02-14 07:37:13 +01:00
uniform int useMask;
2023-11-24 10:41:53 +01:00
uniform int invMask;
2023-02-14 07:37:13 +01:00
uniform sampler2D original;
uniform sampler2D edited;
uniform float mixRatio;
2022-01-13 05:24:03 +01:00
void main() {
2023-02-14 07:37:13 +01:00
vec4 msk = texture2D( mask, v_vTexcoord );
vec4 ori = texture2D( original, v_vTexcoord );
vec4 edt = texture2D( edited, v_vTexcoord );
2023-11-24 10:41:53 +01:00
float mskAmo = (msk.r + msk.g + msk.b) / 3. * msk.a;
if(invMask == 1) mskAmo = 1. - mskAmo;
float rat = (useMask == 1? mskAmo : 1.) * mixRatio;
rat = clamp(rat, 0., 1.);
gl_FragColor = mix(ori, edt, rat);
if(ori.a == 0.) gl_FragColor.rgb = edt.rgb;
if(edt.a == 0.) gl_FragColor.rgb = ori.rgb;
2022-01-13 05:24:03 +01:00
}