From 858b5c12b1f55043964c2e2bd30de8cf112e76d2 Mon Sep 17 00:00:00 2001 From: Daniel van Vugt Date: Mon, 22 Nov 2021 18:23:08 +0800 Subject: [PATCH] background-content: Anti-alias texels that intersect the circle boundary Previously we chose to only anti-alias texels inside the boundary (`clip_radius - 1.0`) but zoomed in you could see it was slightly smaller than the correct curve (#2024). Similarly if you choose to only anti-alias texels outside that edge (`clip_radius + 1.0`) then you'd get an overly convex curve that doesn't match up with the straight line sections. So now we anti-alias texels that intersect the circle boundary, regardless of which side they are mostly on. For efficiency we define "intersect" to mean any texel whose center is within 0.5 of the theoretical edge. Fixes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2024 Part-of: --- src/compositor/meta-background-content.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/compositor/meta-background-content.c b/src/compositor/meta-background-content.c index eeae41c62..49f5885ca 100644 --- a/src/compositor/meta-background-content.c +++ b/src/compositor/meta-background-content.c @@ -169,16 +169,17 @@ typedef enum " float dist_squared = dot (delta, delta); \n"\ " \n"\ " // Fully outside the circle \n"\ -" if (dist_squared >= (clip_radius * clip_radius)) \n"\ +" float outer_radius = clip_radius + 0.5; \n"\ +" if (dist_squared >= (outer_radius * outer_radius)) \n"\ " return 0.0; \n"\ " \n"\ " // Fully inside the circle \n"\ -" float inner_radius = clip_radius - 1.0; \n"\ +" float inner_radius = clip_radius - 0.5; \n"\ " if (dist_squared <= (inner_radius * inner_radius)) \n"\ " return 1.0; \n"\ " \n"\ " // Only pixels on the edge of the curve need expensive antialiasing \n"\ -" return clip_radius - sqrt (dist_squared); \n"\ +" return outer_radius - sqrt (dist_squared); \n"\ "} \n" #define ROUNDED_CLIP_FRAGMENT_SHADER_CODE \