building ray tracing applications with optix™...pixar research interactive lighting nvidia visual...

46
SIGGRAPH 2013 Shaping the Future of Visual Computing Building Ray Tracing Applications with OptiX™ David McAllister, Ph.D., OptiX R&D Manager Brandon Lloyd, Ph.D., OptiX Software Engineer

Upload: others

Post on 29-Jul-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

SIGGRAPH 2013 Shaping the Future of Visual Computing

Building Ray Tracing Applications with OptiX™ David McAllister, Ph.D., OptiX R&D Manager

Brandon Lloyd, Ph.D., OptiX Software Engineer

Page 2: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Why ray tracing? Ray tracing unifies rendering of visual phenomena

fewer algorithms with fewer interactions between algorithms

Easier to combine advanced visual effects robustly

soft shadows

indirect illumination

transparency

reflective & glossy surfaces

subsurface scattering

depth of field

Page 3: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Recursive Ray Tracing

Whitted-style recursive

Reflection and refraction per hit

Beer’s Law attenuation

Depth cut-off

Importance cut-off

Page 4: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Ray Tracing Algorithms

Computational Power

Interactive

Real-time

Batch

today

Page 5: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Real Time Path Tracing

What would it take?

4 rays / sample

50 samples / pixel

2M pixels / frame

30 frames / second

= 12B rays / second

GeForce GTX 680: 350M rays / second

Need 35X speedup

1 shading sample

1 AA sample

9 shading samples

1 AA sample

18 shading samples

2 AA samples

72 shading samples

8 AA samples

144 shading samples

16 AA samples

36 shading samples

4 AA samples

Good enough

for games

Page 6: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

How to optimize ray tracing (or anything)

Better hardware (GPUs)

Better software (Algorithmic improvement)

Better middleware (Tune for the architecture)

Page 7: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

GPUs – the processor for ray tracing

Abundant parallelism, massive computational power

GPUs excel at shading

Opportunity for hybrid algorithms

Page 8: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Acceleration Structures

Page 9: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered
Page 10: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Callable

Program

OptiX Execution Model

rtContextLaunch Ray Generation

Program

Exception

Program

Selector Visit

Program

Miss

Program Node Graph

Traversal

Acceleration

Traversal

Launch

Traverse Shade

rtTrace

Closest Hit

Program

Any Hit

Program

Intersection

Program

Page 11: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

C Host API Sample

RTresult rtContextCreate (RTcontext* context);

RTresult rtContextDestroy (RTcontext context);

RTresult rtContextDeclareVariable (RTcontext context, const char* name, RTvariable* v);

RTresult rtContextSetRayGenerationProgram (RTcontext context, unsigned int entry_point_index, RTprogram program);

RTresult rtBufferCreate (RTcontext context, unsigned int bufferdesc, RTbuffer* buffer);

RTresult rtBufferSetFormat (RTbuffer buffer, RTformat format);

RTresult rtBufferMap (RTbuffer buffer, void** user_pointer);

RTresult rtBufferUnmap (RTbuffer buffer);

RTresult rtProgramCreateFromPTXString (RTcontext context, const char* ptx, const char* program_name, RTprogram* program);

RTresult rtProgramCreateFromPTXFile (RTcontext context, const char* filename, const char* program_name, RTprogram* program);

RTresult rtContextLaunch2D (RTcontext context, unsigned int entry_point_index, RTsize image_width, RTsize image_height);

Page 12: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

C++ Host API Sample

Context* context = Context::create();

context["max_depth"]->setInt( 5 );

context["scene_epsilon"]->setFloat( 1.e-4f );

// Ray gen program

Program ray_gen_program = context->createProgramFromPTXFile( “myprogram.ptx”,"pinhole_camera" );

context->setRayGenerationProgram( 0, ray_gen_program );

BasicLight lights[] = { ..... };

Buffer light_buffer = context->createBuffer(RT_BUFFER_INPUT);

light_buffer->setFormat(RT_FORMAT_USER);

