From 4ee56a1e75a043c6f317ea2f71c96b2061e85cf5 Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Sat, 13 Nov 2021 23:34:48 +0000 Subject: [PATCH] rendervulkan: Do not premultiply color The surface should already have premultiplied alpha. Gets us to how we look with planes. --- src/composite.comp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/composite.comp b/src/composite.comp index 4f2f0d1..9e7fe15 100644 --- a/src/composite.comp +++ b/src/composite.comp @@ -102,8 +102,14 @@ void main() { for (int i = 1; i < c_layerCount; i++) { vec4 layerColor = sampleLayer(i, uv); - float layerAlpha = u_opacity[i] * layerColor.a; - outputValue = layerColor * layerAlpha + outputValue * (1.0f - layerAlpha); + // wl_surfaces come with premultiplied alpha, so that's them being + // premultiplied by layerColor.a. + // We need to then multiply that by the layer's opacity to get to our + // final premultiplied state. + // For the other side of things, we need to multiply by (1.0f - (layerColor.a * opacity)) + float opacity = u_opacity[i]; + float layerAlpha = opacity * layerColor.a; + outputValue = layerColor * opacity + outputValue * (1.0f - layerAlpha); } if (c_swapChannels)