Skip to content

Commit 539b801

Browse files
committed
Refactor blend functions
1 parent de7cf66 commit 539b801

32 files changed

Lines changed: 104 additions & 103 deletions
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
vec4 blend(const in vec4 x, const in vec4 y, const in float opacity) {
1+
vec4 blend(const in vec4 dst, const in vec4 src, const in float opacity) {
22

3-
return mix(x, vec4(x.rgb + y.rgb, y.a), y.a * opacity);
3+
return mix(dst, vec4(dst.rgb + src.rgb, src.a), src.a * opacity);
44

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

3-
return mix(x, y, y.a * opacity);
3+
return mix(dst, src, src.a * opacity);
44

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

3-
return mix(x, vec4((x.rgb + y.rgb) * 0.5, y.a), y.a * opacity);
3+
return mix(dst, vec4((dst.rgb + src.rgb) * 0.5, src.a), src.a * opacity);
44

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

3-
vec3 a = x.rgb, b = y.rgb;
4-
vec3 z = 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(x, vec4(z, y.a), y.a * opacity);
3+
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);
66

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

3-
vec3 a = x.rgb, b = y.rgb;
4-
vec3 z = 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(x, vec4(z, y.a), y.a * opacity);
3+
vec3 a = dst.rgb, b = src.rgb;
4+
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);
66

77
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
vec4 blend(const in vec4 x, const in vec4 y, const in float opacity) {
1+
vec4 blend(const in vec4 dst, const in vec4 src, const in float opacity) {
22

3-
vec3 xHSL = RGBToHSL(x.rgb);
4-
vec3 yHSL = RGBToHSL(y.rgb);
5-
vec3 z = HSLToRGB(vec3(yHSL.xy, xHSL.z));
6-
return mix(x, vec4(z, y.a), y.a * opacity);
3+
vec3 a = RGBToHSL(dst.rgb);
4+
vec3 b = RGBToHSL(src.rgb);
5+
vec3 c = HSLToRGB(vec3(b.xy, a.z));
6+
return mix(dst, vec4(c, src.a), src.a * opacity);
77

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

3-
return mix(x, vec4(min(x.rgb, y.rgb), y.a), y.a * opacity);
3+
return mix(dst, vec4(min(dst.rgb, src.rgb), src.a), src.a * opacity);
44

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

3-
return mix(x, vec4(abs(x.rgb - y.rgb), y.a), y.a * opacity);
3+
return mix(dst, vec4(abs(dst.rgb - src.rgb), src.a), src.a * opacity);
44

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

3-
return mix(x, vec4(x.rgb / max(y.rgb, 1e-12), y.a), y.a * opacity);
3+
return mix(dst, vec4(dst.rgb / max(src.rgb, 1e-12), src.a), src.a * opacity);
44

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

3-
return mix(x, vec4((x.rgb + y.rgb - 2.0 * x.rgb * y.rgb), y.a), y.a * opacity);
3+
return mix(dst, vec4((dst.rgb + src.rgb - 2.0 * dst.rgb * src.rgb), src.a), src.a * opacity);
44

55
}

0 commit comments

Comments
 (0)