From 1074c81f524f65cc0c4108bc0c6e28e80ca8cf32 Mon Sep 17 00:00:00 2001 From: gianlucafiore <50465150+gianlucafiore@users.noreply.github.com> Date: Mon, 12 Oct 2026 18:07:48 -0300 Subject: [PATCH] fix: increase bounded screen draw-order depth resolution for overlapping block wipeouts --- src/shaders/draw_order.wgsl | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/shaders/draw_order.wgsl b/src/shaders/draw_order.wgsl index d0d243d85..d7f90e122 100644 --- a/src/shaders/draw_order.wgsl +++ b/src/shaders/draw_order.wgsl @@ -1,13 +1,12 @@ -// Positive order draws in front; zero retains geometric depth. Keep the usual -// 0.001 NDC offset away from the clipping planes, but reduce it near either -// plane: perspective depth can be much closer to 1 than this fixed offset. -// -// Using order / (1 + abs(order)) for the limited region keeps ordering monotonic -// (including the paper background's -2). Less than half the remaining depth is -// consumed, so valid vertices stay valid. Out-of-range/behind-eye vertices get -// no offset and remain subject to the real near/far clipping planes. +// Positive draw order moves geometry towards the camera. In dense blocks, +// child ranks occupy a narrow fraction of the INSERT depth band: a 0.001 +// NDC bias can quantize two overlapping lines/masks to the same depth value, +// especially after changing view/zoom. Use a wider, yet bounded range for +// CAD 2D draw order. Limit displacement to less than half the available +// clip-space room, so we never push valid geometry across near/far planes. +// This is a screen-only GPU change; PDF order uses its own stable sorting. fn apply_draw_order(clip: vec4, order: f32) -> vec4 { let room = 0.5 * max(0.0, min(clip.z, clip.w - clip.z)); - let scale = min(0.001 * max(clip.w, 0.0), room / (1.0 + abs(order))); + let scale = min(0.02 * max(clip.w, 0.0), room / (1.0 + abs(order))); return vec4(clip.xy, clip.z - order * scale, clip.w); }