Download - Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Transcript
Page 1: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Review

CSE167: Computer Graphics

Instructor: Steve Rotenberg

UCSD, Fall 2005

Page 2: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Final

The final is on Tuesday, December 6 From 11:30-2:30 Center Hall, room 105 It will cover material from the entire quarter It will be similar to the midterm, but with 20

questions There will not be any questions on C++ or

OpenGL

Page 3: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Topics

The final will have geometry problems similar to those in the midterm

There will be some mathematical questions about curved surfaces and ray tracing (lectures 12, 13, & 16)

I suggest studying lectures 12, 13 & 16 well, as I might ask about anything from those (you don’t have to memorize the Fresnel equations, but you should know what they are for)

There will not be any math questions about BRDFs, the ‘Rendering Equation’, or global illumination, but I expect you to be familiar with the concepts of these things

There will be conceptual questions about scene management and modeling

There will also be mathematical and conceptual questions from things covered in the first half of the class (traditional graphics pipeline)

Page 4: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Example: Distance to Plane

A plane is described by a point p on the plane and a unit normal n. Find the distance from point x to the plane

•p

n

• x

Page 5: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Example: Distance to Plane

The distance is the length of the projection of x-p onto n:

•p

n

• x

x-p

npx dist

Page 6: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Example: Target ‘Lock On’

For an airplane to get a missile locked on, the target must be within a 10 degree cone in front of the plane. If the plane’s matrix is M and the target position is t, find an expression that determines if the plane can get a lock on.

M

• t

Page 7: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Example: Target ‘Lock On’

For an airplane to get a missile locked on, the target must be within a 10 degree cone in front of the plane. If the plane’s matrix is M and the target position is t, find an expression that determines if the plane can get a lock on.

a

b

cd

• t

Page 8: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Example: Target ‘Lock On’

We want to check the angle between the heading vector (-c) and the vector from d to t:

We can speed that up by comparing the cosine instead ( cos(10°)=.985 )

10cos 1

td

ctdif

985.0

td

ctdif

Page 9: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Example: Target ‘Lock On’

We can even speed that up further by removing the division and the square root in the magnitude computation:

All together, this requires 8 multiplications and 8 adds

22 *970.0 tdctd if

Page 10: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Example: Camera ‘Look At’

Our eye is located at position e and we want to look at a target at position t. Generate an appropriate camera matrix M.

Page 11: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Example: Camera ‘Look At’

Our eye is located at position e and we want to look at a target at position t. Generate an appropriate camera matrix M.

Two possible approaches include: Measure angles and rotate matrix into place Construct a,b,c, & d vectors of M directly

Page 12: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Example: Camera ‘Look At’Method 1: Measure Angles & Rotate

Measure Angles: Tilt angle Heading angle Position

Construct matrix by starting with the identity, then apply tilt and heading rotations

Page 13: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Example: Camera ‘Look At’Method 2: Build Matrix Directly

The d vector is just the position of the camera, which is e:

The c vector is a unit length vector that points directly behind the viewer:

te

tec

ed

Page 14: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Example: Camera ‘Look At’Method 2: Build Matrix Directly

The a vector is a unit length vector that points to the right of the viewer. It is perpendicular to the c axis. To keep the camera from rolling, we also want the a vector to lay flat in the xz-plane, perpendicular to the y-axis.

Note that a cross product with the y-axis can be optimized as follows:

cy

cya

xz cc 0010 c

Page 15: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Example: Camera ‘Look At’Method 2: Build Matrix Directly

The b vector is a unit length vector that points up relative to the viewer. It is perpendicular to the both the c and a axes

Note that b does not need to be normalized because it is already unit length. This is because a and c are unit length vectors 90 degrees apart.

acb

1*1*190sin acb

Page 16: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Example: Camera ‘Look At’Method 2: Build Matrix Directly

Summary:

acb

te

tec

ed

cy

cya

Page 17: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Position Vector Dot Matrix

zzzzyzxz

yyzyyyxy

xxzxyxxx

z

y

x

zzzz

yyyy

xxxx

dcvbvavv

dcvbvavv

dcvbvavv

v

v

v

dcba

