widgets/cliprect: fix premultiplied alpha blending

This commit is contained in:
outfoxxed 2025-05-17 17:03:03 -07:00
parent 8124a63ee4
commit 6dbc310df4
Signed by untrusted user: outfoxxed
GPG key ID: 4C88A185FB89301E

View file

@ -14,11 +14,12 @@ layout(binding = 2) uniform sampler2D content;
vec4 overlay(vec4 base, vec4 overlay) { vec4 overlay(vec4 base, vec4 overlay) {
if (overlay.a == 0.0) return base; if (overlay.a == 0.0) return base;
if (base.a == 0.0) return overlay;
float baseMul = 1.0 - overlay.a; vec3 rgb = overlay.rgb + base.rgb * (1.0 - overlay.a);
float newAlpha = overlay.a + base.a * baseMul; float a = overlay.a + base.a * (1.0 - overlay.a);
vec3 rgb = (overlay.rgb * overlay.a + base.rgb * base.a * baseMul) / newAlpha;
return vec4(rgb, newAlpha); return vec4(rgb, a);
} }
void main() { void main() {