39
David Luebke 05/13/22 Advanced Computer Advanced Computer Graphics Graphics Lecture 4: Faster Ray Lecture 4: Faster Ray Tracing Tracing David Luebke David Luebke [email protected] [email protected] http://www.cs.virginia.edu/ http://www.cs.virginia.edu/ ~cs551dl ~cs551dl

Advanced Computer Graphics Lecture 4: Faster Ray Tracing

  • Upload
    khoi

  • View
    31

  • Download
    0

Embed Size (px)

DESCRIPTION

Advanced Computer Graphics Lecture 4: Faster Ray Tracing. David Luebke [email protected] http://www.cs.virginia.edu/~cs551dl. Administrivia. Read Chapter 9 Verify collection of Exercise 1. Recap. Ray tracing is too slow Chapter 9: Different methods to speed it up - PowerPoint PPT Presentation

Citation preview

Page 1: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

Advanced Computer GraphicsAdvanced Computer GraphicsLecture 4: Faster Ray TracingLecture 4: Faster Ray Tracing

David LuebkeDavid Luebke

[email protected]@cs.virginia.edu

http://www.cs.virginia.edu/~cs551dlhttp://www.cs.virginia.edu/~cs551dl

Page 2: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

AdministriviaAdministrivia

Read Chapter 9Read Chapter 9 Verify collection of Exercise 1Verify collection of Exercise 1

Page 3: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

RecapRecap

Ray tracing is too slowRay tracing is too slow Chapter 9:Chapter 9:

– Different methods to speed it upDifferent methods to speed it up– Ways of using ray tracing Ways of using ray tracing selectivelyselectively

Page 4: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

RecapRecap

Speedup TechniquesSpeedup Techniques– Intersect rays fasterIntersect rays faster– Shoot fewer raysShoot fewer rays– Shoot “smarter” raysShoot “smarter” rays

Page 5: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

RecapRecap

Intersect Rays FasterIntersect Rays Faster– Bounding volumesBounding volumes– Spatial partitionsSpatial partitions– Reordering ray intersection testsReordering ray intersection tests– Optimizing intersection testsOptimizing intersection tests

Page 6: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

RecapRecap

Bounding volumesBounding volumes– Idea: before intersecting a ray with a Idea: before intersecting a ray with a

collection of objects, test it against one collection of objects, test it against one simple object that bounds the collectionsimple object that bounds the collection

0

1

2

3

4

56

78

90

1

2

3

4

56

78

9

Page 7: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

RecapRecap

Hierarchical bounding volumesHierarchical bounding volumes– Group nearby volumes hierarchicallyGroup nearby volumes hierarchically– Test rays against hierarchy top-downTest rays against hierarchy top-down

Page 8: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

Bounding VolumesBounding Volumes

Some different bounding volumes:Some different bounding volumes:– SpheresSpheres– Axis-aligned bounding boxes (AABBs)Axis-aligned bounding boxes (AABBs)– Oriented bounding boxes (OBBs)Oriented bounding boxes (OBBs)– SlabsSlabs

Show examplesShow examples

Page 9: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

Bounding VolumesBounding Volumes

What makes a “good” bounding What makes a “good” bounding volume?volume?– Tightness of fit (Tightness of fit (expressed how?expressed how?))– Simplicity of intersection Simplicity of intersection

Total costTotal cost = b*B + i*I = b*B + i*I bb: # times volume tested for intersection: # times volume tested for intersection BB: cost of ray-volume intersection test: cost of ray-volume intersection test ii: # times item is tested for intersection: # times item is tested for intersection II: cost of ray-item intersection test: cost of ray-item intersection test

Page 10: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

Bounding VolumesBounding Volumes

SpheresSpheres– Cheap intersection testCheap intersection test– Poor fit Poor fit – A pain to fit to dataA pain to fit to data

Page 11: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

Bounding VolumesBounding Volumes

Axis-aligned bounding boxes Axis-aligned bounding boxes (AABBs)(AABBs)– Relatively cheap intersection testRelatively cheap intersection test– Usually better fitUsually better fit– Trivial to fit to dataTrivial to fit to data

Page 12: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

Bounding VolumesBounding Volumes