dcba

dcba

11000

vMv

dcbav zyx vvv

Page 18: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Position Vector Dot Matrix

dcbav zyx vvv

v=(.5,.5,0,1)

x

y

Local Space

(0,0,0)

Page 19: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Position Vector Dot Matrix

dcbav zyx vvv

v=(.5,.5,0,1)

x

y

Local Space

(0,0,0)x

y

World Space

(0,0,0)

a

b

d

Matrix M

Page 20: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Position Vector Dot Matrix

dcbav zyx vvv

v=(.5,.5,0,1)

x

y

Local Space

(0,0,0)x

y

World Space

(0,0,0)

a

b

d

v’

Page 21: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Position vs. Direction Vectors

Vectors representing a position in 3D space are expanded into 4D as:

Vectors representing direction are expanded as:

1zyx vvv

0zyx vvv

Page 22: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Direction Vector Dot Matrix

cbav zyx vvv

zzzyzxz

yzyyyxy

xzxyxxx

z

y

x

zzzz

yyyy

xxxx

cvbvavv

cvbvavv

cvbvavv

v

v

v

dcba

dcba

dcba

01000

vMv

Page 23: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

The abcd vectors of M’ are the abcd vectors of M transformed by matrix N

Notice that a, b, and c transform as direction vectors and d transforms as a position

Matrix Dot Matrix

1000zzzz

yyyy

xxxx

dcba

dcba

dcba

MMNM

Page 24: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Identity

Take one more look at the identity matrix It’s a axis lines up with x, b lines up with y, and c lines up with z Position d is at the origin Therefore, it represents a transformation with no rotation or

translation

1000

0100

0010

0001

I

Page 25: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Linear Interpolation

Linear interpolation (Lerp) is a common technique for generating a new value that is somewhere in between two other values

A ‘value’ could be a number, vector, color, or even something more complex like an entire 3D object…

Consider interpolating between two points a and b by some parameter t

baba tttLerp 1,,

a

b

t=1.

. 0<t<1t=0

Page 26: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

de Casteljau Algorithm

p0

p1

p2

p3

We start with our original set of points

In the case of a cubic Bezier curve, we start with four points

Page 27: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

de Casteljau Algorithm

p0

q0

p1

p2

p3

q2

q1

322

211

100

,,

,,

,,

ppq

ppq

ppq

tLerp

tLerp

tLerp

Page 28: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

de Casteljau Algorithm

q0

q2

q1

r1

r0

211

100

,,

,,

qqr

qqr

tLerp

tLerp

Page 29: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

de Casteljau Algorithm

r1x

r0•

10 ,, rrx tLerp

Page 30: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Bezier Curve

x•

p0

p1

p2

p3

Page 31: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Recursive Linear Interpolation

322

211

100

,,

,,

,,

ppq

ppq

ppq

tLerp

tLerp

tLerp

211

100

,,

,,

qqr

qqr

tLerp

tLerp

10 ,, rrx tLerp

3

2

1

0

p

p

p

p

2

1

0

q

q

q

1

0

r

rx

3

2

1

0

p

p

p

p

Page 32: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Expanding the Lerps

3221

211010

3221211

2110100

32322

21211

10100

111

1111,,

111,,

111,,

1,,

1,,

1,,

pppp

pppprrx

ppppqqr

ppppqqr

ppppq

ppppq

ppppq

ttttttt

ttttttttLerp

tttttttLerp

tttttttLerp

tttLerp

tttLerp

tttLerp

Page 33: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Bernstein Polynomials

!!

!1

33

363

133

363363133

333

2332

2331

2330

3

33

223

123

023

ini

n

i

ntt

i

ntB

ttB

tttB

ttttB

ttttB

tBt

ttttttttttt

iinni

ii

px

ppppx

Page 34: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

The Bernstein polynomial form of a Bezier curve is

where

and

Bernstein Polynomials

n

ii

ni tBt

0

px

iinni tt

i

ntB

1

!!

!

ini

n

i

n

Page 35: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Bernstein Polynomials

B33B0

3

B13 B2

3

Page 36: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Cubic Equation Form

0

10

210

3210

23

010

