Should I use Intel Embree via API or via the project's source code itself?

650 views Asked by At

I am thinking about using Intel Embree in my renderer and currently playing around with Embree tutorials.

So, the question is, is it possible to use Intel Embree efficiently via API?

I mean, I can see that the functions from <embree2/rtcore.h>, <embree2/rtcore_ray.h>, e.t.c use some internal data structures like RTCRay. And obviously, since I can't overload any operators I always have to cast my data structures to Embree data structures and vice versa. And that's not even just a type cast, that's a construction of a new object.

For example, before calling rtcIntersect(RTCScene scene, RTCRay ray); I construct RTCRay ray from my Ray class object and then when the function returns some data, I copy some values back.

It doesn't look like a good way to use Intel Embree.

2

There are 2 answers

0
user3322793 On BEST ANSWER

Constructing RTCRay, use rtcIntersect, then copy the data back. The overhead is negligible (<0.5%) compared to ray-traversing and primitive intersection.

I think Corona render uses RTCRay internally, so they save the 0.5% overhead.

I know that V-Ray does exactly constructing RTCRay, use rtcIntersect, then copy the data back.

General advice: Avoid premature optimization. Implement working code and then use profiler to guide your optimizations.

0
Adam Davidson On

I used the API directly from the pre-built binaries. The downside is there are no vector or matrix features to work with, but on the upside it means you can use any other library you want, it's not decided for you. I used the open source single header file linalg.h to keep things simple.

Here is my EmbreeTest project that has a single Main.cpp file which gets you started. Just use the Embree installer and that's all you need.

As for efficiency, if you start with this project you should be able to identify if there are any performance bottlenecks, as it does almost nothing but call Embree. The ray cast method just copies the ray org and dir that I've calculated into the RTCRay structure on the stack. I don't think this will be much of an overhead. Restructuring to cast multiple rays at once will make more of a difference to performance than the copy for sure.