Constructive solid geometry

Hi. I try to learn OptiX and now I develop an application to view constructive solid geometry objects (CSG). Now I try to compile (when my application execute) runtime-created CUDA files with intersection function for CSG objects, but it is too expensive. Can someone explane me, how I can do this easier?

I suggest you start by modifying one of the samples included in the OptiX SDK. Unless you convert your CSG objects to triangles, you’ll have to write new bounding box and intersection programs for your CSG objects.

Use this forum to ask questions about specific problems you encounter, and include error messages you receive.

I ask about some way, which will help me to solve my problem. I think, in this forum I can ask any questions about OptiX, which didn’t answered in OptiX documentation.
I try, for example, render a box without sphere (both in (0, 0, 0), sized 1 meter). For any intersection with box I have to ask, did this ray intersect sphere? If it intersect sphere, I have to continue search intersection with other objects, otherwise I have to return intersected box point. Bounding box for this CSG object will be equal with original box. Can someone explain me, how I can do this?

Your ray payload needs to contain a bit that indicates whether the ray is in a sphere. Set it to one upon entering the sphere and zero upon leaving. Your closest hit program for the sphere sends a new ray in the same direction with this bit set. Your closest hit program for the box sends a new ray in the same direction if the bit is one and sets the color of the ray payload if the bit is zero.

In order to render the interface between the box and shere where they touch, you also need to keep a bit indicating whether the ray is inside the box.

Thank you, I will try this method. But how can I apply this to all types of objects and all types of CSG operations? Have someone things about unification this process?