Ray Tracing Acceleration Steve Marschner CS4621 Cornell University - - PowerPoint PPT Presentation

ray tracing acceleration
SMART_READER_LITE
LIVE PREVIEW

Ray Tracing Acceleration Steve Marschner CS4621 Cornell University - - PowerPoint PPT Presentation

Ray Tracing Acceleration Steve Marschner CS4621 Cornell University Cornell CS4620 Fall 2020 Steve Marschner 1 Ray tracing acceleration Ray tracing is slow. This is bad! Ray tracers spend most of their time in ray-surface


slide-1
SLIDE 1

Steve Marschner CS4621 Cornell University

Steve Marschner • Cornell CS4620 Fall 2020

Ray Tracing Acceleration

1

slide-2
SLIDE 2
  • Ray tracing is slow. This is bad!

– Ray tracers spend most of their time in ray-surface intersection methods

  • Ways to improve speed

– Make intersection methods more efficient

  • Yes, good idea. But only gets you so far

– Call intersection methods fewer times

  • Intersecting every ray with every object is wasteful
  • Basic strategy: efficiently find big chunks of geometry that

definitely do not intersect a ray

Steve Marschner • Cornell CS4620 Fall 2020

Ray tracing acceleration

2

slide-3
SLIDE 3
  • Quick way to avoid intersections: bound object with a

simple volume

– Object is fully contained in the volume – If it doesn’t hit the volume, it doesn’t hit the object – So test bvol first, then test object if it hits

[Glassner 89, Fig 4.5] Steve Marschner • Cornell CS4620 Fall 2020

Bounding volumes

3

slide-4
SLIDE 4
  • Cost: more for hits and near misses, less for far misses
  • Worth doing? It depends:

– Cost of bvol intersection test should be small

  • Therefore use simple shapes (spheres, boxes, …)

– Cost of object intersect test should be large

  • Bvols most useful for complex objects

– Tightness of fit should be good

  • Loose fit leads to extra object intersections
  • Tradeoff between tightness and bvol intersection cost

Steve Marschner • Cornell CS4620 Fall 2020

Bounding volumes

4

slide-5
SLIDE 5
  • Bvols around objects may help
  • Bvols around groups of objects will help
  • Bvols around parts of complex objects will help
  • Leads to the idea of using bounding volumes all the way

from the whole scene down to groups of a few objects

Steve Marschner • Cornell CS4620 Fall 2020

If it’s worth doing, it’s worth doing hierarchically!

5

slide-6
SLIDE 6
  • A bounding volume hierarchy is a tree of boxes

– each bounding box contains all children – ray misses parent implies ray misses all children

  • Leaf nodes contain surfaces

– again the bounding box contains all geometry in that node – if ray hits leaf node box, then we finally test the surfaces

  • Replace the intersection loop over all objects in the

scene with a partial tree traversal

– test node first; test all children only ray hits parent

  • Usually we use binary trees (each non-leaf box has

exactly two contained boxes)

Steve Marschner • Cornell CS4620 Fall 2020

Implementing a bvol hierarchy

6

slide-7
SLIDE 7

Steve Marschner • Cornell CS4620 Fall 2020

BVH construction example

7

slide-8
SLIDE 8

Steve Marschner • Cornell CS4620 Fall 2020

BVH construction example

7

slide-9
SLIDE 9

Steve Marschner • Cornell CS4620 Fall 2020

BVH construction example

7

slide-10
SLIDE 10

Steve Marschner • Cornell CS4620 Fall 2020

BVH construction example

7

slide-11
SLIDE 11

Steve Marschner • Cornell CS4620 Fall 2020

BVH ray-tracing example

8

slide-12
SLIDE 12

Steve Marschner • Cornell CS4620 Fall 2020

BVH ray-tracing example

8

slide-13
SLIDE 13

Steve Marschner • Cornell CS4620 Fall 2020

BVH ray-tracing example

8

slide-14
SLIDE 14

Steve Marschner • Cornell CS4620 Fall 2020

BVH ray-tracing example

8

slide-15
SLIDE 15

Steve Marschner • Cornell CS4620 Fall 2020

BVH ray-tracing example

8

slide-16
SLIDE 16

Steve Marschner • Cornell CS4620 Fall 2020

BVH ray-tracing example

8

slide-17
SLIDE 17

Steve Marschner • Cornell CS4620 Fall 2020

BVH ray-tracing example

8

slide-18
SLIDE 18

