CS 636 Start Up Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date:...

11
1 CS 636 Advanced Rendering Techniques Dr. David Breen Online Wednesday 6PM ® 8:50PM Presentation 4 4/29/20 1 Start Up n Any questions from last time? n Go over acceleration techniques? n Or intersection algorithms? 2 Slide Credits n Leonard McMillan, Seth Teller, Fredo Durand, Barb Cutler - MIT n G. Drew Kessler, Larry Hodges - Georgia Institute of Technology n John Hart - University of Illinois n Rick Parent - Ohio State University 3 Transformations & Hierarchical Models 28 n Add an extra dimension in 2D, we use 3 x 3 matrices In 3D, we use 4 x 4 matrices n Each point has an extra value, w Homogeneous Coordinates x' y' z' w' = x y z w a e i m b f j n c g k o d h l p p' = M p 29 n Most of the time w = 1, and we can ignore it Homogeneous Coordinates x' y' z' 1 = x y z 1 a e i 0 b f j 0 c g k 0 d h l 1 30

Transcript of CS 636 Start Up Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date:...

Page 1: CS 636 Start Up Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:10:11 PM ...

1

CS 636 Advanced Rendering Techniques

Dr. David BreenOnlineWednesday 6PM ® 8:50PM

Presentation 44/29/20

1

Start Upn Any questions from last time?n Go over acceleration techniques?n Or intersection algorithms?

2

Slide Creditsn Leonard McMillan, Seth Teller,

Fredo Durand, Barb Cutler - MITn G. Drew Kessler, Larry Hodges - Georgia

Institute of Technologyn John Hart - University of Illinoisn Rick Parent - Ohio State University

3

Transformations & Hierarchical Models

28

n Add an extra dimension• in 2D, we use 3 x 3 matrices• In 3D, we use 4 x 4 matrices

n Each point has an extra value, w

Homogeneous Coordinates

x'y'z'w'

=

xyzw

aeim

bfjn

cgko

dhlp

p' = M p

29

n Most of the time w = 1, and we can ignore it

Homogeneous Coordinates

x'y'z'1

=

xyz1

aei0

bfj0

cgk0

dhl1

30

Page 2: CS 636 Start Up Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:10:11 PM ...

2

Translate (tx, ty, tz)n Why bother with the

extra dimension?Because now translations can be encoded in the matrix!

Translate(c,0,0)

x

y

p p'

c

x'y'z'1

=

xyz1

1000

0100

0010

tx

ty

tz

1

x'y'z'

31

Scale (sx, sy, sz)n Isotropic (uniform)

scaling: sx = sy = sz

n You only have to implement uniform scaling

x'y'z'1

=

xyz1

sx

000

0sy

00

00sz

0

0001

Scale(s,s,s)

x

p

p'

qq'

y

32

Rotationn About z axis

x'y'z'1

=

xyz1

cos fsin f

00

-sin fcos f

00

0010

0001

ZRotate(f)

x

y

z

p

p'

θ

33

Rotation

n About x axis:

n About y axis:

x'y'z'1

=

xyz1

0cos asin a

0

0-sin acos a

0

1000

0001

x'y'z'1

=

xyz1

cos q0

-sin q0

sin q0

cos q0

0100

0001

34

Rotationn About (kx, ky, kz), an

arbitrary unit vector (Rodrigues Formula)

x'y'z'1

=

xyz1

kxkx(1-c)+ckykx(1-c)+kzskzkx(1-c)-kys

0

0001

kykx(1-c)-kzskyky(1-c)+c

kzky(1-c)+kxs0

kxkz(1-c)+kyskykz(1-c)-kxskzkz(1-c)+c

0

where c = cos q & s = sin q

Rotate(k, q)

x

y

z

θ

k

35

How are transforms combined?

(0,0)(1,1)

(2,2)

(0,0)

(5,3)

(3,1)Scale(2,2) Translate(3,1)

TS =20

02

00

10

01

31

20

02

31=

Scale then Translate

Use matrix multiplication: p' = T ( S p ) = ((TS) p)

Caution: matrix multiplication is NOT commutative!

0 0 1 0 0 1 0 0 1

36