Oriented bounding boxes (OBBs)Oriented bounding boxes (OBBs)– Medium-expensive intersection testMedium-expensive intersection test– Very good fit (asymptotically better)Very good fit (asymptotically better)– Medium-difficult to fit to dataMedium-difficult to fit to data

Page 13: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

Intermission:Intermission:Parallel Close ProximityParallel Close Proximity

We will analyze how OBBs, AABBs, and spheres should perform in parallel close proximity situations.

•Define parallel close proximity•Convergence rates of BV types•Asymptotic performance•Experimental evidence (graph)

(The following 11 slides are courtesy Stefan Gottschalk, UNC)

Page 14: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

Parallel Close ProximityParallel Close Proximity

Q: How does the number of BV tests increase as the gap size decreases?

Two models are in parallel close proximity when every point on each model is a given fixed distance () from the other model.

Page 15: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

Parallel Close Proximity:Parallel Close Proximity:ConvergenceConvergence

1

Page 16: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

12/2 1

4/

Parallel Close Proximity:Parallel Close Proximity:ConvergenceConvergence

Page 17: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

1

Parallel Close Proximity:Parallel Close Proximity:ConvergenceConvergence

Page 18: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

12/2

14/

Parallel Close Proximity:Parallel Close Proximity:ConvergenceConvergence

Page 19: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

1

Parallel Close Proximity:Parallel Close Proximity:ConvergenceConvergence

Page 20: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

14/

116/

Parallel Close Proximity:Parallel Close Proximity:ConvergenceConvergence

Page 21: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

14/

14/

14/

Parallel Close Proximity:Parallel Close Proximity:ConvergenceConvergence

Page 22: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

OBBsOBBs

k

O(n)

Spheres & AABBsSpheres & AABBs

2k

O(n )2

Parallel Close Proximity:Parallel Close Proximity:Asymptotic PerformanceAsymptotic Performance

Page 23: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

OBBs asymptotically outperform AABBs and spheresOBBs asymptotically outperform AABBs and spheres

Log-log plot

10-4 10-3 10-2 10-1 100 1012 3 4 5 6 7 2 3 4 5 6 7 2 3 4 5 6 7 2 3 4 5 6 7 2 3 4 5 6 7

101

102

103

104

105

106

2346

235

2346

235

235

23

Gap Size ()

Num

ber

of B

V te

sts

Parallel Close Proximity: Parallel Close Proximity: ExperimentExperiment

Page 24: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

Bounding VolumesBounding Volumes

Slabs (parallel planes)Slabs (parallel planes)– Comparatively expensiveComparatively expensive– Very good fitVery good fit– A pain to fit to dataA pain to fit to data

Page 25: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

Bounding Volume Bounding Volume HierarchiesHierarchies

What makes a “good” bounding volume What makes a “good” bounding volume hierarchy?hierarchy?– Grouped objects (or volumes) should be Grouped objects (or volumes) should be

near each othernear each other– Volume should be minimalVolume should be minimal– Sum of all volumes should be minimalSum of all volumes should be minimal– Top of the tree is most criticalTop of the tree is most critical– Constructing the hierarchy should pay for Constructing the hierarchy should pay for

itself!itself!

Page 26: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

Spatial PartitioningSpatial Partitioning

Hierarchical bounding volumesHierarchical bounding volumes surround surround objects in the scene with (possibly objects in the scene with (possibly overlapping) volumesoverlapping) volumes– Often tightest fitOften tightest fit

SpatialSpatial partitioningpartitioning techniques classify all techniques classify all space into non-overlapping portionsspace into non-overlapping portions– Easier to generate automaticallyEasier to generate automatically– Can “walk” ray from partition to partitionCan “walk” ray from partition to partition

Page 27: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

Spatial PartitioningSpatial Partitioning

Some spatial partitioning schemes:Some spatial partitioning schemes:– Uniform grid (2-D or 3-D)Uniform grid (2-D or 3-D)– OctreeOctree– k-D treek-D tree– BSP-treeBSP-tree

Show examplesShow examples

Page 28: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

Uniform GridUniform Grid

Uniform grid pros:Uniform grid pros:– Very simple and fast to generateVery simple and fast to generate– Very simple and fast to trace rays Very simple and fast to trace rays

across (across (How?How?) ) Uniform grid cons:Uniform grid cons:

– Not adaptiveNot adaptive Wastes storage on empty spaceWastes storage on empty space Assumes uniform spread of dataAssumes uniform spread of data