2210

33210

33

363

33

133

36333

pd

ppc

pppb

ppppa

dcbax

ppp

pppppppx

ttt

t

tt

Page 37: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Cubic Matrix Form

0

10

210

3210

23

33

363

33

pd

ppc

pppb

ppppa

dcbax

ttt

3

2

1

0

23

0001

0033

0363

1331

1

p

p

p

p

d

c

b

a

d

c

b

a

x ttt

Page 38: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Cubic Matrix Form

zyx

zyx

zyx

zyx

ppp

ppp

ppp

ppp

ttt

ttt

333

222

111

000

23

3

2

1

0

23

0001

0033

0363

1331

1

0001

0033

0363

1331

1

x

p

p

p

p

x

Page 39: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Matrix Form

Ctx

GBtx

x

BezBez

zyx

zyx

zyx

zyx

ppp

ppp

ppp

ppp

ttt

333

222

111

000

23

0001

0033

0363

1331

1

Page 40: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Bezier Curves & Cubic Curves

By adjusting the 4 control points of a cubic Bezier curve, we can represent any cubic curve

Likewise, any cubic curve can be represented uniquely by a cubic Bezier curve

There is a one-to-one mapping between the 4 Bezier control points (p0,p1,p2,p3) and the pure cubic coefficients (a,b,c,d)

The Bezier basis matrix BBez (and it’s inverse) perform this mapping

There are other common forms of cubic curves that also retain this property (Hermite, Catmull-Rom, B-Spline)

Page 41: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Derivatives

Finding the derivative (tangent) of a curve is easy:

cbax

dcbax ttdt

dttt 23 223

d

c

b

a

x

d

c

b

a

x 01231 223 ttdt

dttt

Page 42: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Tangents

The derivative of a curve represents the tangent vector to the curve at some point

tdt

dx

tx

Page 43: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Convex Hull Property

If we take all of the control points for a Bezier curve and construct a convex polygon around them, we have the convex hull of the curve

An important property of Bezier curves is that every point on the curve itself will be somewhere within the convex hull of the control points

p0

p1

p2

p3

Page 44: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Continuity

A cubic curve defined for t ranging from 0 to 1 will form a single continuous curve and not have any gaps

We say that it has geometric continuity, or C0 continuity We can easily see that the first derivative will be a

continuous quadratic function and the second derivative will be a continuous linear function

The third derivative (and all others) are continuous as well, but in a trivial way (constant), so we generally just say that a cubic curve has second derivative continuity or C2 continuity

In general, the higher the continuity value, the ‘smoother’ the curve will be, although it’s actually a little more complicated than that…

Page 45: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Interpolation / Approximation

We say that cubic Bezier curves interpolate the two endpoints (p0 & p3), but only approximate the interior points (p1 & p2)

In geometric design applications, it is often desirable to be able to make a single curve that interpolates through several points

Page 46: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Piecewise Curves

Rather than use a very high degree curve to interpolate a large number of points, it is more common to break the curve up into several simple curves

For example, a large complex curve could be broken into cubic curves, and would therefore be a piecewise cubic curve

For the entire curve to look smooth and continuous, it is necessary to maintain C1 continuity across segments, meaning that the position and tangents must match at the endpoints

For smoother looking curves, it is best to maintain the C2 continuity as well

Page 47: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Connecting Bezier Curves

A simple way to make larger curves is to connect up Bezier curves Consider two Bezier curves defined by p0…p3 and v0…v3

If p3=v0, then they will have C0 continuity If (p3-p2)=(v1-v0), then they will have C1 continuity C2 continuity is more difficult…

p0

p0

p1

p2

P3

P3

p2

p1

v0

v1

v2

v3

v3

v2

v1

v0

C0 continuity C1 continuity

Page 48: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Bezier Surfaces Bezier surfaces are a straightforward extension to Bezier curves Instead of the curve being parameterized by a single variable t, we

use two variables, s and t By definition, we choose to have s and t range from 0 to 1 and we

say that an s-tangent crossed with a t-tangent will represent the normal for the front of the surface

s

t

0,0

1,1

1,0

0,1

n

Page 49: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Curved Surfaces

