2016-07-03 22:02:56 +00:00
|
|
|
vec3 BlendMultiply(vec3 Cb, vec3 Cs) {
|
|
|
|
return Cb * Cs;
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3 BlendScreen(vec3 Cb, vec3 Cs) {
|
|
|
|
return Cb + Cs - (Cb * Cs);
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3 BlendHardLight(vec3 Cb, vec3 Cs) {
|
|
|
|
vec3 m = BlendMultiply(Cb, 2.0 * Cs);
|
|
|
|
vec3 s = BlendScreen(Cb, 2.0 * Cs - 1.0);
|
|
|
|
vec3 edge = vec3(0.5, 0.5, 0.5);
|
|
|
|
|
|
|
|
/* Use mix() and step() to avoid a branch */
|
|
|
|
return mix(m, s, step(edge, Cs));
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3 BlendOverlay(vec3 Cb, vec3 Cs) {
|
|
|
|
return BlendHardLight(Cs, Cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3 BlendDarken(vec3 Cb, vec3 Cs) {
|
|
|
|
return min(Cb, Cs);
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3 BlendLighten(vec3 Cb, vec3 Cs) {
|
|
|
|
return max(Cb, Cs);
|
2016-07-03 20:12:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void main() {
|
2016-08-02 15:58:47 +00:00
|
|
|
vec4 Cs = Texture(uSource, vUv);
|
|
|
|
vec4 Cb = Texture(uMask, vUv);
|
2016-07-03 20:12:22 +00:00
|
|
|
vec3 res;
|
|
|
|
|
2016-07-21 16:17:49 +00:00
|
|
|
if (uBlendMode == 0) {
|
2016-07-08 15:26:44 +00:00
|
|
|
res = Cs.xyz;
|
2016-07-03 20:12:22 +00:00
|
|
|
}
|
2016-07-21 16:17:49 +00:00
|
|
|
else if (uBlendMode == 1) {
|
2016-07-08 15:26:44 +00:00
|
|
|
res = BlendMultiply(Cb.xyz, Cs.xyz);
|
2016-07-03 22:02:56 +00:00
|
|
|
}
|
2016-07-21 16:17:49 +00:00
|
|
|
else if (uBlendMode == 2) {
|
2016-07-08 15:26:44 +00:00
|
|
|
res = BlendScreen(Cb.xyz, Cs.xyz);
|
2016-07-03 22:02:56 +00:00
|
|
|
}
|
2016-07-21 16:17:49 +00:00
|
|
|
else if (uBlendMode == 3) {
|
2016-07-08 15:26:44 +00:00
|
|
|
res = BlendOverlay(Cb.xyz, Cs.xyz);
|
2016-07-03 22:02:56 +00:00
|
|
|
}
|
2016-07-21 16:17:49 +00:00
|
|
|
else if (uBlendMode == 4) {
|
2016-07-08 15:26:44 +00:00
|
|
|
res = BlendDarken(Cb.xyz, Cs.xyz);
|
2016-07-03 22:02:56 +00:00
|
|
|
}
|
2016-07-21 16:17:49 +00:00
|
|
|
else if (uBlendMode == 5) {
|
2016-07-08 15:26:44 +00:00
|
|
|
res = BlendLighten(Cb.xyz, Cs.xyz);
|
2016-07-03 22:02:56 +00:00
|
|
|
}
|
2016-07-21 16:17:49 +00:00
|
|
|
else if (uBlendMode == 8) {
|
2016-07-08 15:26:44 +00:00
|
|
|
res = BlendHardLight(Cb.xyz, Cs.xyz);
|
2016-07-03 20:12:22 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Use red for debugging missing blend modes
|
|
|
|
res = vec3(1.0, 0.0, 0.0);
|
|
|
|
}
|
|
|
|
|
2016-07-21 16:17:49 +00:00
|
|
|
setOutputColor(vec4(res, Cs.a * uAlpha));
|
2016-07-03 20:12:22 +00:00
|
|
|
}
|