Intersection with Triangles Aligned in the Same Plane

Intersection with Triangles Aligned in the Same Plane

Firstly, thanks for the great library! Really enjoying playing around with it so far.

I have a question related to how Embree handles triangles that are aligned (and overlapping) in the same plane. To illustrate this please refer to the 2D examples below. In case 1, one triangle mesh (b) is enclosed within another (a) and one side is aligned and overlapping. In case 2, the triangle meshes (a and b) are side by side but share a side.

In both of these cases I would like to receive intersection hits for each intersection. In case 1 this would be two back faces and in case 2 this would be one back face and one front face. With what I have tested so far, it seems Embree always returns a single intersection in these cases. The intersection always has the same primitive ID, so there is no z-fighting. 

Is there a way I can receive intersection hits in such cases? Thanks in advance!

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

You can achieve this by using the intersection filter callback mechanism. Register a callback function that that does the following:

if (ray.hit is front facing and closer than stored front facing hit) {

   ray.frontfacing_hit = ray.hit;

} else if (ray.hit is back facing and closer than stored back facing hit) {

  ray.backfacing_hit = ray.hit;

}

ray.tfar = max(ray.frontfacing_hit.tfar, ray.backfacing_hit.tfar);

This intersection filter functions remembers the closest front-facing and back-facing hit in some extended ray fields (ray.frontfacing_hit and ray.backfacing_hit). At the end it resets the hit distance to the largest of the current front-facing and back-facing hit to let the traversal find any potential closer hit inbetween.

This will return the closest front and backfacing hit, which you can test for same (or similar) hit distance to detect the above cases.

Thanks Sven!

Leave a Comment

Please sign in to add a comment. Not a member? Join today