Page 3: CS 636 Start Up Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:10:11 PM ...

3

Non-commutative CompositionScale then Translate: p' = T ( S p ) = TS p

Translate then Scale: p' = S ( T p ) = ST p

(0,0)(1,1)

(4,2)(3,1)

(8,4)

(6,2)

(0,0)(1,1)

(2,2)

(0,0)

(5,3)

(3,1)Scale(2,2) Translate(3,1)

Translate(3,1) Scale(2,2)

37

TS =200

020

001

100

010

311

ST =20

02

00

10

01

31

Non-commutative CompositionScale then Translate: p' = T ( S p ) = TS p

200

020

311

20

02

62

=

=

Translate then Scale: p' = S ( T p ) = ST p

0 0 1 0 0 1 0 0 1

38

Transformations in Ray Tracing

39

Transformations in Modelingn Position objects in a scenen Change the shape of objectsn Create multiple copies of objectsn Projection for virtual camerasn Animations

40

Scene Description

Scene

LightsCamera ObjectsMaterialsBackground

41

Simple Scene Description File

Camera {center 0 0 10direction 0 0 -1up 0 1 0 }

Lights {numLights 1DirectionalLight {

direction -0.5 -0.5 -1color 1 1 1 } }

Background { color 0.2 0 0.6 }

Materials {numMaterials <n>

<MATERIALS> }

Group { numObjects <n><OBJECTS> }

42

Page 4: CS 636 Start Up Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:10:11 PM ...

4

Hierarchical Models

n Logical organization of scene

43

Group { numObjects 3Group {

numObjects 3Box { <BOX PARAMS> }Box { <BOX PARAMS> }Box { <BOX PARAMS> } }

Group {numObjects 2Group {

Box { <BOX PARAMS> }Box { <BOX PARAMS> }Box { <BOX PARAMS> } }

Group {Box { <BOX PARAMS> }Sphere { <SPHERE PARAMS> }Sphere { <SPHERE PARAMS> } } }

Plane { <PLANE PARAMS> } }

Simple Example with Groups

44

Group { numObjects 3Group {

numObjects 3Box { <BOX PARAMS> }Box { <BOX PARAMS> }Box { <BOX PARAMS> } }

Group {numObjects 2Group {

Box { <BOX PARAMS> }Box { <BOX PARAMS> }Box { <BOX PARAMS> } }

Group {Box { <BOX PARAMS> }Sphere { <SPHERE PARAMS> }Sphere { <SPHERE PARAMS> } } }

Plane { <PLANE PARAMS> } }

Adding Materials

45

Adding Transformations

46

Using Transformations

n Position the logical groupings of objects within the scene

n Transformation in group

47

Directed Acyclic Graph is more efficient and useful

48

Page 5: CS 636 Start Up Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:10:11 PM ...

5

Processing Model Transformattions

n Goaln Get everything into world coordinates

n Traverse graph/tree in depth-first ordern Concatenate transformationsn Can store intermediate transformationsn Apply/associate final transformation to

primitive at leaf noden What about cylinders, superquadrics, etc.?

n Transform ray!

49

Transform the Ray

n Map the ray from World Spaceto Object Space

World Space

r majorr minor

(x,y)

(0,0) Object Space

r = 1

pWS = M pOS

pOS = M-1 pWS

50

Transform Rayn New origin:

n New direction:originOS = M-1 originWS

directionOS = M-1 (originWS + 1 * directionWS) - M-1 originWS

originOS

originWS

directionOS

directionWS

Object SpaceWorld Space

qWS = originWS + tWS * directionWS

qOS = originOS + tOS * directionOS

directionOS = M-1 directionWS

51

Transforming Points & Directions

n Transform point

n Transform direction

n Map intersection point and normal back to world coordinates

Homogeneous Coordinates: (x,y,z,w)W = 0 is a point at infinity (direction)

52

Transform Normalsn Why? They’re used for shading

object color only Diffuse Shading

53

Transforming Normalsn A surface normal is a property, not a

geometric entity

n Correct normal transformation matrix:

See https://www.scratchapixel.com/lessons/mathematics-physics-for-computer-graphics/geometry/transforming-normals

54

