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.
This commit is contained in:
swaits committed 2026-04-07 12:28:38 -06:00
1 parent bdd3482b75
commit dacc631d57
2 files changed
+11 -13

No files matched your search

+5 -7
View File
@@ -62,12 +62,10 @@ impl GpuRenderer {
})) }))
.context("no compatible GPU adapter")?; .context("no compatible GPU adapter")?;
let (device, queue) = pollster::block_on(adapter.request_device( let (device, queue) = pollster::block_on(adapter.request_device(&wgpu::DeviceDescriptor {
&wgpu::DeviceDescriptor { label: Some("ringa"),
label: Some("ringa"), ..Default::default()
..Default::default() }))
},
))
.context("request GPU device")?; .context("request GPU device")?;
let caps = surface.get_capabilities(&adapter); let caps = surface.get_capabilities(&adapter);
@@ -119,7 +117,7 @@ impl GpuRenderer {
inner_corner_radius: 100.0, inner_corner_radius: 100.0,
glow_spread: 50.0, glow_spread: 50.0,
cursor_avoid_radius: 300.0, cursor_avoid_radius: 300.0,
cursor_avoid_falloff: 1500.0, cursor_avoid_falloff: 400.0,
_pad: 0.0, _pad: 0.0,
color, color,
_pad2: 0.0, _pad2: 0.0,
+6 -6
View File
@@ -60,12 +60,12 @@ fn fs_main(@builtin(position) pos: vec4f) -> @location(0) vec4f {
alpha = exp(-3.0 * t * t); alpha = exp(-3.0 * t * t);
} }
// Cursor avoidance // Cursor avoidance — rounded square (box SDF with corner rounding)
let cursor_dist = distance(pos.xy, u.cursor_pos); let cursor_half = vec2f(u.cursor_avoid_radius);
let avoid_start = u.cursor_avoid_radius; let cursor_corner = u.cursor_avoid_radius * 0.3; // 30% rounding smooths the diagonals
let avoid_end = u.cursor_avoid_radius + u.cursor_avoid_falloff; let cursor_sd = rounded_rect_sdf(pos.xy - u.cursor_pos, cursor_half, cursor_corner);
if cursor_dist < avoid_end { if cursor_sd < u.cursor_avoid_falloff {
let t_avoid = clamp((cursor_dist - avoid_start) / (avoid_end - avoid_start), 0.0, 1.0); 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); alpha *= t_avoid * t_avoid * (3.0 - 2.0 * t_avoid);
} }