Simple shadow ray

Good morning,

I am sure this has been asked before and I have had some postings regarding this question, so I apologize for any reiteration that may occur.

I am looking for the simplest use of a shadow ray using OptiX 7.2. Can anyone point me to some simple example code that shows the execution of a shadow ray? Nothing fancy, just a simple shadow cast via ray.

Thanks for any help, and again all apologies if this is a stupid question.

If your scene has only opaque objects, this post explains the fastest method for shadow rays with example code:
https://forums.developer.nvidia.com/t/anyhit-program-as-shadow-ray-with-optix-7-2/181312/2

If you have cutout opacity the same post points to example code for anyhit programs handling opaque and cutout opacity materials.

Don’t use anyhit programs for visibility tests when you’re only handling opaque materials! Note that opaque is meant in the sense of no-cutout and includes transparent materials as well because shadows from that are lit by caustics and those get handled by the light transport algorithms, not by the visibility test rays. A global illumination path tracer only needs boolean visibility tests.

Further down it describes where to find example code inside the SDK attenuating transmissions for shadows in non-global illumation light transports.

OptiX forum search for “shadow ray” topics: Search results for 'shadow ray #visualization:optix' - NVIDIA Developer Forums

1 Like

Thanks for information @droettger - that’s exactly what I am looking for.

So, if one uses the miss shader/program as a shadow ray as in the linked example there really is not need to even have a closesthit program defined? The miss program acts as a renderer.

So, if one uses the miss shader/program as a shadow ray as in the linked example there really is not need to even have a closesthit program defined? The miss program acts as a renderer.

Reformulating that with the proper terminology:
So if the shadow ray type is only using the miss program, there is really no need to have a closest hit and any hit program defined?

Correct. The descriptions inside that linked post and the comments inside the code are pretty clear about not needing a closest hit and any hit program for that kind of shadow/visibility test ray type.
Even if you specified them, they would never be reached with the two ray flags OPTIX_RAY_FLAG_DISABLE_ANYHIT | OPTIX_RAY_FLAG_DISABLE_CLOSESTHIT set, means they are unnecessary for that shadow ray implementation and can stay empty, which means nullptr module and nullptr entryFunctionName fields for both inside the OptixProgramGroupDesc structure for the hitgroup. Only the intersection program would need to be set for custom and curve geometric primitives.

That miss program just sets a boolean visibility flag and what your “renderer” implementation, that is, everything your OptiX device code does, makes of this, is completely your responsibility.

1 Like

Cool. Thanks, I just wanted to be completely sure I was correct.