Two geometries with different colors and materials

I’m following the optixPrimitiveIndexOffsets project and I’m trying to create two geometries with different properties.
I’m using the triangle_mesh for each geometry however I don’t succeed to create it.
do you have simple example with two geometries, that uses triangle_mesh, with different colors or materials?

I would appereciate your help.

I moved this thread to the OptiX forum for you.

Well, that optixPrimitiveIndexOffsets example is only using a single material.

(I’m looking at the OptiX SDK 6.5.0 version of it.)

There are four objects which are instanced inside the function createSingleGeometryGroup() or createMultipleGeometryGroups() and they are all using the same single material given as an argument there.

If you want that to have a different material per instance, then you would need to generate four different materials in a std::vector at the beginning of createScene(), look for Material matl = context->createMaterial();, then give that vector of materials to the functions above, and pick a different material index inside the loop over the four instances, means there should be a line change from
gis.push_back( context->createGeometryInstance( mesh, &matl, &matl+1 ) );
to something like
gis.push_back( context->createGeometryInstance( mesh, &matls + i, &matls + i + 1 ) );

And maybe another one for the floor which follows after that, so you’d need five materials.

(Not tried myself. I’m not using the old OptiX API anymore and always recommend using OptiX 7 instead.)

Read the chapter about how to build OptiX render graphs with the old API and where Material nodes belong:

The optixPrimitiveIndexOffsets example is showing one specific feature of OptiX which allows to put multiple mesh geometries into one buffer. While that is good because that can reduce the amount of buffer objects, that actually isn’t used very often.

For more information about different materials, either study the optixMeshViewer or my OptiX advanced examples on github which can both handle multiple materials.

Depending on the OptiX SDK version you’re looking at, the older OptiX SDKs examples show that for PLY models or OBJ geometry and their MTL material file format, the new OptiX SDK 7 optixMeshViewer is showing that for the Khronos glTF file format.

In my examples it’s more abstract. Each instanced geometry mesh can have a different material there which is controlled by a single index pointing to the information inside a buffer with the material’s parameters including BXDF index, colors, textures, and other physical properties.