Steve Marschner • Cornell CS4620 Fall 2020

BVH ray-tracing example

8

slide-19
SLIDE 19

Steve Marschner • Cornell CS4620 Fall 2020

BVH ray-tracing example

8

slide-20
SLIDE 20

Steve Marschner • Cornell CS4620 Fall 2020

BVH ray-tracing example

8

slide-21
SLIDE 21
  • Spheres -- easy to intersect, not always so tight
  • Axis-aligned bounding boxes (AABBs) -- easy to

intersect, often tighter (esp. for axis-aligned models)

  • Oriented bounding boxes (OBBs) -- easy to intersect

(but cost of transformation), tighter for arbitrary

  • bjects
  • Computing the bvols

– For primitives -- generally pretty easy – For groups -- not so easy for OBBs (to do well) – For transformed surfaces -- not so easy for spheres

Steve Marschner • Cornell CS4620 Fall 2020

Choice of bounding volumes

9

slide-22
SLIDE 22
  • Probably easiest to implement
  • Computing for (axis-aligned) primitives

– Cube: duh! – Sphere, cylinder, etc.: pretty obvious – Triangles: compute min/max of vertex coordinates – Groups or meshes: min/max of component parts

  • How to intersect them

– Treat them as an intersection of slabs (see also textbook)

Steve Marschner • Cornell CS4620 Fall 2020

Axis aligned bounding boxes

10

slide-23
SLIDE 23
  • Could intersect with 6 faces individually
  • Better way: box is the intersection of 3 slabs

Steve Marschner • Cornell CS4620 Fall 2020

Ray-box intersection

11

slide-24
SLIDE 24
  • Could intersect with 6 faces individually
  • Better way: box is the intersection of 3 slabs

Steve Marschner • Cornell CS4620 Fall 2020

Ray-box intersection

11

slide-25
SLIDE 25
  • Could intersect with 6 faces individually
  • Better way: box is the intersection of 3 slabs

Steve Marschner • Cornell CS4620 Fall 2020

Ray-box intersection

11

slide-26
SLIDE 26
  • Could intersect with 6 faces individually
  • Better way: box is the intersection of 3 slabs

Steve Marschner • Cornell CS4620 Fall 2020

Ray-box intersection

11

slide-27
SLIDE 27
  • 2D example
  • 3D is the same!

Steve Marschner • Cornell CS4620 Fall 2020

Ray-slab intersection

12

(xmin, ymin) (xmax, ymax)

slide-28
SLIDE 28
  • 2D example
  • 3D is the same!

Steve Marschner • Cornell CS4620 Fall 2020

Ray-slab intersection

12

xmin xmax ymax ymin

slide-29
SLIDE 29
  • 2D example
  • 3D is the same!

Steve Marschner • Cornell CS4620 Fall 2020

Ray-slab intersection

12

xmin xmax txmin txmax (px, py) (dx, dy)

slide-30
SLIDE 30
  • 2D example
  • 3D is the same!

Steve Marschner • Cornell CS4620 Fall 2020

Ray-slab intersection

12

xmin xmax ymax ymin txmin txmax (px, py) (dx, dy) tymin tymax

slide-31
SLIDE 31
  • Each intersection is an interval
  • Want last entry point and

first exit point

Steve Marschner • Cornell CS4620 Fall 2020

Intersecting intersections

13

xmin xmax txenter txexit

slide-32
SLIDE 32

txenter = min(txmin, txmax) txexit = max(txmin, txmax)

  • Each intersection is an interval
  • Want last entry point and

first exit point

Steve Marschner • Cornell CS4620 Fall 2020

Intersecting intersections

13

xmin xmax txenter txexit

slide-33
SLIDE 33

txenter = min(txmin, txmax) txexit = max(txmin, txmax)

  • Each intersection is an interval
  • Want last entry point and

first exit point

Steve Marschner • Cornell CS4620 Fall 2020

Intersecting intersections

13

ymax ymin tyexit tyenter

slide-34
SLIDE 34

txenter = min(txmin, txmax) txexit = max(txmin, txmax) tyenter = min(tymin, tymax) tyexit = max(tymin, tymax)

  • Each intersection is an interval
  • Want last entry point and

first exit point

Steve Marschner • Cornell CS4620 Fall 2020

Intersecting intersections

13

ymax ymin tyexit tyenter

slide-35
SLIDE 35

