Merge branch 'vulkan-alpha-blend' into 'master'

[RFC] vulkan: compensate alpha to better match perceptual blend intent

See merge request wlroots/wlroots!4634
This commit is contained in:
John Lindgren 2025-06-11 23:19:36 +00:00
commit f4cfc79a6d
3 changed files with 81 additions and 8 deletions

View file

@ -26,11 +26,17 @@ vec4 srgb_color_to_linear(vec4 color) {
return vec4(0);
}
color.rgb /= color.a;
// Estimate perceptual lightness from sRGB values
float v = (color.r + color.g + color.b) / 3;
color.rgb = vec3(
srgb_channel_to_linear(color.r),
srgb_channel_to_linear(color.g),
srgb_channel_to_linear(color.b)
);
// Adjust alpha to make dark semi-transparent overlays a bit more
// opaque, better matching perceptual intent compared to simple
// linear blending (see README-alpha-blend for a longer discussion)
color.a = ((v - 0.5) * color.a * color.a + color.a) / (v + 0.5);
color.rgb *= color.a;
return color;
}