Skip to content

Commit

Permalink
backend/gl: fix rendering when corner_radius is 0
Browse files Browse the repository at this point in the history
Fixes #1311

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
  • Loading branch information
yshui committed Aug 13, 2024
1 parent f977763 commit 6b858b8
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/backend/gl/shaders.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,24 +154,26 @@ const char blit_shader_glsl[] = GLSL(330,
border_color.rgb = border_color.rgb * (max_brightness / brightness);
}

// Rim color is the color of the outer rim of the window, if there is no
// border, it's the color of the window itself, otherwise it's the border.
// Using mix() to avoid a branch here.
vec4 rim_color = mix(c, border_color, clamp(border_width, 0.0f, 1.0f));
if (corner_radius != 0) {
// Rim color is the color of the outer rim of the window, if there is no
// border, it's the color of the window itself, otherwise it's the border.
// Using mix() to avoid a branch here.
vec4 rim_color = mix(c, border_color, clamp(border_width, 0.0f, 1.0f));

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 + 1.0f;
if (rect_distance > 0.0f) {
c = (1.0f - clamp(rect_distance, 0.0f, 1.0f)) * rim_color;
} else {
float factor = clamp(rect_distance + border_width, 0.0f, 1.0f);
c = (1.0f - factor) * c + factor * border_color;
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 + 1.0f;
if (rect_distance > 0.0f) {
c = (1.0f - clamp(rect_distance, 0.0f, 1.0f)) * rim_color;
} else {
float factor = clamp(rect_distance + border_width, 0.0f, 1.0f);
c = (1.0f - factor) * c + factor * border_color;
}
}

return c;
Expand Down

1 comment on commit 6b858b8

@pijulius
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @yshui please see this
#1261 (comment)

Please sign in to comment.