txenter = min(txmin, txmax) txexit = max(txmin, txmax) tyenter = min(tymin, tymax) tyexit = max(tymin, tymax)

  • Each intersection is an interval
  • Want last entry point and

first exit point

Steve Marschner • Cornell CS4620 Fall 2020

Intersecting intersections

13

xmin xmax ymax ymin txenter txexit tyexit tyenter

slide-36
SLIDE 36

txenter = min(txmin, txmax) txexit = max(txmin, txmax) tyenter = min(tymin, tymax) tyexit = max(tymin, tymax)

  • Each intersection is an interval
  • Want last entry point and

first exit point

Steve Marschner • Cornell CS4620 Fall 2020

Intersecting intersections

13

xmin xmax ymax ymin txenter txexit tyexit tyenter

tenter = max(txenter, tyenter) texit = min(txexit, tyexit)

slide-37
SLIDE 37
  • Input: list of triangles
  • Output: tree
  • Strategy:

– make bbox for the whole list – if list is is too long:

  • split list into 2 parts
  • recursively build subtree for each part
  • return an internal node with those 2 children

– if list is short enough:

  • return a leaf node with all the triangles in it

Steve Marschner • Cornell CS4620 Fall 2020

Building a hierarchy

14

slide-38
SLIDE 38
  • How to partition?

– Ideal: clusters – Practical: partition along the longest axis

  • Center partition

– less expensive, simpler – unbalanced tree (but may sometimes be better)

  • Median partition

– more expensive – more balanced tree

  • Surface area heuristic

– models expected cost of ray intersection – generally produces best-performing trees

Steve Marschner • Cornell CS4620 Fall 2020

Building the hierarchy

15

slide-39
SLIDE 39
  • Input: ray and tree (could be subtree)
  • Output: smallest , corresponding hit data
  • Strategy:

– Ray hits this tree’s bbox? No miss – For leaf node: intersect all triangles, return first hit – For internal node: intersect both children, return first hit

t

Steve Marschner • Cornell CS4620 Fall 2020

Using the hierarchy

16

slide-40
SLIDE 40
  • An entirely different approach: uniform grid of cells

Steve Marschner • Cornell CS4620 Fall 2020

Regular space subdivision

17

slide-41
SLIDE 41
  • Grid divides space, not objects

Steve Marschner • Cornell CS4620 Fall 2020

Regular grid example

18

slide-42
SLIDE 42

Steve Marschner • Cornell CS4620 Fall 2020

Traversing a regular grid

19

slide-43
SLIDE 43
  • k-d Tree

– subdivides space, like grid – adaptive, like BVH

Steve Marschner • Cornell CS4620 Fall 2020

Non-regular space subdivision

20

slide-44
SLIDE 44
  • k-d Tree

– subdivides space, like grid – adaptive, like BVH

Steve Marschner • Cornell CS4620 Fall 2020

Non-regular space subdivision

20

slide-45
SLIDE 45
  • k-d Tree

– subdivides space, like grid – adaptive, like BVH

Steve Marschner • Cornell CS4620 Fall 2020

Non-regular space subdivision

20

slide-46
SLIDE 46
  • Conceptually, structure traversal replaces main ray

intersection loop

– could literally replace code in Scene

  • Better engineering decision to separate the

acceleration structure

– plug and play different acceleration structures – keep representation of scene itself simple

  • Acceleration engine has two fundamental methods:

– build from list of surfaces – intersect with ray

Steve Marschner • Cornell CS4620 Fall 2020

Implementing acceleration structures

21

slide-47
SLIDE 47
  • High RT performance is a major engineering task

– becoming more common to rely on external libraries – Intel Embree: CPU library optimized for Intel processors – Nvidia RTX: hardware accelerated ray tracing for latest generation GPUs

  • Fastest current systems:

– CPU: tens to hundreds of megarays / sec – GPU: a few gigarays / sec – 1 gigaray / 60 frames / 1M pixels ≈ 16 rays/pixel/frame – not a ton of rays but with judicious use many nice reflection/ shadow effects can be rendered in real time

Steve Marschner • Cornell CS4620 Fall 2020

Ray tracing acceleration in practice

22

slide-48
SLIDE 48

Steve Marschner • Cornell CS4620 Fall 2020 23

slide-49
SLIDE 49

Steve Marschner • Cornell CS4620 Fall 2020 24

Minecraft RTX tech demo

slide-50
SLIDE 50

Steve Marschner • Cornell CS4620 Fall 2020 24

Minecraft RTX tech demo