Repository navigation
fix: renders hide edges just behind a face; lines on steep faces draw whole - #983
Merged
bherbruck merged 1 commit intoOct 14, 2026
Merged
Conversation
… whole The CPU renderer (snapshots, MCP screenshots, model renders, the CPU viewport) let a line through its depth test within 2e-4 of the screen depth range. That is a share of the scene, not of what a pixel shows: in orthographic views 2e-4 * (8 * radius + 2), about 2 mm on a 2.4 m design, and in perspective, where the near plane sits at 0.1 % of the camera distance, tens of millimetres near the camera. Close views showed the far edges of thin sheet, and parts a millimetre or two behind it, on its face. Each pixel now keeps the screen depth slope of the triangle it shows, and a line passes where it is no further behind than that slope times its distance from the pixel centre (plus a few f32 steps). Edges and sketch lines lying on a face pass at any slope (on steep faces in small renders they used to lose the near half of their width), and what lies behind a face is hidden once it is further behind than the face's depth changes across the line's width. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
|
Merged, thanks! The slope-based allowance is a much better fit than the fixed share of the depth range, and the before/after close views made the difference easy to see. |
CamWight
added a commit
to CamWight/solidcraft
that referenced
this pull request
Oct 16, 2026
…anar faces stop z-fighting (tangency-labs#1434, tangency-labs#1739) Edges: lines were pulled toward the eye by a share of the depth range (2e-4), about 27 mm in orthographic on a design 34 m across and 0.16 % of the distance in perspective, so edges behind a face showed through it. Opaque faces are now pushed back instead, by a few depth steps and by their own depth slope over one pixel (FACE_BIAS, a hardware depth bias; the section cap, which writes its own depth, adds the same in the shader). It is the CPU renderer's rule since tangency-labs#983: whatever lies on a face (its edges, an origin plane, a sketch, a decal) draws over it at any angle, and an edge behind it stays hidden. The origin plane's square no longer z-fights with a face on the same plane (tangency-labs#1739). Depth precision: where the device has a 32-bit float depth buffer with a stencil, the viewport draws with reversed depth (1 near, 0 far), whose precision follows the distance from the eye (about 1 µm at 10 m, where 24 bits gave 0.6 mm), so a 0.3 mm label no longer speckles at 10 m. reversed_depth decides from the depth format; depth_compare, depth_bias and far_depth turn every test, bias and clear round with it; the CPU keeps its 0-near projection and only the GPU's matrix is turned round (gpu_view_proj). egui clears its depth to 1, so the viewport sets its rectangle to the far plane first (depth_reset). The window asks for the float buffer only when every adapter it could start has one (eframe makes the depth buffer before it picks the adapter); devices are opened with DEPTH32FLOAT_STENCIL8 wherever the adapter offers it. Other devices and safe mode keep Depth24PlusStencil8; the web uses Depth32Float. Headless pictures make the same choice. Tests: crates/gpu/tests/depth.rs runs the issue's reproductions and edge checks on a real GPU with the device's depth and the 24-bit fallback; an_origin_plane_on_a_face_is_tinted_evenly covers tangency-labs#1739. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change
Wrong. The CPU renderer (
snapshot, the MCPscreenshot, model renders, the CPU viewport) let a line through its depth test where it lay within 2e-4 of the screen depth range behind the surface. That range comes from the scene's radius, not from what a pixel shows: orthographic views span8 · radius + 2, so the allowance is about 2 mm on a 2.4 m design and more when the view is zoomed in away from its centre; perspective views put the near plane at 0.1 % of the camera distance, so near the camera the allowance is tens of millimetres. In close views the far edges of thin sheet, and parts a millimetre or two behind it, were drawn on its face.Now. Each pixel keeps the screen depth slope of the triangle it shows. A line lying on a face is at the face's depth where it passes, while the pixel holds the face's depth at its centre,
daway from the line (the distance the line's coverage already uses), so a line passes where it is no further behind thanslope · d, plus a fewf32steps for rounding. Where a section cap sets the depth, its plane's slope counts.crates/render/src/raster.rschanges; it costs onef32per render pixel (as the depth buffer). The GPU viewport is unchanged (Section cut faces hide the inside; perspective no longer shows hidden edges through solids #83 fixed its perspective depth bias).Validation
Two tests in
crates/render/src/raster.rs, both on a close front view 40 mm high on 64 pixels (128 render pixels of 0.3125 mm), orthographic and perspective (fov 0.6):edges_behind_a_thin_sheet_stay_hidden_in_close_views: a red edge 1 mm behind a sheet, in a design of radius 1200. The old allowance was 2e-4 · (8 · 1200 + 2) = 1.92 mm, so onmainthe edge is drawn (64 red pixels, square to the view). Square to the view the sheet's slope is 0; tilted 45° the edge lies 1 / cos 45° = 1.414 mm behind along the view, and the sheet's depth changes 0.3125 mm per pixel, at most 2 · 1.7 · 0.3125 = 1.06 mm over a 1.2 pixel line (1.7 pixels from its middle to the edge of its anti-aliasing). Hidden in all four cases; drawn over everything it is in the picture.edges_on_a_steep_face_draw_whole: the outline of a sheet turned 70° from the view (its depth changes tan 70° · 0.3125 = 0.86 mm per pixel) and a line across it, in designs of radius 30 and 1200, draw exactly as many pixels as the same lines drawn over everything. Onmain, radius 30 (orthographic) drew 238 of 286.The pictures below: a 400 × 300 × 1 sheet at z = 200 with a 16 mm boss and a 10 mm hole, a 60 × 60 × 30 box 1 mm under the sheet, and a 4000 × 40 × 40 beam elsewhere that makes the design large;
solidcraft-cli mcp --inthe script,screenshotwith acamera, 1000 × 700.mainIn those close views only pixels where hidden lines were drawn change (3042 to 6479 per picture, all lighter); in the whole design fitted to the view, 858 pixels are darker where lines on sloped faces now draw their full width.
cargo fmt --all --checkandcargo clippy -p solidcraft-render -p solidcraft-engine --all-targets --profile ci --locked -- -D warningsclean (workspace clippy is clean too apart from the Windows-onlyunused_mutinsolidcraft-mcpthatmainhas);cargo test -p solidcraft-render32 passed; the engine's view, snapshot, render, screenshot and thumbnail tests 33 passed; the UI's render, snapshot, screenshot and section tests 10 passed.The whole
cargo xtask cion this commit (f7e3ae7, on2eb292dd), on Windows, merged with the two-lineunused_mutfix that draft #907 proposes (since #901, workspace clippy-D warningsstops insolidcraft-mcpon Windows before any test runs). It passes fmt, assets, licences, layers, clippy-D warnings, the wasm32 check, and the render, doc and kernel tests. What failed is not this change's:main(8fb5742with the same two lines) fails on this machine the same day, alone too: the robustness goldensall_0toall_3,cmd::motion::tests::motion_study_plays_and_exports, and the path-scope tests of the mcp, io and ui-egui libs (this machine's temp folder has an 8.3 short name in its path, which the path scope refuses).press_pull_on_the_enclosure_lid_is_prompt(a timing test) failed beside the other test binaries and passes alone, and the action matrix's sample (Action matrix: every ordinary action on every face, edge, vertex and body of the corpus #553) timed out on a few actions beside them; run alone it passes (1145 of 1195 actions, the rest as in its baseline). This commit changes onlycrates/render/src/raster.rs.Screenshots of the behavior (when observable)
Close view, orthographic:
maindraws the box under the sheet and the sheet's own bottom edges on its top face; this change hides them.The sheet's back corner and the boss and hole, enlarged (
mainleft, this change right): the 1 mm sheet's bottom edges, the box's edge and the hole's bottom rim are gone; the boss's base edge stays.Perspective:
7° above the sheet, where its top face is steepest on screen: the box, the boss's far base and the hole's bottom rim are hidden, while the boss's near base edge, its top rim and the hole's rim are drawn whole.
Integration status
Based on
origin/main2eb292dd(#824), one commit, not stacked. It merges cleanly withorigin/mainb34d4523(#980), which has changed nothing incrates/rendersince. Searched upstream issues and pull requests, open and closed: #83 fixed the GPU viewport's perspective depth bias; nothing reports this for the CPU renderer. The open render pull requests #800, #849 and #863 change only line 79 ofraster.rs(shademadepub(crate)); this change does not touch it, and their hunk applies on top of it. No new command, parameter or stored field (format unchanged). Action matrix: not run (rendering only).🤖 Generated with Claude Code