cs 636 advanced rendering techniques · cs636_pres4 author: david breen created date: 4/13/2020...

64
CS 636 Advanced Rendering Techniques Dr. David Breen Online Wednesday 6PM ® 8:50PM Presentation 4 4/29/20

Upload: others

Post on 06-Aug-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

CS 636 Advanced Rendering Techniques

Dr. David BreenOnlineWednesday 6PM ® 8:50PM

Presentation 44/29/20

Page 2: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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

Page 3: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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

Page 4: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Transformations & Hierarchical Models

Page 5: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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

Page 6: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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

Homogeneous Coordinates

x'y'z'1

=

xyz1

aei0

bfj0

cgk0

dhl1

Page 7: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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'

Page 8: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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

Page 9: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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'

θ

Page 10: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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

Page 11: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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

Page 12: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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

Page 13: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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)

Page 14: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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

Page 15: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Transformations in Ray Tracing

Page 16: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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

Page 17: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Scene Description

Scene

LightsCamera ObjectsMaterialsBackground

Page 18: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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> }

Page 19: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Hierarchical Models

n Logical organization of scene

Page 20: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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

Page 21: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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

Page 22: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Adding Transformations

Page 23: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Using Transformations

n Position the logical groupings of objects within the scene

n Transformation in group

Page 24: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Directed Acyclic Graph is more efficient and useful

Page 25: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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!

Page 26: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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

Page 27: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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

Page 28: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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)

Page 29: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Transform Normalsn Why? They’re used for shading

object color only Diffuse Shading

Page 30: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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

Page 31: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Given overlapping shapes A and B:

Union Intersection Subtraction

Constructive Solid Geometry (CSG)

Page 32: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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

Page 33: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Collect all the intersections

Union Intersection Subtraction

Page 34: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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

Page 35: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Constructive Solid Geometry

Ray Tracing CSG Models

Rick ParentOhio State U.

Page 36: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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

Page 37: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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

Page 38: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Ray tracing CSG modelsn Intersect ray with primitivesn Produces “spans” along rayn Perform Boolean operations on

spansn Determines intersection of evaluated

modeln Calculate normal at intersection

Page 39: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Union

Min (tCmin, tB

min )

B

C +

BC

Ray intersects union: at first intersection

Page 40: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Possible ways for 2 spans to overlap

Page 41: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Intersection

++

If ((tCmin< tB

min ) and (tCmax> tB

min ) ): tBmin

Else If ((tBmin< tC

min ) and (tBmax> tC

min ) ): tCmin

Else: none

BC

B

C

First time in B and in C

Page 42: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Difference

-

B C

If ((tBmin< tC

min ): tBmin

Else if (tCmax< tB

max ): tCmax

Else: none

B

C

First time in B not in C

Page 43: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Difference-

BC

If ((tCmin< tB

min): tCmin

Else if (tBmax< tC

max ): tBmax

Else: none

B

C

First time in C not in B

Page 44: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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

Page 45: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Controlling the Combinations

-+

+

?

Page 46: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Tree Structure

circlerectangle rectangle

+ +

+ -

T1T2 T3

T4

T5- +

+T1

T2

T3

Page 47: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Tree Structure #1

Page 48: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Tree Structure

circlerectangle rectangle

+ +

- +

T1T2 T3

T4

T5- +

+T1

T2

T3

Page 49: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Tree Structure #2

Page 50: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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

• union• intersection• difference

• Might create multiple spans

Page 51: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Union of Spans

Page 52: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Intersection of Spans

Page 53: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Difference of Spans

Page 54: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Normals of CSG intersections

Normal of some surface (or its negation)

Union or intersection: positive normal of intersected surface

Page 55: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Difference normals• Intersection is one of:

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

Page 56: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Add transformations to tree

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

Page 57: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

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

Page 58: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Example

Page 59: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Example

Page 60: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Example

Page 61: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Example (Simon Chorley)

Page 62: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Example (Simon Chorley)

Page 63: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

For example:

Page 64: CS 636 Advanced Rendering Techniques · CS636_Pres4 Author: David Breen Created Date: 4/13/2020 9:09:51 PM

Wrap Upn Discuss status/problems/issues with

this week’s programming assignment