Call multiple closest hit programs on geometry

I am currently writing a simple OptiX program with a few Geometries. One Geometry is 50%transparant and emits some light. The other only emits light. Right now I need a closest hit program for each Geometry. I would however like to make one closest hit program for each Material.

Which means: if I would like a Geometry to emit light, I simple add the light emitting material (=closest hit program). If I also want it to be transparant, I add that material too. Now this means that after my rtPotentialIntersection() I need this:

rtReportIntersection(0);
rtReportIntersection(1);

However this doesn’t work. The variables changed in the closest hit program on index 0, are not seen in the closest hit program at index 1. So it only executes the second rule.

Is there any way in which I can add multiple closest hit programs on a geometry and call them after each other?

I would think the best approach would be to define two materials. Your first closest hit program will be for the material that is 50% transparent and emits light, and your second closest hit program will be for the material that only emits light. Then assign one material to each geometry, and don’t try to call rtReportIntersection() more than once in your intersection program.

You would need to transfer data between programs via the per-ray payload.

The payload which I change in closest hit program 0, remains unchanged in closest hit program 1. Like every closest hit program start with a “clean” ray payload.

Right now I “solved” the issue by adding an if-else clause in my closest hit program for every material property… Not very ideal though.