Remove artifact when a border side was not rendered
Antonio Scandurra
created 4 years ago
This introduces an extra conditional in the shader, there's probably a
way of writing it without ifs but I like how the logic reads with it and
it shouldn't be that big of a deal performance-wise.
Change summary
gpui/src/platform/mac/shaders/shaders.metal | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
Detailed changes
@@ -73,12 +73,18 @@ fragment float4 quad_fragment(
border_width = center_to_point.y <= 0.0 ? input.quad.border_top : input.quad.border_bottom;
}
- float inset_distance = distance + border_width;
- float4 color = mix(
- coloru_to_colorf(input.quad.border_color),
- coloru_to_colorf(input.quad.background_color),
- saturate(0.5 - inset_distance)
- );
+ float4 color;
+ if (border_width == 0.) {
+ color = coloru_to_colorf(input.quad.background_color);
+ } else {
+ float inset_distance = distance + border_width;
+ color = mix(
+ coloru_to_colorf(input.quad.border_color),
+ coloru_to_colorf(input.quad.background_color),
+ saturate(0.5 - inset_distance)
+ );
+ }
+
float4 coverage = float4(1.0, 1.0, 1.0, saturate(0.5 - distance));
return coverage * color;
}