Repository navigation
Description
Behavior
Edges behind a face are drawn on top of it, and thin features z-fight. It shows most on large models.
- Orthographic: edges up to about 27 mm behind a face show through it on a model about 34 m across, however far you zoom in. On a small model it's a fraction of a millimetre. Bolts, washers and nuts behind a plate show through the plate. Corners show short ticks where an edge carries on just behind a face, and circles show hooks near their silhouette, where their back half is only millimetres behind the front.
- Perspective: the same, by camera distance. At 10 m, edges 12–15 mm behind a face show through it; at 2.5 m they don't.
- Z-fighting: a face 0.3 mm in front of another speckles at 10 m in perspective, and it's solid at 2.5 m. That's the case for raised lettering and thin plates on a face.
It was seen first on a large private STEP model; the reproduction below is public. Measured on main at 5fa8e7d, Windows 11, NVIDIA Quadro RTX 4000, D3D12.
Reproduction
All in the desktop app through the control channel. Screenshots are in the comment below.
-
A 20 mm plate with a 30 mm washer 22–25 mm behind its front face, and a 30 m × 8 m slab far away to make the scene large:
{"commands": [ {"command": "solid.box", "params": {"length": 30000, "width": 8000, "height": 100, "corner": [-15000, 3000, -3000], "body_name": "slab"}}, {"command": "solid.box", "params": {"length": 200, "width": 20, "height": 200, "corner": [0, 0, 0], "body_name": "plate"}}, {"command": "solid.cylinder", "params": {"radius": 8, "height": 60, "base": [100, -20, 100], "axis": "Y", "body_name": "bolt"}}, {"command": "solid.cylinder", "params": {"radius": 15, "height": 3, "base": [100, 22, 100], "axis": "Y", "body_name": "washer"}} ]}Camera
{"target": [100, 10, 100], "yaw": 0.35, "pitch": 0.25, "distance": 450}:- Orthographic: the washer's circle shows through the plate.
- Perspective: hidden.
- Orthographic without the slab: hidden.
-
A 2 m plate 10 mm thick, a 600 mm washer 12–15 mm behind its front face, and a red label 0.3 mm thick on it. The commands are the same apart from sizes;
appearance.assigncolours the label#cc2222. In perspective with target[1000, 5, 1000]:- At 10 m the washer shows through and the label speckles, with or without the slab.
- At 2.5 m both are right.
Cause
Edges. biased_z (assets/shaders/viewport.wgsl) pulls lines toward the eye by screen.z = 2e-4 (crates/ui-egui/src/gpu.rs, the uniform's 2e-4):
- Orthographic: that's a fixed step of clip depth.
Camera::clipsets the orthographic range to8r + 2mm, whererisscene_radius(crates/ui-egui/src/viewport.rs): the model's half-diagonal plus how far its centre is from the target, and at least twice the view's half-height. So the pull is2e-4 × (8r + 2)mm. For a model 34 m across,r≈ 17 m and the pull is ≈ 27 mm. Zooming in doesn't shrinkr. - Perspective: the point moves toward the eye by
8 × 2e-4= 0.16 % of its distance: 16 mm at 10 m.
Z-fighting. In perspective the near plane is max(d − 2r, d / 1000) (Camera::clip). Since r is at least twice the half-height (about 0.62 × d at the 0.6 rad field of view), d − 2r is always negative, so the near plane is always d / 1000, whatever the model's size. With the 24-bit depth buffer (DEPTH_BITS = 24, Depth24Plus) one depth step at the target is about d × 6e-5: 0.6 mm at 10 m.
Earlier work on the same family: #83 (hidden edges through solids in perspective), #305 (near-plane clipping), #983 (render edges just behind a face). Open PR #1135 adds Depth32Float textures for its ambient-occlusion pass, but the main depth buffer and the edge pull are unchanged there.
Directions (the choice is the maintainer's)
- Edges: pull them by an amount tied to the pixel size at their depth (a pixel or two), not a fraction of the depth range, so the pull shrinks as you zoom in. The orthographic range could also fit the scene's depth along the view direction rather than
8r. - Z-fighting:
- a reversed-Z projection with a 32-bit float depth buffer (
Depth32Float, available on D3D12, Vulkan, Metal, WebGPU and WebGL2); or - a near plane taken from the scene's nearest point rather than
d / 1000.
- a reversed-Z projection with a 32-bit float depth buffer (
Activity
CamWight commentedon Oct 15, 2026
Screenshots of the reproduction above, in the desktop app (
mainat 5fa8e7d with an unrelated meshing fix; Windows 11, D3D12).1. The plate, bolt and washer, with the 30 m slab
2. The 2 m plate: a washer 12–15 mm behind its front face and a 0.3 mm red label on it, in perspective
CamWight commentedon Oct 16, 2026
Plan for this one (claimed in draft #1768, which also takes #1739: the origin-plane square z-fighting with a face on the same plane comes from the same family).
A correction to the issue first: #1555 moved the renderer into
crates/gpu, so the edge pull's2e-4is now incrates/gpu/src/view.rs(uniform_bytes), and the depth format isDepth24PlusStencil8(the stencil marks section caps). A nice side effect of #1555: headless pictures use the viewport's pipelines, so one fix covers both, andcrates/gpu/tests/capture.rscan test it on a real GPU.1. A depth range fitted to what's shown.
Camera::clipkeeps its radius form for the CPU callers; a bounds-aware form fits near and far to the shown bodies along the view direction. In perspective the near plane is never closer than today'sd / 1000, and with the eye outside the model it's about 1000× finer at 10 m. In orthographic the range is the scene's depth, not8r + 2.2. Faces pushed back by their own slope, instead of lines pulled forward by a share of the depth range. This is the same rule the CPU renderer has had since #983: a line on a face shows where it's no further behind the face than the face's slope spans across the line's width. On the GPU it's a slope-scaled depth bias on the opaque face pipelines. Section caps write their own depth, so
fs_solid_cutadds the same push by hand.biased_zshrinks to a rounding allowance. Edges on a face draw whole at any angle, and edges behind it stay hidden. Anything lying exactly on a face (an origin plane, a sketch) sits cleanly on top, which is #1739.3. Reversed-Z with a 32-bit float depth buffer, where the device has it. The viewport always draws into its own target, which the SSAA path already does, so the depth format is chosen at runtime:
Depth32FloatStencil8when the adapter offers it;Depth32Floaton the web;One
reversedswitch drives every compare, the clear value, the bias signs,cap_depthand the near-plane cut invs_line. CPU code keeps the 0-near convention, soto_screenand the fit check don't change.Tests:
After that come planted faults, D3D12, Vulkan and the wasm build, SSAA and MSAA on and off, a frame-time check, and before and after screenshots from the app.
@CypherNaught-0x, @0xlillith: a heads-up, since #1135 and #1086 add depth passes. With part 3, your
Lesstests would need to come from the same helper so they flip with it. I'll make that a one-line change for you and mention it on your PRs when it's ready.🤖 Generated with Claude Code
Viewport: hidden edges no longer show through faces, and thin or copl…
Viewport: hidden edges no longer show through faces, and thin or copl…
Viewport: lift selected and hovered edge highlights toward the eye
Viewport: lift selected and hovered edge highlights toward the eye
Section Analysis: edges behind the cut no longer show through the cap (…
Viewport: a selected edge's highlight no longer shows as a wedge on a…
Section Analysis: the cap is marked by true depth, so far edges no lo…