From 655dcba6aeff14c5ec90f3366334cf7a279c2083 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Fri, 15 Sep 2023 04:50:34 +0200 Subject: [PATCH] gpu: Improve conic gradient rendering 1. Compute the fwidth() twice with offset offsets That way, we avoid glitches at the boundary between 0.0 and 1.0, because by offsetting it by 0.5, that boundary goes away. Then we take the min() of both which gives us the one we care about. 2. Set the gradient to repeating By doing that, we don't get values at the 0.0/1.0 boundary clamped, but things smoothly transition. This smoothes the line at that boundary and makes it look just like every other line. --- gsk/gpu/shaders/pattern.glsl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/gsk/gpu/shaders/pattern.glsl b/gsk/gpu/shaders/pattern.glsl index 12ca48af66..f84dae0546 100644 --- a/gsk/gpu/shaders/pattern.glsl +++ b/gsk/gpu/shaders/pattern.glsl @@ -187,10 +187,12 @@ conic_gradient_pattern (inout uint reader, /* scaling modifies angles, so be sure to use right coordinate system */ pos = pos / push.scale - center; float offset = atan (pos.y, pos.x); - offset = fract (degrees (offset + angle) / 360.0); - float d_offset = 0.5 * fwidth (offset); + offset = degrees (offset + angle) / 360.0; + float overflow = fract (offset + 0.5); + offset = fract (offset); + float d_offset = max (0.00001, 0.5 * min (fwidth (offset), fwidth (overflow))); - return gradient_get_color (gradient, offset - d_offset, offset + d_offset); + return gradient_get_color_repeating (gradient, offset - d_offset, offset + d_offset); } vec4