Skip to content

Commit 32c5f46

Browse files
committed
widgets/cliprect: fix premultiplied alpha blending
1 parent 5048b97 commit 32c5f46

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/widgets/shaders/cliprect.frag

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ layout(binding = 2) uniform sampler2D content;
1414

1515
vec4 overlay(vec4 base, vec4 overlay) {
1616
if (overlay.a == 0.0) return base;
17+
if (base.a == 0.0) return overlay;
1718

18-
float baseMul = 1.0 - overlay.a;
19-
float newAlpha = overlay.a + base.a * baseMul;
20-
vec3 rgb = (overlay.rgb * overlay.a + base.rgb * base.a * baseMul) / newAlpha;
21-
return vec4(rgb, newAlpha);
19+
vec3 rgb = overlay.rgb + base.rgb * (1.0 - overlay.a);
20+
float a = overlay.a + base.a * (1.0 - overlay.a);
21+
22+
return vec4(rgb, a);
2223
}
2324

2425
void main() {

0 commit comments

Comments
 (0)