The Bezier surface is a type of parametric surface A parametric surface is a surface that can be

parametrized by two variables, s and t Parametric surfaces have a rectangular topology In computer graphics, parametric surfaces are

sometimes called patches, curved surfaces, or just surfaces

There are also some non-parametric surfaces used in computer graphics, but we won’t consider those now

Page 50: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Control Mesh

Consider a bicubic Bezier surface (bicubic means that it is a cubic function in both the s and t parameters)

A cubic curve has 4 control points, and a bicubic surface has a grid of 4x4 control points, p0 through p15

p0 p1

p2

p3

p4 p5

p6

p7

p8 p9

p10

p11

p12 p13

p14 p15

s

t

Page 51: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Surface Evaluation The bicubic surface can be thought of as 4 curves along the s parameter (or

alternately as 4 curves along the t parameter) To compute the location of the surface for some (s,t) pair, we can first solve

each of the 4 s-curves for the specified value of s Those 4 points now make up a new curve which we evaluate at t Alternately, if we first solve the 4 t-curves and to create a new curve which

we then evaluate at s, we will get the exact same answer This gives a pretty straightforward way to implement smooth surfaces with

little more than what is needed to implement curves

s

t(0.2, 0.6)

Page 52: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Matrix Form

We saw the matrix form for a 3D Bezier curve is

Ctx

GBtx

x

BezBez

zyx

zyx

zyx

zyx

ppp

ppp

ppp

ppp

ttt

333

222

111

000

23

0001

0033

0363

1331

1

Page 53: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Matrix Form

To simplify notation for surfaces, we will define a matrix equation for each of the x, y, and z components, instead of combining them into a single equation as for curves

For example, to evaluate the x component of a Bezier curve, we can use:

x

xBez

x

x

x

x

x

x

p

p

p

p

tttx

ct

gBt

3

2

1

0

23

0001

0033

0363

1331

1

Page 54: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Matrix Form

To evaluate the x component of 4 curves simultaneously, we can combine 4 curves into a 4x4 matrix

To evaluate a surface, we evaluate the 4 curves, and use them to make a new curve which is then evaluated

This can be written in a compact matrix form:

1

1

,

23

23

ttt

sss

tsx TTBezxBez

t

s

tBGBs

Page 55: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Matrix Form

1

1

,

23

23

ttt

sss

ts

TBezxBezx

Tz

Ty

Tx

t

s

BGBC

tCs

tCs

tCs

x

xxxx

xxxx

xxxx

xxxx

x

TBezBez

pppp

pppp

pppp

pppp

151173

141062

13951

12840

0001

0033

0363

1331

G

BB

Page 56: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Matrix Form

Cx stores the coefficients of the bicubic equation for x Gx stores the geometry (x components of the control

points) BBez is the basis matrix (Bezier basis) s and t are the vectors formed from the exponents of s

and t

The matrix form is a nice and compact notation and leads to an efficient method of computation

It can also take advantage of 4x4 matrix support which is built into modern graphics hardware

Page 57: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Tangents

To compute the s and t tangent vectors at some (s,t) location, we can use:

Tz

Ty

Tx

Tz

Ty

Tx

d

d

d

t

d

d

d

s

tCs

tCs

tCsx

tCs

tCs

tCsx

0123

0123

1

1

2

2

23

23

ttd

ssd

ttt

sss

t

s

t

s

Page 58: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Normals

To compute the normal of the surface at some location (s,t), we compute the two tangents at that location and then take their cross product

Usually, it is normalized as well

*

*

*

n

nn

xxn

ts

s

tn

x

sx

tx

Page 59: Review CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.

Bezier Surface Properties

Like Bezier curves, Bezier surfaces retain the convex hull property, so that any point on the actual surface will fall within the convex hull of the control points

With Bezier curves, the curve will interpolate (pass through) the first and last control points, but will only approximate the other control points

With Bezier surfaces, the 4 corners will interpolate, and the other 12 points in the control mesh are only approximated

The 4 boundaries of the Bezier surface are just Bezier curves defined by the points on the edges of the surface

By matching these points, two Bezier surfaces can be connected precisely