# Simple shadow ray

**URL:** <https://forums.developer.nvidia.com/t/simple-shadow-ray/215564>\
**Category:** OptiX\
**Created:** [May 25, 2022, 11:33am UTC](https://forums.developer.nvidia.com/t/simple-shadow-ray/215564 "2022-05-25T11:33:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![picard1969](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@picard1969](https://forums.developer.nvidia.com/u/picard1969)\
**Post date:** [May 25, 2022, 11:33am UTC](https://forums.developer.nvidia.com/t/simple-shadow-ray/215564/1 "2022-05-25T11:33:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![droettger](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/droettger/32/14043_2.png) [@droettger](https://forums.developer.nvidia.com/u/droettger)\
**Post date:** [May 25, 2022, 12:05pm UTC](https://forums.developer.nvidia.com/t/simple-shadow-ray/215564/2 "2022-05-25T12:05:17Z")

</div>

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](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](https://forums.developer.nvidia.com/search?q=shadow%20ray%20%23visualization%3Aoptix)

---

<div class="post-metadata">

**Author:** ![picard1969](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@picard1969](https://forums.developer.nvidia.com/u/picard1969)\
**Post date:** [May 26, 2022, 5:22pm UTC](https://forums.developer.nvidia.com/t/simple-shadow-ray/215564/3 "2022-05-26T17:22:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![droettger](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/droettger/32/14043_2.png) [@droettger](https://forums.developer.nvidia.com/u/droettger)\
**Post date:** [May 30, 2022, 7:27am UTC](https://forums.developer.nvidia.com/t/simple-shadow-ray/215564/4 "2022-05-30T07:27:46Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![picard1969](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@picard1969](https://forums.developer.nvidia.com/u/picard1969)\
**Post date:** [June 1, 2022, 6:17pm UTC](https://forums.developer.nvidia.com/t/simple-shadow-ray/215564/5 "2022-06-01T18:17:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TomNVIDIA](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/tomnvidia/32/14181_2.png) [@TomNVIDIA](https://forums.developer.nvidia.com/u/TomNVIDIA)\
**Post date:** [June 14, 2022, 9:05pm UTC](https://forums.developer.nvidia.com/t/simple-shadow-ray/215564/6 "2022-06-14T21:05:19Z")

</div>

Closed on June 14, 2022, 9:05pm UTC


