54
Introduction to Computer Graphics GAMES101, Lingqi Yan, UC Santa Barbara Ray Tracing 2 (Acceleration & Radiometry) Lecture 14: http://www.cs.ucsb.edu/~lingqi/teaching/games101.html

GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

Introduction to Computer GraphicsGAMES101, Lingqi Yan, UC Santa Barbara

Ray Tracing 2(Acceleration & Radiometry) 

Lecture 14:

http://www.cs.ucsb.edu/~lingqi/teaching/games101.html

Page 2: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Announcements

• Grading of resubmissions — we’re working on that

• GTC news: DLSS 2.0 - https://zhuanlan.zhihu.com/p/116211994

• GTC news: RTXGI - https://developer.nvidia.com/rtxgi

• Personal feeling - Offline rendering techniques will soon become real-time

- Current real-time rendering techniques will still be useful

• Next lectures won’t be easy

2

Page 3: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Last Lecture

• Why ray tracing?

• Whitted-style ray tracing

• Ray-object intersections

- Implicit surfaces

- Triangles

• Axis-Aligned Bounding Boxes (AABBs)

- Understanding — pairs of slabs

- Ray-AABB intersection

3

Page 4: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Today

• Using AABBs to accelerate ray tracing

- Uniform grids

- Spatial partitions

• Basic radiometry (辐射度量学)

4

Page 5: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

Uniform Spatial Partitions (Grids)

Page 6: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Preprocess – Build Acceleration Grid

6

1. Find bounding box

Page 7: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Preprocess – Build Acceleration Grid

7

1. Find bounding box

2. Create grid

Page 8: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Preprocess – Build Acceleration Grid

8

1. Find bounding box

2. Create grid

3. Store each object in overlapping cells

Page 9: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Ray-Scene Intersection

9

Step through grid in ray traversal order

For each grid cell Test intersection with all objects stored at that cell

Page 10: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Grid Resolution?

One cell

• No speedup

10

Page 11: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Grid Resolution?

Too many cells

• Inefficiency due to extraneous grid traversal

11

Page 12: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Grid Resolution?

Heuristic:

• #cells = C * #objs

• C ≈ 27 in 3D

12

Page 13: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Uniform Grids – When They Work Well

13

Deussen et al; Pharr & Humphreys, PBRT

Grids work well on large collections of objects that are distributed evenly in size and space

Page 14: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Jun Yan, Tracy Renderer

Uniform Grids – When They Fail

14

“Teapot in a stadium” problem

Page 15: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

Spatial Partitions

Page 16: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Spatial Partitioning Examples

16

BSP-TreeKD-Tree

Note: you could have these in both 2D and 3D. In lecture we will illustrate principles in 2D.

Oct-Tree

Page 17: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

KD-Tree Pre-Processing

17

A

A

Page 18: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

B

A

KD-Tree Pre-Processing

18

A

B

Page 19: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

4 5

D 3

2 C

KD-Tree Pre-Processing

19

A

BC

D

1

2

34

5

1 B

A

Note: also subdivide nodes 1 and 2, etc.

Page 20: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Data Structure for KD-Trees

Internal nodes store

• split axis: x-, y-, or z-axis

• split position: coordinate of split plane along axis

• children: pointers to child nodes

• No objects are stored in internal nodes Leaf nodes store

• list of objects

20

Page 21: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

4 5

D 3

2 C

Traversing a KD-Tree

21

A

BC

D

1 B

A

Page 22: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

4 5

D 3

2 C

Traversing a KD-Tree

22

A

BC

1 B

A

tmin

tmax

Internal node: split

D

Page 23: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

4 5

D 3

2 C

Traversing a KD-Tree

23

BC

1 B

A

tmin

tmax

Assume it’s leaf node: intersect all objects

D

A

Page 24: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

4 5

D 3

2 C

Traversing a KD-Tree

24

BC

1 B

Atmin

tmax

Internal node: split

D

A

Page 25: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

4 5

D 3

2 C

Traversing a KD-Tree

25

BC

1 B

Atmin

tmax

Leaf node: intersect all objects

D

A

Page 26: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

4 5

D 3

2 C

Traversing a KD-Tree

26

BC

1 B

A

tmin

tmax

Internal node: split

D

A

Page 27: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

4 5

D 3

2 C

Traversing a KD-Tree

27

BC

1 B

A

tmin

tmax

ALeaf node: intersect all objects

D

Page 28: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

4 5

D 3

2 C

Traversing a KD-Tree

28

BC

D

1 B

A

thit

Intersection foundA

Page 29: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

Object Partitions &

Bounding Volume Hierarchy (BVH)

Page 30: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Bounding Volume Hierarchy (BVH)

30

Root

Page 31: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Bounding Volume Hierarchy (BVH)

31

Page 32: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Bounding Volume Hierarchy (BVH)

32

Page 33: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

C D

B

Bounding Volume Hierarchy (BVH)

33

A

AB

C

D

Page 34: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Summary: Building BVHs

• Find bounding box

• Recursively split set of objects in two subsets

• Recompute the bounding box of the subsets

• Stop when necessary

• Store objects in each leaf node

34

Page 35: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Building BVHs

