I’m trying to add spheres to my patch tracer but I’m having trouble with not getting any intersections when I call optixTrace(…).
Currently I have a TLAS with 1 triangle BLAS and 1 sphere BLAS. The TLAS looks correct when viewed in the Nsight Compute AS viewer. I am getting triangle intersections, but no sphere intersections.
These were the steps I tried:
- Add
OPTIX_PRIMITIVE_TYPE_FLAGS_SPHERE
to pipeline_compile_options.usesPrimitiveTypeFlags
.
- Create a program group with the
moduleIS
set to the built-in sphere intersection module retrieved from optixBuiltinISModuleGet
with builtin_is_options.builtinISModuleType = OPTIX_PRIMITIVE_TYPE_SPHERE;
.
- Add an SBT record for every sphere with the correct program group header.
I’m starting to get a bit clueless now. Do I need separate closesthit programs for triangles/spheres ?
Thanks in advance.
Primitive flags OPTIX_PRIMITIVE_TYPE_FLAGS_TRIANGLE | OPTIX_PRIMITIVE_TYPE_FLAGS_SPHERE
, intersection program, and SBT setup sound correct.
Do I need separate closesthit programs for triangles/spheres?
Not necessarily, but the intersection attributes for triangles (two barycentric coordinates beta and gamma) and for spheres (one for the second intersection distance ordered along a ray) are different.
https://raytracing-docs.nvidia.com/optix8/guide/index.html#curves#spheres-and-the-hit-program
When sharing hit programs among different geometric primitive types, you must be able to distinguish the hit primitve types, and that’s done via optixGetHitKind
resp. the convenience functions on top of that, like optixGetPrimitiveType
or optixIsTriangleHit
.
That is used to access and calculate the resp. vertex/shading attributes accordingly per primitive type.
Though if you’re just using the intersection distance optixGetRayTmax
, that’s working for any primitive.
If you implement different hit programs for triangles and spheres, you just need to use the right ones on the resp. SBT entries.
Note that when using multiple ray types (radiance, shadow) all ray types must have the SBT hit records with the sphere intersection program set correctly.
Sounds like an issue with the SBT offset.
Make sure that the two OptixInstance
structures inside your TLAS have their sbtOffset
set to 0 and 1 to get the correct effective SBT entry.
See the formula in https://raytracing-docs.nvidia.com/optix8/guide/index.html#shader_binding_table#accelstruct-sbt
Thank you ! It was indeed the SBT.
I assume you meant to set the sbtOffset
to 0 and the amount of records for the previous instance, like in the docs (example-sbt-for-a-scene) ?
I was assuming you had only one SBT record per GAS.
Yes, the instance sbtOffset of the first instance is usually 0 and then the following instance sbtOffsets have the sum of all previous numbers of SBT records per GAS. (That’s the line with SBT instance offset: 0 ... 6 ...
in that table.)