light_buffer->setElementSize(sizeof(BasicLight));

light_buffer->setSize( sizeof(lights)/sizeof(lights[0]) );

memcpy(light_buffer->map(), lights, sizeof(lights));

light_buffer->unmap();

context["lights"]->set(light_buffer);

Page 13: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

OptiX 3.0.1

Bug fix release

Available this week

Page 14: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

OptiX Feature Sneak Peek

Next release coming in a few months

Page 15: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Compilation Optimization

rtContextCompile()

3-7X faster

Still, you should avoid recompiles if possible.

Page 16: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Updated Support

Visual Studio 2012 support

CUDA 5.5 support

Quadro K6000 support

Page 17: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Visual Studio OptiX Wizard

Page 18: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Acceleration Builder Options

Sbvh has world class ray tracing performance

Lbvh is extremely fast and works on very large datasets

Slow Build

Fast Render Fast Build

Slow Render

Sbvh Bvh MedianBvh Lbvh

Page 19: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Acceleration Builder Options

Slow

Render

Slow Build

Bvh

Fast Build

Fast

Render

Sbvh

MedianBvh

Lbvh

Page 20: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Fast BVH Builds

LBVH + refinement

A new approach introduced in OptiX 3.0

Very fast to build

Good for animation

Quality does not approach optimal

Page 21: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

TRBVH

LBVH + refinementnew + splits

New work by NVIDIA Research

VERY fast to build

40M tris / sec on a GeForce GTX Titan

World’s fastest high quality BVH builder

Quality averages 91% of SBVH

HPG 2013 paper: https://research.nvidia.com/publication/fast-

parallel-construction-high-quality-bounding-volume-hierarchies

Page 22: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Acceleration Builder Options

Slow

Render

Slow Build

Bvh

Fast Build

Fast

Render

Sbvh

MedianBvh

Lbvh

Trbvh

Page 23: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

OptiX Low-Level Library

Specialized for ray tracing (no shading)

Replaces rtuTraversal

Improved performance

Uses latest algorithms from NVIDIA Research

ray tracing kernels [Aila and Laine 2009; Aila et al. 2012]

Treelet Reordering BVH (TRBVH) [Karras 2013]

Can use CUDA buffers as input/output

Support for asynchronous computation

Distributed as DLL and static library

Designed with an eye towards future features

Page 24: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

API Overview

C API with C++ wrappers

API Objects

Context

Buffer Descriptor

Model

Query

Page 25: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Context

Context tracks other API objects and encapsulates the ray tracing

backend

Creating a context

OLLresult

ollContextCreate(OLLcontexttype type, OLLcontext* context)

Context types

OLL_CONTEXT_TYPE_CPU

OLL_CONTEXT_TYPE_CUDA

Default for CUDA backend uses all available GPUs

Selects “Master GPU” and makes it the current device

Master GPU builds acceleration structure

Page 26: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Context

Selecting devices:

ollContextSetCudaDeviceNumbers( OLLcontext context, int deviceCount, const int* deviceNumbers )

First device is used as the master GPU

Destroying the context

destroys objects created by the context

synchronizes the CPU and GPU

Page 27: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Buffer Descriptor

Buffers are allocated by the application

Buffer descriptors encapsulate

information about the buffers ollBufferDescCreate(

OLLcontext context,

OLLbufferformat format,

OLLbuffertype type,

void* buffer,

OLLbufferdesc* desc )

Specify region of buffer to use (in elements) ollBufferDescSetRange( OLLbufferdesc desc, int begin, int end )

Context

BufferDesc

Page 28: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Buffer Descriptor

Variable stride supported for vertex format

ollBufferDescSetStride

Allows for vertex attributes

Page 29: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Buffer Descriptor

Formats OLL_BUFFER_FORMAT_INDICES_INT3

OLL_BUFFER_FORMAT_VERTEX_FLOAT3,

OLL_BUFFER_FORMAT_RAY_ORIGIN_DIRECTION,

