Skip to content

Commit 3b9a96d

Browse files
committed
Update blend functions
1 parent ae29c4a commit 3b9a96d

30 files changed

Lines changed: 58 additions & 43 deletions
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
vec4 blend(const in vec4 dst, const in vec4 src, const in float opacity) {
22

3-
return mix(dst, vec4(dst.rgb + src.rgb, src.a), src.a * opacity);
3+
vec3 c = dst.rgb + src.rgb;
4+
return mix(dst, vec4(c, max(dst.a, src.a)), opacity);
45

56
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
vec4 blend(const in vec4 dst, const in vec4 src, const in float opacity) {
22

3-
return mix(dst, vec4((dst.rgb + src.rgb) * 0.5, src.a), src.a * opacity);
3+
vec3 c = (dst.rgb + src.rgb) * 0.5;
4+
return mix(dst, vec4(c, max(dst.a, src.a)), opacity);
45

56
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
vec4 blend(const in vec4 dst, const in vec4 src, const in float opacity) {
22

33
vec3 a = dst.rgb, b = src.rgb;
4-
vec3 c = mix(step(0.0, b) * (1.0 - min(vec3(1.0), (1.0 - a) / b)), vec3(1.0), step(1.0, a));
5-
return mix(dst, vec4(c, src.a), src.a * opacity);
4+
vec3 c = mix(step(0.0, b) * (1.0 - min(vec3(1.0), (1.0 - a) / max(b, 1e-9))), vec3(1.0), step(1.0, a));
5+
return mix(dst, vec4(c, max(dst.a, src.a)), opacity);
66

77
}

src/effects/blending/blend-functions/shaders/color-dodge.frag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ vec4 blend(const in vec4 dst, const in vec4 src, const in float opacity) {
22

33
vec3 a = dst.rgb, b = src.rgb;
44
vec3 c = step(0.0, a) * mix(min(vec3(1.0), a / max(1.0 - b, 1e-9)), vec3(1.0), step(1.0, b));
5-
return mix(dst, vec4(c, src.a), src.a * opacity);
5+
return mix(dst, vec4(c, max(dst.a, src.a)), opacity);
66

77
}

src/effects/blending/blend-functions/shaders/color.frag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ vec4 blend(const in vec4 dst, const in vec4 src, const in float opacity) {
33
vec3 a = RGBToHSL(dst.rgb);
44
vec3 b = RGBToHSL(src.rgb);
55
vec3 c = HSLToRGB(vec3(b.xy, a.z));
6-
return mix(dst, vec4(c, src.a), src.a * opacity);
6+
return mix(dst, vec4(c, max(dst.a, src.a)), opacity);
77

88
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
vec4 blend(const in vec4 dst, const in vec4 src, const in float opacity) {
22

3-
return mix(dst, vec4(min(dst.rgb, src.rgb), src.a), src.a * opacity);
3+
vec3 c = min(dst.rgb, src.rgb);
4+
return mix(dst, vec4(c, max(dst.a, src.a)), opacity);
45

56
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
vec4 blend(const in vec4 dst, const in vec4 src, const in float opacity) {
22

3-
return mix(dst, vec4(abs(dst.rgb - src.rgb), src.a), src.a * opacity);
3+
vec3 c = abs(dst.rgb - src.rgb);
4+
return mix(dst, vec4(c, max(dst.a, src.a)), opacity);
45

56
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
vec4 blend(const in vec4 dst, const in vec4 src, const in float opacity) {
22

3-
return mix(dst, vec4(dst.rgb / max(src.rgb, 1e-12), src.a), src.a * opacity);
3+
vec3 c = dst.rgb / max(src.rgb, 1e-9);
4+
return mix(dst, vec4(c, max(dst.a, src.a)), opacity);
45

56
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
vec4 blend(const in vec4 dst, const in vec4 src, const in float opacity) {
22

3-
return mix(dst, vec4((dst.rgb + src.rgb - 2.0 * dst.rgb * src.rgb), src.a), src.a * opacity);
3+
vec3 c = dst.rgb + src.rgb - 2.0 * dst.rgb * src.rgb;
4+
return mix(dst, vec4(c, max(dst.a, src.a)), opacity);
45

56
}

src/effects/blending/blend-functions/shaders/hard-light.frag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ vec4 blend(const in vec4 dst, const in vec4 src, const in float opacity) {
33
vec3 a = min(dst.rgb, 1.0);
44
vec3 b = min(src.rgb, 1.0);
55
vec3 c = mix(2.0 * a * b, 1.0 - 2.0 * (1.0 - a) * (1.0 - b), step(0.5, b));
6-
return mix(dst, vec4(c, src.a), src.a * opacity);
6+
return mix(dst, vec4(c, max(dst.a, src.a)), opacity);
77

88
}

0 commit comments

Comments
 (0)