From 0585e3172d271914efa5e25fd0296b7d481f820b Mon Sep 17 00:00:00 2001 From: Istvan Petres Date: Sat, 18 May 2024 12:01:58 +0300 Subject: [PATCH] backend/glx: fix anti-alising of rounded corner Closes #1261 Signed-off-by: Yuxuan Shui Co-authored-by: Istvan Petres --- CHANGELOG.md | 1 + src/backend/gl/shaders.c | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1bd759415..f8add0d148 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ * Fix ghosting artifacts that sometimes occur when window manager is restarted (#1081) * Fix a bug where rounded corner is disabled after making a window fullscreen and back (#1216) +* Fix ugly looking rounded corners (#1261) ## Build changes diff --git a/src/backend/gl/shaders.c b/src/backend/gl/shaders.c index 3a87324fb1..b45325de78 100644 --- a/src/backend/gl/shaders.c +++ b/src/backend/gl/shaders.c @@ -95,7 +95,7 @@ const char masking_glsl[] = GLSL(330, if (mask_corner_radius != 0) { vec2 inner_size = mask_size - vec2(mask_corner_radius) * 2.0f; float dist = mask_rectangle_sdf(maskcoord - mask_size / 2.0f, - inner_size / 2.0f) - mask_corner_radius; + inner_size / 2.0f) - mask_corner_radius + 1.0f; if (dist > 0.0f) { mask.r *= (1.0f - clamp(dist, 0.0f, 1.0f)); } @@ -161,8 +161,12 @@ const char blit_shader_glsl[] = GLSL(330, vec2 outer_size = effective_size; vec2 inner_size = outer_size - vec2(corner_radius) * 2.0f; + // +1.0 so the last 1-pixel ring of the rounded rectangle will transition + // smoothly from 1 to 0 for anti-aliasing. If we don't do this, everything + // inside the corner radius will be solid, and we will have an extra 1-pixel + // feathering outside the corner radius, which makes it look bad. float rect_distance = rectangle_sdf(texcoord - outer_size / 2.0f, - inner_size / 2.0f) - corner_radius; + inner_size / 2.0f) - corner_radius + 1.0f; if (rect_distance > 0.0f) { c = (1.0f - clamp(rect_distance, 0.0f, 1.0f)) * rim_color; } else {