OLL_BUFFER_FORMAT_RAY_ORIGIN_TMIN_DIRECTION_TMAX,

OLL_BUFFER_FORMAT_HIT_T_TRIID_U_V

OLL_BUFFER_FORMAT_HIT_T_TRIID

Types OLL_BUFFER_TYPE_HOST

OLL_BUFFER_TYPE_CUDA_LINEAR

Page 30: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Model

A model is a set of triangles

combined with an acceleration

data structure ollModelCreate

ollModelSetTriangles

ollModelFinalize

Asynchronous finalize ollModelFinalizeWait

ollModelFinalizePoll

Context

Model BufferDesc

BufferDesc

indices

vertices

Page 31: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Query

Queries perform the ray

tracing on a model ollQueryCreate

ollQuerySetRays

ollQuerySetHits

ollQueryExecute

Query types OLL_QUERY_TYPE_ANY

OLL_QUERY_TYPE_CLOSEST

Asynchronous query ollQueryWait

ollQueryPoll

Context

Model BufferDesc

BufferDesc

indices

vertices

Query BufferDesc

BufferDesc

rays

hits

Page 32: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

0

20

40

60

80

100

120

140

160

180

200

Speedup v

s. S

BV

H i

n

rtuTra

vers

al

Build Performance

Page 33: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

0.0

0.5

1.0

1.5

2.0

2.5

3.0

Speedup v

s. S

BV

H i

n

rtuTra

vers

al

Ray Tracing Performance

Page 34: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

0.0

50.0

100.0

150.0

200.0

250.0

300.0

350.0

400.0

Mra

ys/

s Ray Tracing Performance

Page 35: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Future

Features we want to implement

Animation support (refit/refine)

Instancing

Large-model optimizations

Page 36: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Art And Animation Studio

Page 37: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Vertex Light Baking

Working with Bungie

But will be made available. Contact us if interested.

Kavan, Bargteil, Sloan, “Least Squares Vertex Baking”, EGSR 2011

“NVIDIA's Optix has been instrumental when baking Ambient

Obscurance (AO) over the extremely complex geometry in the

worlds of Destiny. The high performance and ability to quickly

explore various formulations of AO were invaluable.”

Page 38: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Vertex Light Baking

Working with Bungie

But will be made available. Contact us if interested.

Kavan, Bargteil, Sloan, “Least Squares Vertex Baking”, EGSR 2011

Compared to textures…

Less memory & bandwidth

No u,v parameterization

Good for low-frequency effects

Page 39: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Typical Scene

Linear interpolation

Static mesh

Coarse mesh

Page 40: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Piecewise Linear Approximation

Sample illumination on surface

Each sample is a hemisphere of rays

Reconstruct values at vertices

1

0 0

0

0 0

0 x

x x

x

x x

x

x x

x x

x

x

x

x

x

Page 41: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Weighted Averaging

Page 42: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Least Squares Vertex Baking

Page 43: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

Pixar Research & NVIDIA OptiX Interactive Lighting Collaboration

Page 44: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

NVIDIA Visual Computing

Theater in NVIDIA Booth

Tue. 4:00 – 4:30

Wed. 2:00 – 2:30

Thur. 10:40 – 11:10

Page 45: Building Ray Tracing Applications with OptiX™...Pixar Research Interactive Lighting NVIDIA Visual Computing Theater Tue. 4:00, Wed. 2:00, Thur. 10:40 Mental ray with OptiX-powered

See OptiX at Siggraph

Pixar Research Interactive Lighting NVIDIA Visual Computing Theater

Tue. 4:00, Wed. 2:00, Thur. 10:40

Mental ray with OptiX-powered Final Gather NVIDIA booth

Bunkspeed Shot / Move / Drive with IRay Bunkspeed booth, NVIDIA booth

NVIDIA Visual Computing Theater: Thur. 1:20

Course: “Physically Based Shading in Theory and Practice”

Thur. 9:00

10:00: “Crafting a Next-Gen Material Pipeline for The Order: 1886”