r/GraphicsProgramming • u/Tetrakis-dev • 1h ago
Video Cross-sections on real, messy meshes: GPU cut while the plane moves, CPU cap fill when it stops
I've been working on a section-cut tool for Unity URP and wanted to share how it's split, since most of the effort went into the meshes rather than the cut itself.
- While the plane moves: a compute shader cuts the triangles every frame (0.05–0.27 ms for ~1M tris). No caps, just the cut edges and the clipped mesh.
- When the plane stops: the CPU (Burst) rebuilds the section loops and fills the caps with LibTessDotNet, solid by solid. Up to ~65 ms on 2M tris, so it only runs once the plane is still.
- Zero-thickness surfaces are drawn as lines instead of being filled.
The hard part was real-world input. The 3D-printer model had tens of thousands of duplicated and reversed triangles, the game kits aren't closed, and the medical scan (public-domain skull) has holes. Shader-only approaches with stencil caps tend to break on exactly those cases, so the tool dedupes first, then closes small gaps per solid with a tolerance relative to its size.
Happy to go into the loop-building or gap-closing details if anyone's dealt with similar data.
AI disclosure: parts of the code were written with an AI coding assistant (Claude Code). The approach, the test meshes and the numbers come from my own runs.
•
u/AutoModerator 1h ago
Recently updated rules. Please check that your post is in compliance with Rules 1, 4, 5, and 6 on the sidebar. TL;DR:
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.