I have slightly modified the optixTriangle
example of OptiX 7.2 to obtain the image of a single sphere with triangular mesh. The whole code is attached.
I’m shading the sphere using the information about the normal. Accordingly, the sphere appears light green at the center and darker at the borders. The __global__
hit function passing the color information through the payload is __closesthit__ch()
.
Now I would like to add a plane below the sphere of a different color (blue, for example) and “see” the interaction between the two (sphere and plane).
How should I implement the reflection?
generateMesh.cpp (2.4 KB)
generateMesh.h (139 Bytes)
optixTriangle.cpp (25.8 KB)
optixTriangle.cu (6.5 KB)
optixTriangle.h (785 Bytes)
Please work through the OptiX Programming Guide
If you understood how optixTriangle works, then you would now have to look into the other OptiX 7.x SDK examples and have a look at the ones using OptixInstance which explain this.
Basically you would need to build another function to generate a plane mesh geometry acceleration structure (GAS), then build an OptiX scene graph which has an instance acceleration structure (IAS) as the root node to which you add two OptixInstance elements, one referencing your sphere GAS and the other the plane GAS traversable handle.
The OptixInstance struct contains an affine matrix with which you can place the meshes inside your scene if the have been built at the origin, e.g. move the sphere up by radius to lie exactly over the plane.
Then you would need to implement another closest hit shader you want to use for the plane geometry.
That would need to be added to the program groups building the OptixPipeline.
To select the normal shader for the sphere and the blue shader for the plane, you would need to have two hit records in your shader binding table.
Which hit record is used per geometry is defined with this SBT index formula:
https://raytracing-docs.nvidia.com/optix7/guide/index.html#shader_binding_table#acceleration-structures
Note that this contains an sbt-instance-offset
which comes directly from the OptixInstance::sbtOffset
field. Means that can be used to select which hit record (0 or 1) is used for the sphere and the plane mesh via the OptixInstance.
The SBToffset field inside the optixTrace() would be 0 then if there is only one ray type.
Please also follow the links to more OptiX 7 introduction and advanced examples in this post:
https://forums.developer.nvidia.com/t/optix-7-2-release/156619
My OptiX 7 examples there have plane, box, sphere, and torus geometry generators already, but use a unidirectional path tracer and a flexible material system which is a steep learning curve for a beginner.