# Ray contact points for objects

**URL:** <https://forums.developer.nvidia.com/t/ray-contact-points-for-objects/81124>\
**Category:** OptiX\
**Created:** [September 4, 2019, 5:48am UTC](https://forums.developer.nvidia.com/t/ray-contact-points-for-objects/81124 "2019-09-04T05:48:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![CherryBlossoms](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@CherryBlossoms](https://forums.developer.nvidia.com/u/CherryBlossoms)\
**Post date:** [September 4, 2019, 5:48am UTC](https://forums.developer.nvidia.com/t/ray-contact-points-for-objects/81124/1 "2019-09-04T05:48:07Z")

</div>

Hello.  
Currently, we are looking for a way to get all the points that a ray can touch when penetrating, without any reflection or refraction of one object.  
I’m sorry for the rudimentary question, what kind of method is there?

---

<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:** [September 4, 2019, 8:01am UTC](https://forums.developer.nvidia.com/t/ray-contact-points-for-objects/81124/2 "2019-09-04T08:01:53Z")

</div>

Are you saying you want to gather all intersections along a straight ray?

Please follow the links in my answer to this thread for possible implementation methods and caveats to consider:  
[url][distinguish objects when closest hit program occured - OptiX - NVIDIA Developer Forums](https://devtalk.nvidia.com/default/topic/1051105/optix/distinguish-objects-when-closest-hit-program-occured/%5B/url%5D)

---

<div class="post-metadata">

**Author:** ![CherryBlossoms](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@CherryBlossoms](https://forums.developer.nvidia.com/u/CherryBlossoms)\
**Post date:** [September 5, 2019, 7:48am UTC](https://forums.developer.nvidia.com/t/ray-contact-points-for-objects/81124/3 "2019-09-05T07:48:20Z")

</div>

Thank you for your reply. I will read the thread.  
That’s right about the question.  
For example, suppose you have a sphere with a center (1,1,1) radius of 0.5 and a ray fired from (0,0,0) to (1,1,1). I want to get two intersections where the line meets the sphere.

---

<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:** [September 5, 2019, 8:23am UTC](https://forums.developer.nvidia.com/t/ray-contact-points-for-objects/81124/4 "2019-09-05T08:23:40Z")

</div>

Your sphere example is not quite what I explained. I thought you wanted to capture all intersections along a ray inside a full scene where all intersection programs exist already.

Your sphere example would be a custom geometric primitive intersection routine. It’s your responsibility to calculate the primitive intersection points inside an intersection program for any custom geometric primitive, like parametric spheres. Only triangles have built-in intersection routines in OptiX 6 and 7.

The OptiX SDK contains example code for a ray-sphere intersection routine. Search the SDK sources for \*.cu files with “sphere” in the name and you’ll find that intersection calculation.

---

<div class="post-metadata">

**Author:** ![CherryBlossoms](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@CherryBlossoms](https://forums.developer.nvidia.com/u/CherryBlossoms)\
**Post date:** [September 6, 2019, 8:05am UTC](https://forums.developer.nvidia.com/t/ray-contact-points-for-objects/81124/5 "2019-09-06T08:05:41Z")

</div>

I misread your question because my English reading ability was insufficient.

I saw a sample of .  
In this sample, is it correct that the registered process (intersect this time) is called when the light beam emitted by \<pinhole\_camera\> hits an object?  
Also, when it is called, is it correct that the ray information that was struck is passed in the ray of rtDeclareVariable (optix :: Ray, ray, rtCurrentRay,);

I ’m sorry to ask you some basic questions.

---

<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:** [September 6, 2019, 8:30am UTC](https://forums.developer.nvidia.com/t/ray-contact-points-for-objects/81124/6 "2019-09-06T08:30:46Z")

</div>

> [@](#):
>
> In this sample, is it correct that the registered process (intersect this time) is called when the light beam emitted by \<pinhole\_camera\> hits an object?

Yes, that intersection program is called whenever a ray hits a bounding box for a geometry with that custom intersection program assigned.  
Also see this thread:  
[https://devtalk.nvidia.com/default/topic/1050973/optix/when-the-rtpotentialintersection-t-return-true-is-t-the-any-hit-or-must-closest-hit/post/5334456](https://devtalk.nvidia.com/default/topic/1050973/optix/when-the-rtpotentialintersection-t-return-true-is-t-the-any-hit-or-must-closest-hit/post/5334456)  
[https://raytracing-docs.nvidia.com/optix6/guide\_6\_0/index.html#programs#intersection](https://raytracing-docs.nvidia.com/optix6/guide_6_0/index.html#programs#intersection)

> [@](#):
>
> Also, when it is called, is it correct that the ray information that was struck is passed in the ray of rtDeclareVariable (optix :: Ray, ray, rtCurrentRay,);

Yes, the semantic variable of type rtCurrentRay is accessible inside the intersection program.  
Note that the coordinate space in that intersection program domain is object space, also in the anyhit program, but it’s in world space inside the raygeneration and closest hit program domain. See Table 5 and 7 here:  
[https://raytracing-docs.nvidia.com/optix6/guide\_6\_0/index.html#programs#internally-provided-semantics](https://raytracing-docs.nvidia.com/optix6/guide_6_0/index.html#programs#internally-provided-semantics)

If you’re new to OptiX, I would recommend to watch my GTC 2018 OptiX Introduction presentation.  
Links to that and the examples’ source code here:  
[https://devtalk.nvidia.com/default/topic/998546/optix/optix-advanced-samples-on-github/](https://devtalk.nvidia.com/default/topic/998546/optix/optix-advanced-samples-on-github/)  
GTC 2018 S8518 - An Introduction to NVIDIA OptiX [http://on-demand-gtc.gputechconf.com/gtc-quicklink/4JAjAp](http://on-demand-gtc.gputechconf.com/gtc-quicklink/4JAjAp)

Then watch the GTC 2019 presentation from David Hart about new features in OptiX 6.0.0.  
GTC 2019 S9768 - New Features in OptiX 6.0 [http://on-demand-gtc.gputechconf.com/gtc-quicklink/4FB3l](http://on-demand-gtc.gputechconf.com/gtc-quicklink/4FB3l)

If you’re starting a new development, there is also the newest OptiX 7 API.  
The device side programs behave mostly the same, but the host side API is very different:  
[https://devtalk.nvidia.com/default/topic/1058310/optix/optix-7-0-release/](https://devtalk.nvidia.com/default/topic/1058310/optix/optix-7-0-release/)  
[https://devtalk.nvidia.com/default/topic/1058577/optix/porting-to-optix-7/post/5368038](https://devtalk.nvidia.com/default/topic/1058577/optix/porting-to-optix-7/post/5368038)

The landing page for all NVIDIA raytracing docs is here: [https://raytracing-docs.nvidia.com](https://raytracing-docs.nvidia.com)

---

<div class="post-metadata">

**Author:** ![CherryBlossoms](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@CherryBlossoms](https://forums.developer.nvidia.com/u/CherryBlossoms)\
**Post date:** [September 11, 2019, 8:07am UTC](https://forums.developer.nvidia.com/t/ray-contact-points-for-objects/81124/7 "2019-09-11T08:07:26Z")

</div>

Thank you for your polite explanation. I was saved.  
I will study for a while.  
I might ask again.

---

<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/ray-contact-points-for-objects/81124/8 "2022-06-14T21:05:32Z")

</div>

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


