Closed tomas16 closed 5 months ago
Hi @tomas16
I believe Embree 2, by default, does robust ray intersections whereas Embree turned that into a feature flag that Mitsuba does not enable.
To enable robust ray intersections in Mitsuba, you need to replace this line with: rtcSetSceneFlags(s.accel, RTC_SCENE_FLAG_ROBUST);
and then recompile the project.
I haven't tried it myself on your reproducer yet, could you give this a go?
Hi @njroussel, thanks. Setting that flag solves the issue.
I've been building custom versions of mitsuba by invoking cmake and ninja, but that doesn't build a fully finished python package. If I build through python -m build
, how can I specify which variants to build, or any additional cmake flags, like e.g. MI_ENABLE_EMBREE? So far I've been mixing and matching and manually copying files, but I might want to build a customized version of mitsuba to host on our company-internal pypi server.
@tomas16 this sounds related to #1147, I suggest continuing the install / package-related discussion over there.
Hi @tomas16
I'll close this issue, we've resolved the original problem.
I've put this on our internal feature tracker - it would be practical to have this a feature flag one can enable at runtime. If anyone comes across this, we'd welcome a PR for it - it should be fairly simple.
Summary
I encountered a case where rays seem to pass through solid geometry. 2 of the rays are at fairly glancing angles, but 3 others aren't. In all 5 cases, the rays seem to hit the edge between 2 triangles.
System configuration
System information:
OS: 14.2 CPU: b'Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz' Python: 3.11.8 | packaged by conda-forge | (main, Feb 16 2024, 20:51:20) [Clang 16.0.6 ] LLVM: 16.0.6
Dr.Jit: 0.4.4 Mitsuba: 3.5.0 Is custom build? False Compiled with: AppleClang 14.0.0.14000029 Variants: scalar_rgb scalar_spectral llvm_ad_rgb
Description
I've extracted the relevant geometry from the original mesh and created a standalone example. In the example, I compare to:
trimesh.ray.ray_pyembree.RayMeshIntersector
: trimesh uses Embree version 2. (I refer to this asEmbreeIntersector
)trimesh.ray.ray_triangle.RayMeshIntersector
: a python fallback, similar to mitsuba without Embree. (I refer to this asPyIntersector
)Coloring in the plots:
In above screenshot, the left and middle geometry are parts of a sphere. According to mitsuba, the rays hit on the inside. Comparing to trimesh, the reason is they first pass through a different triangle at a shallow angle.
On the right, there are 3 rays passing through a first surface and then hitting a surface behind it. trimesh correctly finds the intersections with the first surface.
Note that even the
EmbreeIntersector
in trimesh gets this right. But trimesh uses Embree 2, vs mitsuba's Embree 3.Some close-ups:
I tried to narrow down the root cause, so I compiled custom versions of mitsuba:
prim_index
will be different from trimesh output, essentially the other triangle that shares the edge. (which is fine)PyIntersector
results.Another thing I observed is that in all these cases, the rays and the edges of the triangles they're intersecting form a plane. And moreover, these are exactly the XZ and YZ planes...
To investigate this further, I added a rotation around the Z axis of both the rays and mesh. Results were mixed:
Steps to reproduce
submesh.ply.zip