fix: increase bounded screen draw-order depth resolution for overlapping block wipeouts

This commit is contained in:
gianlucafiore committed 2026-10-12 18:07:48 -03:00
1 parent 93a54d66e3
commit 1074c81f52
1 file changed
+8 -9
+8 -9
View File
@@ -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<f32>, order: f32) -> vec4<f32> {
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<f32>(clip.xy, clip.z - order * scale, clip.w);
}