Page 6: CS 636 Start Up Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:10:11 PM ...

6

Given overlapping shapes A and B:

Union Intersection Subtraction

Constructive Solid Geometry (CSG)

55

How can we implement CSG?

Points on A, Outside of B

Points on B, Outside of A

Points on B, Inside of A

Points on A, Inside of B

Union Intersection Subtraction

56

Collect all the intersections

Union Intersection Subtraction

57

Implementing CSG

1. Test "inside" intersections:• Find intersections with A,

test if they are inside/outside B• Find intersections with B,

test if they are inside/outside A

2. Overlapping intervals:• Find the intervals of "inside"

along the ray for A and B• Compute

union/intersection/subtractionof the intervals

58

Constructive Solid Geometry

Ray Tracing CSG Models

Rick ParentOhio State U.

59

Seminal paper Ray tracing CSG models

nS.D. Roth, "Ray Casting for Modeling Solids", Computer Graphics and Image Processing 18 (2): 109–144, February 1982

60

Page 7: CS 636 Start Up Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:10:11 PM ...

7

CSGn Form object as booleans of primitive

objectsn Primitives: sphere, cube, cylinder, conen Boolean operators: union, intersection,

differencen Tree structure used to manage operations

n Leaf nodes are primitive objectsn Intermediate nodes specify combination

operator

61

Ray tracing CSG modelsn Intersect ray with primitivesnProduces “spans” along raynPerform Boolean operations on

spansnDetermines intersection of evaluated

modelnCalculate normal at intersection

62

Union

Min (tCmin, tBmin )

B

C +

BC

Ray intersects union: at first intersection

63

Possible ways for 2 spans to overlap

64

Intersection

++

If ((tCmin< tBmin ) and (tCmax> tBmin ) ): tBmin Else If ((tBmin< tCmin ) and (tBmax> tCmin ) ): tCmin Else: none

BC

B

C

First time in B and in C

65

Difference

-

B C

If ((tBmin< tCmin ): tBmin Else if (tCmax< tBmax ): tCmaxElse: none

B

C

First time in B not in C

66

Page 8: CS 636 Start Up Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:10:11 PM ...

8

Difference-

BC

If ((tCmin< tBmin): tCmin Else if (tBmax< tCmax ): tBmaxElse: none

B

C

First time in C not in B

67

PrimitivesAnything that can be intersected (easily) with a ray

Conics: solve analytically using R(t)Convex polyhedraA plane (a cutting plane is useful)

can be used as a modeling tool (boolean operations) surface model (e.g., polyhedron) computed from CGS

or Can be used as a model representation

keep tree structure and ray trace directly

68

Controlling the Combinations

-+

+

?

69

Tree Structure

circlerectangle rectangle

+ +

+ -

T1T2 T3

T4

T5- +

+T1

T2

T3

70

Tree Structure #1

71

Tree Structure

circlerectangle rectangle

+ +

- +

T1T2 T3

T4

T5- +

+T1

T2

T3

72

Page 9: CS 636 Start Up Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:10:11 PM ...

9

Tree Structure #2

73

Tree Structure• Intersect ray with leaf nodes (primitive objects)• Combine intersection spans according to intermediate nodes

• union• intersection• difference

• Might create multiple spans

74

Union of Spans

75

Intersection of Spans

76

Difference of Spans

77

Normals of CSG intersections

Normal of some surface (or its negation)

Union or intersection: positive normal of intersected surface

78

Page 10: CS 636 Start Up Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:10:11 PM ...

10

Difference normals• Intersection is one of:

• tmin of positive object – normal of surface• tmax of negative object – negated normal

79

Add transformations to tree

http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/model/csg.html

80

Bounding Volumes

circlerectangle rectangle

+ +

+ -

T1T2 T3

T4

T5

Construction•Use bounding volumes at leaf nodes• Union bounding volumes at interior nodes

Traversal•Top-down•Test bounding volume at interior

81

Example

82

Example

83

Example

84

Page 11: CS 636 Start Up Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:10:11 PM ...

11

Example (Simon Chorley)

85

Example (Simon Chorley)

86

For example:

87

Wrap Upn Discuss status/problems/issues with

this week’s programming assignment

88