61
CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica Hodgins V2005-05-1.3

CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

Embed Size (px)

Citation preview

Page 1: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

CS-378: Game TechnologyLecture #2.1: Projection

Prof. Okan ArikanUniversity of Texas, Austin

Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica Hodgins

V2005-05-1.3

Page 2: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

22

Today

Windowing and Viewing Transformations

Windows and viewports

Orthographic projection

Perspective projection

Page 3: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

33

Screen Space

Monitor has some number of pixelse.g. 1024 x 768

Some sub-region used for given program

You call it a window

Let’s call it a viewport instead

Page 4: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

44

Screen Space

May not really be a “screen”Image file

Printer

Other

Little pixel details

Sometimes oddUpside down

HexagonalFrom Shirley textbook.

Page 5: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

55

Screen Space

Viewport is somewhere on screenYou probably don’t care where

Window System likely manages this detail

Sometimes you care exactly where

Viewport has a size in pixelsSometimes you care (images, text, etc.)

Sometimes you don’t (using high-level library)

Page 6: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

66

Canonical View Space

Canonical view region2D: [-1,-1] to [+1,+1]

From

Sh

irle

y

textb

ook.

Page 7: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

77

Canonical View Space

Canonical view region2D: [-1,-1] to [+1,+1]

From

Sh

irle

y

textb

ook.

Page 8: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

88

Canonical View Space

Canonical view region

2D: [-1,-1] to [+1,+1]

Define arbitrary window and define objects

Transform window to canonical region

Do other things (we’ll see clipping latter)

Transform canonical to screen space

Draw it.

Page 9: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

99

Canonical View Space

World Coordinates Canonical Screen Space

(Meters) (Pixels)

Note distortion issues...

Page 10: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

1010

Projection

Process of going from 3D to 2D

Studies throughout history (e.g. painters)

Different types of projectionLinear

Orthographic

Perspective

Nonlinear

Orthographic is special case ofperspective...

Many special cases in books just one of these two...

Page 11: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

1111

Linear Projection

Projection onto a planar surface

Projection directions eitherConverge to a point

Are parallel (converge at infinity)

Page 12: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

1212

Linear Projection

A 2D view

OrthographicPerspective

Page 13: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

1313

Linear Projection

Orthographic Perspective

Page 14: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

1414

Linear Projection

Orthographic Perspective

Page 15: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

1515

OrthographicPerspective

Note how different things can be seen

Parallel lines ŅmeetÓ at infinity

Linear Projection

A 2D view

Page 16: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

1616

Orthographic Projection

No foreshortening

Parallel lines stay parallel

Poor depth cues

Page 17: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

1717

Canonical View Space

Canonical view region3D: [-1,-1,-1] to [+1,+1,+1]

Assume looking down -Z axisRecall that “Z is in your face”

[1,1,1][-1,-1,-1]

-Z

[1,1,1][-1,-1,-1]

-Z

Page 18: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

1818

Orthographic Projection

Convert arbitrary view volume to canonical

[1,1,1] [-1,-1,-1]

-Z

[1,1,1] [-1,-1,-1]

-Z

Page 19: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

1919

Orthographic Projection

View vector

Up vector

Right = view X up

Origin

Center

near,top,right

far,bottom,left

*Assume up is perpendicular to view.

Page 20: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

2020

Orthographic Projection

Step 1: translate center to origin

Page 21: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

2121

Orthographic Projection

Step 1: translate center to origin

Step 2: rotate view to -Z and up to +Y

Page 22: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

2222

Orthographic Projection

Step 1: translate center to origin

Step 2: rotate view to -Z and up to +Y

Step 3: center view volume

Page 23: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

2323

Orthographic Projection

Step 1: translate center to origin

Step 2: rotate view to -Z and up to +Y

Step 3: center view volume

Step 4: scale to canonical size

Page 24: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

2424

Orthographic ProjectionOrthographic Projection

Step 1: translate center to origin

Step 2: rotate view to -Z and up to +Y

Step 3: center view volume

Step 4: scale to canonical size

Page 25: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

2525

Perspective Projection

Foreshortening: further objects appear smaller

Some parallel line stay parallel, most don’t

Lines still look like lines

Z ordering preserved (where we care)

Page 26: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

2626

Perspective Projection

Pinhole a.k.a center of projection

Image f

rom

D.

Fors

yth

Page 27: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

2727

Perspective Projection

Foreshortening: distant objects appear smaller

Image f

rom

D.

Fors

yth

Page 28: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

2828

Perspective Projection

Vanishing pointsDepend on the scene

Not intrinsic to camera

“One point perspective”

Page 29: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

2929

Perspective Projection

Vanishing pointsDepend on the scene

Nor intrinsic to camera

“Two point perspective”

Page 30: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

3030

Perspective Projection

Vanishing pointsDepend on the scene

Not intrinsic to camera

“Three point perspective”

Page 31: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

3131

Perspective Projection

u

v

n

u

v

n

View Frustum

Page 32: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

3232

Perspective Projection

ViewUp

Distance to image planei

Y

-Z

Topt

Bottomb

Nearn

Farf

Center

Page 33: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

3333

Perspective Projection

Step 1: Translate center to origin

Y

-Z

Y

-Z

Page 34: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

