From dacc631d57a64bf55a0032e1221bc1983d05c8f2 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Tue, 7 Apr 2026 11:56:52 -0600 Subject: [PATCH] fix: use rounded-square SDF for cursor avoidance hole Replace Chebyshev distance with a rounded box SDF for the cursor avoidance shape. Eliminates diagonal artifacts where the sharp corners of a pure square distance field intersected the ring geometry. --- src/render.rs | 12 +++++------- src/shader.wgsl | 12 ++++++------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/render.rs b/src/render.rs index 3998897..a012a7d 100644 --- a/src/render.rs +++ b/src/render.rs @@ -62,12 +62,10 @@ impl GpuRenderer { })) .context("no compatible GPU adapter")?; - let (device, queue) = pollster::block_on(adapter.request_device( - &wgpu::DeviceDescriptor { - label: Some("ringa"), - ..Default::default() - }, - )) + let (device, queue) = pollster::block_on(adapter.request_device(&wgpu::DeviceDescriptor { + label: Some("ringa"), + ..Default::default() + })) .context("request GPU device")?; let caps = surface.get_capabilities(&adapter); @@ -119,7 +117,7 @@ impl GpuRenderer { inner_corner_radius: 100.0, glow_spread: 50.0, cursor_avoid_radius: 300.0, - cursor_avoid_falloff: 1500.0, + cursor_avoid_falloff: 400.0, _pad: 0.0, color, _pad2: 0.0, diff --git a/src/shader.wgsl b/src/shader.wgsl index 7864102..7075126 100644 --- a/src/shader.wgsl +++ b/src/shader.wgsl @@ -60,12 +60,12 @@ fn fs_main(@builtin(position) pos: vec4f) -> @location(0) vec4f { alpha = exp(-3.0 * t * t); } - // Cursor avoidance - let cursor_dist = distance(pos.xy, u.cursor_pos); - let avoid_start = u.cursor_avoid_radius; - let avoid_end = u.cursor_avoid_radius + u.cursor_avoid_falloff; - if cursor_dist < avoid_end { - let t_avoid = clamp((cursor_dist - avoid_start) / (avoid_end - avoid_start), 0.0, 1.0); + // Cursor avoidance — rounded square (box SDF with corner rounding) + let cursor_half = vec2f(u.cursor_avoid_radius); + let cursor_corner = u.cursor_avoid_radius * 0.3; // 30% rounding smooths the diagonals + let cursor_sd = rounded_rect_sdf(pos.xy - u.cursor_pos, cursor_half, cursor_corner); + if cursor_sd < u.cursor_avoid_falloff { + let t_avoid = clamp(cursor_sd / u.cursor_avoid_falloff, 0.0, 1.0); alpha *= t_avoid * t_avoid * (3.0 - 2.0 * t_avoid); }