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:
2 files changed
+11
-13
No files matched your search
+5
-7
@@ -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,
|
||||
|
||||
+6
-6
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user