I understand how to associate different hit programs with different ray types. I don’t understand how to call different hit programs( closest hit in this case) for the same ray depending upon the material of the geometry intersected. All geometries are made up of triangles.
It might be worth diving into the optixMeshViewer sample. Specifically in sutil/Scene.cpp look at Scene::createSBT() to see how it is setting up multiple triangle meshes with different materials.
Thank you for the quick response.
If I understood it correctly, the above example actually uses only one closest hit function but does different calculations based on the material inside the function itself. What I am looking for is to have different closest hit functions for each material itself.
You’re right optixMeshViewer just uses one shading program for closest-hit radiance. To use different programs, it’s just separate entries in the SBT. All the samples have separate closest hit programs for radiance vs AO, and setting up multiple radiance shaders is similar.
You can find an example of separate closest hit programs for radiance in samples_exp/optixWhitted.
That one has different kinds of geometry, but you would do exactly the same thing to make two different programs shade the same geometry. Create separate hit groups, and give each a different entry function name for your separate closest hit shaders. Keep track of which SBT slot each one is in, and use those offsets in your acceleration structures.
If you want to factor out the geometry, try modifying optixWhitted to use the same intersection program for both spheres. You could return different colors from the two closesthit programs assigned to the spheres.