Page 29: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

OctreeOctree

Octree pros:Octree pros:– Simple to generateSimple to generate– AdaptiveAdaptive

Octree cons:Octree cons:– Less easy to trace rays across (Less easy to trace rays across (How?How?))– Adaptive only in scaleAdaptive only in scale

Page 30: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

k-D Treesk-D Trees

k-D tree pros:k-D tree pros:– Moderately simple to generateModerately simple to generate– More adaptive than octreesMore adaptive than octrees

k-D tree cons:k-D tree cons:– Less efficient to trace rays acrossLess efficient to trace rays across– Moderately complex data structureModerately complex data structure

Page 31: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

BSP TreesBSP Trees

BSP tree pros:BSP tree pros:– Extremely adaptiveExtremely adaptive– Simple & elegant data structureSimple & elegant data structure

BSP tree cons:BSP tree cons:– Very hard to create optimum BSPVery hard to create optimum BSP– Splitting planes can explode storageSplitting planes can explode storage– Simple but slow to trace rays acrossSimple but slow to trace rays across

Page 32: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

Ray Space SubdivisionRay Space Subdivision

Weird acceleration scheme award…Weird acceleration scheme award… Octree, BSP Tree, grids: 3-D Octree, BSP Tree, grids: 3-D

subdivision schemessubdivision schemes Arvo & Kirk: Arvo & Kirk: 5-D5-D subdivision scheme subdivision scheme

– Position: Position: x, y, zx, y, z– Direction: Direction: u, vu, v

Draw it…Draw it…

Page 33: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

Reordering RayReordering RayIntersection TestsIntersection Tests

Caching ray hitsCaching ray hits Memory-coherent ray tracingMemory-coherent ray tracing

Page 34: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

Caching Ray HitsCaching Ray Hits

Record what object the “last ray” hitRecord what object the “last ray” hit Start by checking that objectStart by checking that object Especially for shadow rays…(Especially for shadow rays…(why?why?)) RSRT uses a RSRT uses a multi-level shadow multi-level shadow

cachecache (what’s that?)(what’s that?)

Page 35: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

Memory-Coherent Memory-Coherent Ray TracingRay Tracing

Goal: ray trace very large scenesGoal: ray trace very large scenes Problem: ray tracing typically Problem: ray tracing typically

exhibits poor memory coherence exhibits poor memory coherence ((Why?Why?))

Solution: re-order ray computationsSolution: re-order ray computations– Ray trace where geometry in cacheRay trace where geometry in cache– Postpone rays going out-of-corePostpone rays going out-of-core

Page 36: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

Optimizing Ray Optimizing Ray Intersection TestsIntersection Tests

Fine-tune the math!Fine-tune the math!– Share subexpressionsShare subexpressions– Precompute everything possiblePrecompute everything possible

Code with careCode with care– Even use assembly, if necessaryEven use assembly, if necessary– Will get its own lectureWill get its own lecture

Page 37: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

Speedup TechniquesSpeedup Techniques

Speedup TechniquesSpeedup Techniques– Intersect rays fasterIntersect rays faster– Shoot fewer raysShoot fewer rays– Shoot “smarter” raysShoot “smarter” rays

Page 38: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

Shoot Fewer RaysShoot Fewer Rays

Adaptive depth controlAdaptive depth control– Naïve ray tracer: spawn 2 rays per Naïve ray tracer: spawn 2 rays per

intersection until max recursion limitintersection until max recursion limit– In practice, few surfaces are In practice, few surfaces are

transparent or reflectivetransparent or reflective Contribution of most rays to image: 0%Contribution of most rays to image: 0% Don’t shoot rays w/ contribution near 0%Don’t shoot rays w/ contribution near 0%

Page 39: Advanced Computer Graphics Lecture 4: Faster Ray Tracing

David Luebke 04/21/23

Shoot Fewer RaysShoot Fewer Rays

Adaptive samplingAdaptive sampling– Shoot rays coarsely, interpolating their Shoot rays coarsely, interpolating their

values across pixelsvalues across pixels– Where adjacent rays differ greatly in Where adjacent rays differ greatly in

value, sample more finelyvalue, sample more finely– Stop when some maximum resolution Stop when some maximum resolution

is reachedis reached Show exampleShow example