<p>Raytracing cores can generally do two hardware accelerated things:</p>
<ol>
<li><p>Test an intersection between a triangle and a ray.</p>
</li>
<li><p>Traverse a BVH (Basically to test an intersection between bounding boxes and a ray).</p>
</li>
</ol>
<p>When things are raytraced we don't typically loop through every triangle and test each one. Instead the triangles are placed into a BVH (<a href="https://en.wikipedia.org/wiki/Bounding_volume_hierarchy" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Bounding_volume_hierarchy</a>) which is a set of boxes which partition the triangles. We first test the ray against this BVH as it allows us to quickly ignore large sets triangles.</p>
<p>Eg, if you have a box with a million triangles inside and the ray doesn't intersect the box you know it won't intersect any of the triangles either using only one test.</p>
<p>If you want to intersect something which isn't a triangle, for example a curve (for hair) or a sphere, you can write your own non-hardware accelerated program which will still benifit from traversing the BVH but will call your intersection program to test individual primitives.</p>

CC BY-SA 4.0
2021-12-07T17:41:15.667Z
2021-12-07T18:05:35.870Z
2021-12-07T18:05:35.870Z
Peter
<p>I've stumbled into Optix samples that define their own intersection programs to define how primitives intersect (or don't) with a ray, and others (mostly those only dealing with triangle meshes) <a href="https://gitlab.com/ingowald/optix7course/-/blob/iw/offline/example04_firstTriangleMesh/devicePrograms.cu" rel="nofollow noreferrer">that don't</a>.</p>
<p>Maybe I haven't really figured out exactly <em>what</em> is hardware accelerated when we write programs using Optix, but I would've guessed that checking the intersection is the costly (and thus hardware accelerated) part. So why are we allowed to write our own software intersection programs? Maybe I'm not really understanding how the hardware acceleration of raytracing works?</p>

<raytracing><gpu>
Are intersections still hardware accelerated if we define a custom intersection program in Optix?
Ilya
# Are intersections still hardware accelerated if we define a custom intersection program in Optix?

(Asked by: username_0 on 2021-12-07)

I've stumbled into Optix samples that define their own intersection programs to define how primitives intersect (or don't) with a ray, and others (mostly those only dealing with triangle meshes) [that don't](https://gitlab.com/ingowald/optix7course/-/blob/iw/offline/example04_firstTriangleMesh/devicePrograms.cu).

Maybe I haven't really figured out exactly *what* is hardware accelerated when we write programs using Optix, but I would've guessed that checking the intersection is the costly (and thus hardware accelerated) part. So why are we allowed to write our own software intersection programs? Maybe I'm not really understanding how the hardware acceleration of raytracing works?

**Tags:** raytracing, gpu


---

## 1 answers

### Answer by username_1 on 2021-12-07. Score: 3 | Accepted answer

Raytracing cores can generally do two hardware accelerated things:

1. Test an intersection between a triangle and a ray.
2. Traverse a BVH (Basically to test an intersection between bounding boxes and a ray).

When things are raytraced we don't typically loop through every triangle and test each one. Instead the triangles are placed into a BVH (<https://en.wikipedia.org/wiki/Bounding_volume_hierarchy>) which is a set of boxes which partition the triangles. We first test the ray against this BVH as it allows us to quickly ignore large sets triangles.

Eg, if you have a box with a million triangles inside and the ray doesn't intersect the box you know it won't intersect any of the triangles either using only one test.

If you want to intersect something which isn't a triangle, for example a curve (for hair) or a sphere, you can write your own non-hardware accelerated program which will still benifit from traversing the BVH but will call your intersection program to test individual primitives.


---

