Repository navigation
Conversation
…length TriangleRay::crossing() widened its three barycentric tests by one slack that bounded every edge by |e1| + |e2|. Across a short edge that widening grows with the triangle's aspect ratio: on a sliver 251 long and 6 wide at coordinates near 1000, rays 0.08 units outside the short edge crossed it (float). Each test now carries the L1 length of the edge it measures from (u: e2, v: e1, 1 - u - v: e2 - e1), as the polygon test in FaceT::rayCrossing() already does, so the widening stays a few ulps of the coordinates whatever the triangle's shape. A shared edge is still widened by at least that rounding error from each side. The new test fails without the change (both precisions). The float tape kernels (signedDistance once and 16 times, firstHit) and a TriMeshSDF firstHit kernel compile to the same registers, stack and spills as the base, and the host Tape and ClosestPrimitive probes' out-of-line tape functions are unchanged. Closes #368 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012mR37bzMSJWYPpFgLhy9sk
|
@claude review |
|
Claude finished @rmrsk's task in 28s —— View job Review of #371: per-edge slack in
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012mR37bzMSJWYPpFgLhy9sk
|
@claude review |
|
Claude finished @rmrsk's task in 26s —— View job Review of #371: per-edge slack in
|
…e correctness fix) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012mR37bzMSJWYPpFgLhy9sk
Summary
Background
TriangleRay::crossing()widens its three barycentric tests so that a ray through an edge two triangles share cannot slip between them. It used one slack for all three tests, bounding every edge's length by|e1| + |e2|. Across the short edge of a long, thin triangle, the widening then grows with the aspect ratio. On Crytek Sponza (float), rays 0.08–0.09 units outside a sliver 251 long and 6 wide reported hits in front of the true one (#368).Closes #368
Solution
Each test now carries the L1 length of the edge it measures from:
e2for the u test,e1for the v test, ande2 - e1for the1 - u - vtest. The polygon test inFaceT::rayCrossing()already works this way. The widening stays a few ulps of the coordinates, whatever the triangle's shape. A shared edge is still widened by at least that rounding error from each side, so no ray slips through. It is still division- and square-root-free, at a few adds per test.A new test in
TestRayMesh.cppuses a sliver like Sponza's, at coordinates near 1000. A second face beside it widens the BVH leaf's box, as neighboring faces do in a real mesh; without it, the box test rejects the rays before the triangle test runs. Rays 20 times the rounding error outside the short edge must miss, and 4 times it outside a long edge. Without the fix, the short-edge checks fail in both precisions.Side-effects
A ray passing just outside a thin triangle's short edge no longer counts as crossing it. That is the documented behavior (
RayTracing.rst: "within rounding error"). The hit for these rays can change, now correctly, inTriMeshSDFray queries and in tapes holding one.Alternative solutions
2 * area: tighter by at most a factor of 3, but needs square roots.Performance
Receipt:
Performance/receipts/thin-triangle-crossing-187f93ec.md(814aa6d against 0a4fbcc). Both sections are yellow. The maintainer accepted them: "Accept as cost of correctness fix".MeshCSG/union-tape/frame,MeshTape/{mesh,tape,view}/frame,Render/mesh/frame). That is expected: rays just outside a thin triangle's short edge now miss it, so a few pixels hit something else. Double checksums are unchanged.Ray/mesh,RayCrossing,MeshTape,MeshCSG,Render/mesh,SurfaceParts). Each triangle test now does a few more double operations, and the A4000 runs double at 1/32 of its float rate.Ray/mesh/intersects-random/floatat +4.1%.MeshCSG/union-tape/frame/float), for the same reason as on the host.Where to look
Source/EBGeometry_TriangleRay.hpp, the slack computation. This kernel serves everyTriMeshSDFray query, and its SIMD-pack form serves theTriangleSoAgroups.-DEBGEOMETRY_TEST_BOTH_PRECISIONS=ON), and the new test fails without the fix.[gpu]tests ofTestRayMeshDeviceandTestTriangleSoApass on an RTX A4000 (sm_86).signedDistance()once and 16 times,firstHit()) and aTriMeshSDFfirstHit()kernel have the same registers, stack and spills as the base. The host Tape and ClosestPrimitive probes' out-of-line tape functions are unchanged.Reviewer checklist (to be completed by a human)
@claude review.🤖 Generated with Claude Code
https://claude.ai/code/session_012mR37bzMSJWYPpFgLhy9sk