How to subdivide a node?

• Choose a dimension to split

• Heuristic #1: Always choose the longest axis in node

• Heuristic #2: Split node at location of median object

Termination criteria?

• Heuristic: stop when node contains few elements (e.g. 5)

35

Page 36: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Data Structure for BVHs

Internal nodes store

• Bounding box

• Children: pointers to child nodes

Leaf nodes store

• Bounding box

• List of objects

Nodes represent subset of primitives in scene

• All objects in subtree

36

Page 37: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

BVH Traversal

Intersect(Ray ray, BVH node) {

if (ray misses node.bbox) return;

if (node is a leaf node)

test intersection with all objs;

return closest intersection;

hit1 = Intersect(ray, node.child1);

hit2 = Intersect(ray, node.child2);

return the closer of hit1, hit2;

}

37

node

child1 child2

Page 38: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Spatial vs Object Partitions

Spatial partition (e.g.KD-tree) • Partition space into

non-overlapping regions • An object can be contained

in multiple regions

Object partition (e.g. BVH) • Partition set of objects into

disjoint subsets • Bounding boxes for each set

may overlap in space

38

Page 39: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Today

• Using AABBs to accelerate ray tracing

- Uniform grids

- Spatial partitions

• Basic radiometry (辐射度量学)

- Advertisement: new topics from now on, scarcely covered in other graphics courses

39

Page 40: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Radiometry — Motivation

Observation

• In assignment 3, we implement the Blinn-Phong model

• Light intensity I is 10, for example

• But 10 what?

Do you think Whitted style ray tracing gives you CORRECT results?

All the answers can be found in radiometry

• Also the basics of “Path Tracing”

40

Page 41: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Radiometry

Measurement system and units for illumination

Accurately measure the spatial properties of light

- New terms: Radiant flux, intensity, irradiance, radiance

Perform lighting calculations in a physically correct manner

—————————————————————————

My personal way of learning things:

- WHY, WHAT, then HOW

41

Page 42: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

Radiant Energy and Flux (Power)

Page 43: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Radiant Energy and Flux (Power)

Definition: Radiant energy is the energy of electromagnetic radiation. It is measured in units of joules, and denoted by the symbol:

Definition: Radiant flux (power) is the energy emitted, reflected, transmitted or received, per unit time.

43

Q [J = Joule]

� ⌘ dQ

dt[W = Watt] [lm = lumen]*

Page 44: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Flux – #photons flowing through a sensor in unit time

44

From London and Upton

Page 45: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Important Light Measurements of Interest

45

Light Emitted From A Source

Light Falling On A Surface

Light Traveling Along A Ray

“Radiant Intensity” “Irradiance” “Radiance”

Page 46: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

Radiant Intensity

Page 47: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Radiant Intensity

Definition: The radiant (luminous) intensity is the power per unit solid angle (?) emitted by a point light source.

47

I(!) ⌘ d�

d!

W

sr

� lm

sr= cd = candela

I(!) ⌘ d�

d!

W

sr

� lm

sr= cd = candela

The candela is one of the seven SI base units.

(⽴体⻆)

Page 48: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Angles and Solid Angles

Angle: ratio of subtended arc length on circle to radius

• Circle has radians

48

2⇡

✓ =l

r

✓✓ =l

r✓ =

l

r

Solid angle: ratio of subtended area on sphere to radius squared

• Sphere has steradians

⌦ =A

r2

4⇡

✓ =l

r⌦ =

A

r2

Page 49: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Differential Solid Angles

49

dA =(r d✓)(r sin ✓ d�)

=r2 sin ✓ d✓ d�

d! =dA

r2= sin ✓ d✓ d�

Page 50: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Differential Solid Angles

50

⌦ =

Z

S2

d!

=

Z ⇡

0

Z 2⇡

0sin ✓ d✓ d�

=

Z 1

�1

Z 2⇡

0d cos ✓ d�

=4⇡

⌦ =

Z

S2

d!

=

Z ⇡

0

Z 2⇡

0sin ✓ d✓ d�

=

Z 1

�1

Z 2⇡

0d cos ✓ d�

=4⇡

⌦ =

Z

S2

d!

=

Z 2⇡

0

Z ⇡

0sin ✓ d✓ d�

=

Z 1

�1

Z ⇡

0d cos ✓ d�

=4⇡

Sphere: S2

Page 51: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

as a direction vector

51

! Will use to denote a direction vector (unit length)

!

!

Page 52: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Isotropic Point Source

52

� =

Z

S2

I d!

=4⇡I

I =�

4⇡

Page 53: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

GAMES101 Lingqi Yan, UC Santa Barbara

Modern LED Light

53

Output: 815 lumens

(11W LED replacement for 60W incandescent)

Radiant intensity?

Assume isotropic: Intensity = 815 lumens / 4pi sr = 65 candelas

Page 54: GAMES101 Lecture 14lingqi/teaching/resources/GAMES101_Lect… · GAMES101 Lingqi Yan, UC Santa Barbara Data Structure for KD-Trees Internal nodes store • split axis: x-, y-, or

Thank you!(And thank Prof. Ravi Ramamoorthi and Prof. Ren Ng for many of the slides!)