NVIDIA OptiX 5.0
Programming Guide
14 December 2017
Version 5.0
Copyright Information
© 2017 NVIDIA Corporation. All rights reserved.
This document is protected under copyright law. The contents of this document may not be
translated, copied or duplicated in any form, in whole or in part, without the express written
permission of NVIDIA Corporation.
The information contained in this document is subject to change without notice. NVIDIA
Corporation and its employees shall not be responsible for incidental or consequential
damages resulting from the use of this material or liable for technical or editorial omissions
made herein.
NVIDIA, the NVIDIA logo, and OptiX are trademarks and/or registered trademarks of
NVIDIA Corporation. Other product names mentioned in this document may be trademarks
or registered trademarks of their respective companies and are hereby acknowledged.
Document build number 300255
ii NVIDIA OptiX 5.0 — Programming Guide © 2017 NVIDIA Corporation
Contents
1 OptiX overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Programming model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3 Ray tracing basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 Programming model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.1 Object model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.4 Execution model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3 Host API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.1 Context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.1.1 Entry points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.1.2 Ray types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.1.3 Global state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.2 Buffers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.2.1 Buffers of buffer ids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.3 Textures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.4 Graph nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.4.1 Geometry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.4.2 Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.4.3 GeometryInstance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.4.4 GeometryGroup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.4.5 Group . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.4.6 Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.4.7 Selector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.5 Acceleration structures for ray tracing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.5.1 Acceleration objects in the node graph . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.5.2 Acceleration structure builders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.5.3 Acceleration structure properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.5.4 Acceleration structure builds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.5.5 Shared acceleration structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.6 Rendering on the VCA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
3.6.1 Remote launches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3.6.2 Parallelization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3.6.3 Remote devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3.6.4 Progressive launches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3.6.5 Stream buffers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.6.6 Device code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
3.6.7 Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
3.6.8 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
© 2017 NVIDIA Corporation NVIDIA OptiX 5.0 — Programming Guide iii
4 Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.1 OptiX program objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.1.1 Managing program objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.1.2 Communication through variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
4.1.3 Internally provided semantics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
4.1.4 Attribute variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
4.1.5 Program variable scoping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
4.1.6 Program variable transformation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
4.2 The program scope of API function calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
4.3 Ray generation programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
4.3.1 Entry point indices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
4.3.2 Launching a ray generation program . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
4.3.3 Ray generation program function signature . . . . . . . . . . . . . . . . . . . . . . . 43
4.3.4 Example ray generation program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.4 Exception programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.4.1 Exception program entry point association . . . . . . . . . . . . . . . . . . . . . . . 45
4.4.2 Exception types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
4.4.3 Exception program function signature . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
4.4.4 Example exception program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
4.5 Closest hit programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
4.5.1 Closest hit program material association . . . . . . . . . . . . . . . . . . . . . . . . . 47
4.5.2 Closest hit program function signature . . . . . . . . . . . . . . . . . . . . . . . . . . 47
4.5.3 Recursion in a closest hit program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
4.5.4 Example closest hit program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
4.6 Any hit programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
4.6.1 Any hit program material association . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
4.6.2 Termination in an any hit program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
4.6.3 Any hit program function signature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
4.6.4 Example any hit program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
4.7 Miss programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
4.7.1 Miss program function signature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
4.7.2 Example miss program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
4.8 Intersection and bounding box programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
4.8.1 Intersection and bounding box program function signatures . . . . . . . . . 50
4.8.2 Reporting intersections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
4.8.3 Specifying bounding boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
4.8.4 Example intersection and bounding box programs . . . . . . . . . . . . . . . . . 51
4.9 Selector programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
4.9.1 Selector visit program function signature . . . . . . . . . . . . . . . . . . . . . . . . . 52
4.9.2 Example visit program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
4.10 Callable programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
4.10.1 Defining a callable program in CUDA . . . . . . . . . . . . . . . . . . . . . . . . . . 53
4.10.2 Using a callable program variable in CUDA . . . . . . . . . . . . . . . . . . . . . . 54
4.10.3 Setting a callable program on the host . . . . . . . . . . . . . . . . . . . . . . . . . . 55
iv NVIDIA OptiX 5.0 — Programming Guide © 2017 NVIDIA Corporation
4.10.4 Bound versus bindless callable programs . . . . . . . . . . . . . . . . . . . . . . . . 57
5 Motion blur . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
5.1 Motion in Geometry nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
5.1.1 Defining motion range for Geometry nodes . . . . . . . . . . . . . . . . . . . . . . . 60
5.1.2 Bounding boxes for motion blur . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5.1.3 Border modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
5.1.4 Acquiring motion parameter values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
5.2 Motion in Acceleration nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
5.3 Motion in Transform nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
5.3.1 Key types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
5.3.1.1 Key type RT_MOTIONKEYTYPE_MATRIX_FLOAT12 . . . . . . . . . . 62
5.3.1.2 Key type RT_MOTIONKEYTYPE_SRT_FLOAT16 . . . . . . . . . . . . . . 62
5.3.2 Border modes for Transform nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
5.3.3 Acquiring motion parameter values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
5.4 Examples of motion transforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
5.5 Motion in user programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
6 Post-processing framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
6.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
6.2 Post-processing stage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
6.2.1 Creating a post-processing stage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
6.2.2 Querying variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
6.2.2.1 Declaring a named variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
6.2.2.2 Getting a named variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
6.2.2.3 Iterating over existing variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
6.3 Command List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
6.3.1 Creating a command list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
6.3.2 Adding a post-processing stage to a command list . . . . . . . . . . . . . . . . . 69
6.3.3 Appending a launch to a command list . . . . . . . . . . . . . . . . . . . . . . . . . . 69
6.3.4 Finalizing a command list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
6.3.5 Running a command list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
6.4 Built-In Post-Processing Stages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
6.4.1 Deep-learning based Denoiser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
6.4.1.1 Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
6.4.1.2 Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
6.4.2 Simple Tone Mapper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
7 Building with OptiX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
7.1 Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
7.2 Header files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
7.3 PTX generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
7.4 SDK build . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
8 Interoperability with OpenGL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
8.1 Opengl interop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
8.1.1 Buffer objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
8.1.2 Textures and render buffers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
© 2017 NVIDIA Corporation NVIDIA OptiX 5.0 — Programming Guide v