3434

Perspective Projection

Step 1: Translate center to origin

Step 2: Rotate view to -Z, up to +Y

Y

-Z

Y

-Z

Page 35: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

3535

Perspective Projection

Step 1: Translate center to origin

Step 2: Rotate view to -Z, up to +Y

Step 3: Shear center-line to -Z axis

Y

-Z

Y

-Z

Page 36: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

3636

Perspective Projection

Step 1: Translate center to origin

Step 2: Rotate view to -Z, up to +Y

Step 3: Shear center-line to -Z axis

Step 4: Perspective

-Z-Z

01

00

00

0010

0001

i

fi

fi

Page 37: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

3737

Perspective Projection

Step 4: PerspectivePoints at z=-i stay at z=-i

Points at z=-f stay at z=-f

Points at z=0 goto z=±∞

Points at z=-∞ goto z=-(i+f)

x and y values divided by -z/i

Straight lines stay straightDepth ordering preserved in [-i,-f ]

Movement along lines distorted

-Z-Z

01

00

00

0010

0001

i

fi

fi

01

00

00

0010

0001

i

fi

fi

Page 38: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

3838

From

Sh

irle

y

textb

ook.

From

Sh

irle

y

textb

ook.

Perspective Projection

WRONG!WRONG!

01

00

00

0010

0001

i

fi

fi

01

00

00

0010

0001

i

fi

fi

Page 39: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

3939

Perspective Projection“Eye” plane

Top

Near Far

Som

e ho

rizon

tal

lines

View vector

Page 40: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

4040

Perspective Projection

Visualizing division of x and y but not z

Page 41: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

4141

Perspective Projection

Motion in x,y

Page 42: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

4242

Perspective Projection

Note that points on near plane fixed

Page 43: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

4343

Perspective Projection

Recall that points on far plane willstay there...

Page 44: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

4444

Perspective Projection

When we also divide z points mustremain on straight lines

Page 45: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

4545

Perspective Projection

Lines extend outside view volume

Page 46: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

4646

Perspective Projection

Motion in z

Page 47: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

4747

Perspective Projection

Motion in z

Page 48: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

4848

Perspective Projection

Motion in z

Page 49: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

4949

Perspective Projection

Total motionTotal motion

Page 50: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

5050

Perspective Projection

Step 1: Translate center to orange

Step 2: Rotate view to -Z, up to +Y

Step 3: Shear center-line to -Z axis

Step 4: Perspective

Step 5: center view volume

Step 6: scale to canonical size

-Z-Z

Page 51: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

5151

Perspective Projection

Step 1: Translate center to orange

Step 2: Rotate view to -Z, up to +Y

Step 3: Shear center-line to -Z axis

Step 4: Perspective

Step 5: center view volume

Step 6: scale to canonical size

-Z-Z

Page 52: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

5252

Perspective Projection

There are other ways to set up the projection matrix

View plane at z=0 zero

Looking down another axis

etc...

Functionally equivalent

Page 53: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

5353

Vanishing Points

Consider a ray:

dp dp

Page 54: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

5454

Vanishing Points

Ignore Z part of matrix

X and Y will give location in image plane

Assume image plane at z=-i

0100

0010

0001

z

y

x

I

I

I

w

y

x

100

010

001

0100

0010

0001

z

y

x

I

I

I

w

y

x

100

010

001

whateverwhatever

Page 55: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

5555

Vanishing Points

z

y

x

z

y

x

I

I

I

w

y

x

100

010

001

zy

zx

II

II

wy

wx

/

/

/

/

z

y

x

z

y

x

I

I

I

w

y

x

100

010

001

zy

zx

II

II

wy

wx

/

/

/

/

Page 56: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

5656

Vanishing Points

Assume

tp

tdptp

tdp

zy

zx

II

II

z

yy

z

xx

wy

wx

/

/

/

/

y

x

d

d

t

Lim

tp

tdptp

tdp

zy

zx

II

II

z

yy

z

xx

wy

wx

/

/

/

/

y

x

d

d

t

Lim

Page 57: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

5757

Vanishing Points

All lines in direction d converge to same point in the image plane -- the vanishing point

Every point in plane is a v.p. for some set of lines

Lines parallel to image plane ( ) vanish at infinity

y

x

d

d

t

Lim

y

x

d

d

t

Lim

What’s a horizon?

Page 58: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

5858

Ray Picking

Pick object by picking point on screen

Compute ray from pixel coordinates.

Page 59: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

5959

Ray Picking

Transform from World to Screen is:

Inverse:

What Z value?

w

z

y

x

w

z

y

x

W

W

W

W

I

I

I

I

M

w

z

y

x

w

z

y

x

W

W

W

W

I

I

I

I

M

w

z

y

x

w

z

y

x

I

I

I

I

W

W

W

W

1M

w

z

y

x

w

z

y

x

I

I

I

I

W

W

W

W

1M

Page 60: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

6060

Ray Picking

Recall that:Points at z=-i stay at z=-i

Points at z=-f stay at z=-f

Depends on screen details, YMMVGeneral idea should translate...

Page 61: CS-378: Game Technology Lecture #2.1: Projection Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica

6161

Suggested Reading

Fundamentals of Computer Graphics by Pete Shirley

Chapter 6