Launch
Traverse Shade
Ray Generation
Program
Miss
Program
Closest Hit
Program
Selector Visit
Program
Intersection
Program
Any Hit
Program
Acceleration
Traversal
Node Graph
Traversal
rtContextLaunch
rtTrace
Exception
Program
Figure 2: A call graph showing the control flow through the ray
tracing pipeline. The yellow boxes represent user-specified pro-
grams and the blue boxes are algorithms internal to OptiX. Execu-
tion is initiated by the API call rtContextLaunch. A built-in func-
tion, rtTrace, can be employed by the ray generation program to
cast rays into the scene. This function may also be called recur-
sively by the closest hit program for shadow and secondary rays.
The exception program is executed when the execution of a partic-
ular ray is terminated by an error such as excessive memory con-
sumption.
variety of mesh representations. A programmable intersection op-
eration facilitates direct access to the native format, which can help
avoid copies when interoperating with rasterization-based systems.
Bounding box programs compute the bounds associated with each
primitive to enable acceleration structures over arbitrary geometry.
Given a primitive index, a simple program of this type may, for
example, read vertex data from a buffer and compute a triangle’s
bounding box. Procedural geometry can sometimes only estimate
the bounds of a primitive. Such estimates are allowed as long as
they are conservative, but loose bounds may degrade performance.
Closest hit programs are invoked once traversal has found the clos-
est intersection of a ray with the scene geometry. This program
type closely resembles surface shaders in classical rendering sys-
tems. Typically, a closest hit program will perform computations
like shading, potentially casting new rays in the process, and store
result data in the ray payload.
Any hit programs are called during traversal for every ray-object
intersection that is found. The any hit program allows the ma-
terial to participate in object intersection decisions while keep-
ing the shading operations separate from the geometry opera-
tions. It may optionally terminate the ray using the built-in func-
tion rtTerminateRay, which will stop all traversal and unwind the
call stack to the most recent invocation of rtTrace. This is a
lightweight exception mechanism that can be used to implement
early ray termination for shadow rays and ambient occlusion. Al-
ternatively, the any hit program may ignore the intersection us-
ing rtIgnoreIntersection, allowing traversal to continue looking for
other geometric objects. An intersection may be ignored, for in-
stance, based on a texture channel lookup, thus implementing effi-
cient alpha-mapped transparency without restarting traversal. An-
RT_PROGRAM void pinhole_camera() {
Ray ray = PinholeCamera::makeRay( launchIndex );
UserPayload payload;
rtTrace( topObject, ray, payload );
outputBuffer[launchIndex] = payload.result;
}
Figure 3: Example ray generation program (in CUDA C) for a
single sample per pixel. The 2-dimensional grid location of the
program invocation is given by the semantic variable launchIn-
dex, which is used to create a primary ray using a pinhole camera
model. Upon tracing a ray, the invoked material hit programs fill
the result field of the user-defined payload structure. The variable
topObject refers to the location in the scene hierarchy where ray
traversal should start, typically the root of the node graph. At the
location specified by launchIndex, the result is written to the output
buffer to be displayed by the application.
other use case for the any hit program can be found in Section 8.1,
where the application performs visibility attenuation for partial
shadows cast by glass objects. Note that intersections may be pre-
sented out of order. The default any hit program is a no-op, which
is often the desired operation.
Miss programs are executed when the ray does not intersect any
geometry in the interval provided. They can be used to implement
a background color or environment map lookup.
Exception programs are executed when the system encounters an
exceptional condition, e.g., when the recursion stack exceeds the
amount of memory available for each thread, or when a buffer ac-
cess index is out of range. OptiX also supports user-defined excep-
tions that can be thrown from any program. The exception program
can react, for example, by printing diagnostic messages or visualiz-
ing the condition by writing special color values to an output pixel
buffer.
Selector visit programs expose programmability for coarse-level
node graph traversal. For example, an application may choose to
vary the level of geometric detail for parts of the scene on a per-
ray basis. In this case, the visit program would examine the ray
distance or a ray differential stored with the payload and make a
traversal decision based on that data.
3.2 Scene representation
The OptiX engine employs a flexible structure for representing
scene information and associated programmable operations, col-
lected in a container object called the context. This representa-
tion is also the mechanism for binding programmable shaders to
the object-specific data that they require. In conjunction with a
special-purpose object model described in Section 3.3, a compact
representation of scene data is achieved.
3.2.1 Hierarchy nodes
A scene is represented as a graph. This representation is very
lightweight and controls the traversal of rays through the scene. It
can also be used to implement instancing two-level hierarchies for
animations of rigid objects, or other common scene structures. To
support instancing and sharing of common data, the nodes can have
multiple parents.
Four main node types can be used to provide the scene representa-
tion using a directed graph. Any node can be used as the root of
scene traversal. This allows, for example, different representations
to be used for different ray types.