lecture 16: projection and camerascs410/yr2017fa/more_progress/... · perspective projection...

32
Lecture 16: Projection and Cameras October 17, 2017

Upload: others

Post on 29-Mar-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

Lecture 16:Projection and Cameras

October 17, 2017

Page 2: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

3D Viewing as Virtual Camera

1. Position the camera/viewpoint in 3D space

2. Orient the camera/viewpoint in 3D space

3. Focus camera – ray trace thin lens

4. Crop image to the aperture/window

5. Project scene onto the image plane

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 2

Totakeapicturewithacamera,ortorenderanimagewithcomputergraphics,weneedto:

Page 3: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

Perspective…

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 3

Page 4: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

OrthographicProjection

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 4

Ifnotforthefog,youcouldseeforever…

andnothingeverwouldlooksmaller.

Page 5: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

Orthographic/PerspectiveThinkAboutRays

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 5

Page 6: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

IsPerspectiveAlwaysBetter?

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 6

No!Technicalprograms,includingforexampleMaple,oftenfavororthographicprojection.

Page 7: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

Math: Orthographic Projection• Simply drop a dimension.

• Think of a bug hitting a windshield.

• No more z axis! – no more bug

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 7

PhotobyBrian,JeffBoothsite

www.jeffbooth.net(creativecommonLicense)

Page 8: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

Perspective Projection• Light rays pass through the focal point.– a.k.a. Eye, principal reference point, or PRP.

• The image plane is an infinite plane in front of (or behind) the focal point.

• Images are formed by rays of light passing through the image plane

• Common convention:– Image points are (u,v)–World points are (x,y,z)

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 8

Page 9: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

Why “Pinhole” Camera?• Because you can build a camera that exactly

fits this description:– Create a fully-enclosed black box• So that no light enters

– Put a piece of film inside it, facing front– Punch a pin-hole in the front face of the box

• What doesn’t this camera have?• What is this camera’s depth-of-field?• Why don’t we build cameras this way?

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 9

Page 10: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

History• The Camera Obscura - see Wikipedia

• Pre-dates photographic cameras.– Theory: Mo-Ti (China, 470-390 BC)– Practice: Abu Ali Al-Hasan Ibn al-Haitham (~1000 AD)– Western Painting: Johannes Vermeer (~1660 AD)

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 10

http://en.wikipedia.org/wiki/Image:Camera_obscura_box.jpg

Page 11: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

PinholeProjectionFliptheBearintheBox

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper Slide 11

Page 12: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper Slide 12

HumanEye- 4yearoldview

DrawingbyBryceBeveridgein2006

Page 13: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

RoomObscura

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 13

Page 14: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

Perspective Projection• Where we place the origin matters• How we handle z values matters• Form #1:– Origin at focal point, z values constant

• Form #2:– Origin at image center, z values are zero

• Form #3: – Origin at focal point, z proportional to depth

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 14

Page 15: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

ThekeytoperspectiveprojectionisthatalllightraysmeetatthePRP(E,focalpoint).

NoticethatwearelookingdowntheZaxis,withtheoriginatthefocalpointandtheimageplaneatz= d. v

z

P(x,y,z)

Pv

d

Pz

Py

PerspectiveProjectionForm#1

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 15

Page 16: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

Pu Pxd Pz

=Pv Pyd Pz

=

Pu = PxdPz

Pv = PydPz

Pu = PxdPz

Pv = PydPz

Bysimilartriangles:

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 16

horizontal vertical

Page 17: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

PerspectiveProjectionMatrix

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 17

Problem: division of one variable by another is a non-linear operation.

Solution: homogeneous coordinates!

1 0 0 00 1 0 00 0 1 00 0 1/d 0

Page 18: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

PerspectiveMatrix(II)

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 18

ProjectionMatrixtimesaPointPointinNon-normalizedHomogeneouscoordinates

Normalized

Pointin(u,v)

coordinates

𝑢𝑣𝑑1=

𝑥𝑑𝑧

𝑦𝑑𝑧𝑑1

=

𝑥𝑦𝑧𝑧𝑑)=

1 0 0 00 1 0 00 0 1 00 0 1

𝑑) 0

𝑥𝑦𝑧1

Page 19: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

What happens to Z?• What happens to the Z dimension?

• The Z dimension projects to d. Why? • Because (u, v, d) is a 3D point on the image

plane located at z = d!10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 19

𝑢𝑣𝑑1=

𝑥𝑑𝑧

𝑦𝑑𝑧𝑑1

=

𝑥𝑦𝑧𝑧𝑑)=

1 0 0 00 1 0 00 0 1 00 0 1

𝑑) 0

𝑥𝑦𝑧1

Page 20: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

PerspectiveProjectionForm#2

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 20

P

Pyv

Od Pz

𝑣𝑑 =

𝑃,𝑑 + 𝑃.

𝑣 = 𝑃,𝑑

𝑑 + 𝑃.

Page 21: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

x dd + z!

"#

$

%&

y dd + z!

"#

$

%&

01

'

(

)))))))

*

+

,,,,,,,

=

xy0

z+ dd

'

(

))))))

*

+

,,,,,,

=

xy0zd+1

'

(

))))))

*

+

,,,,,,

=

1 0 0 00 1 0 00 0 0 0

0 0 1d

1

'

(

))))))

*

+

,,,,,,

xyz1

'

(

))))

*

+

,,,,

Leadingtothefollowing

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 21

• Now look at what happens to depth.

• Contrast this with previous version.

Page 22: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

Letdistancedgotoinfinity.

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 22

Formulation#1

Formulation#2

Recallformulation#2whenconsideringhowprojectionchangeswithincreasedfocallength.

XY01

Page 23: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

Moving to Formulation #3• Review, #1 origin at PRP.• Review, #2 origin at image center.• Review, #1 and #2– No useful information on the z-axis

• We now have a new goal• Project into a cannonical view volumne• A rectangular value with bounds:– U: -1 to 1, V: -1 to 1, D: 0 to 1

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 23

Page 24: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

Remember When We Started• What happens if you multiply a point in

homogeneous coordinates by a scalar?• Nothing!

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 24

xyzw

!

"

####

$

%

&&&&

=

sxsyszsw

!

"

####

$

%

&&&&

= s ⋅

xyzw

!

"

####

$

%

&&&&

Page 25: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

Scalar Multiplication Continued• Multiply a homogeneous matrix by a scalar?• Again, nothing changes.

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 25

ax + by+ cz+ dwex + fy+ gz+ hwix + jy+ kz+ lwmx + ny+oz+ pw

!

"

#####

$

%

&&&&&

=

a b c de f g hi j k lm n o p

!

"

#####

$

%

&&&&&

xyzw

!

"

####

$

%

&&&&

ax + by+ cz+ dwex + fy+ gz+ hwix + jy+ kz+ lwmx + ny+oz+ pw

!

"

#####

$

%

&&&&&

=

s ax + by+ cz+ dw( )s ex + fy+ gz+ hw( )s ix + jy+ kz+ lw( )s mx + ny+oz+ pw( )

!

"

######

$

%

&&&&&&

= s ⋅

a b c de f g hi j k lm n o p

!

"

#####

$

%

&&&&&

xyzw

!

"

####

$

%

&&&&

Page 26: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

Form#1&TextbookDerivation

10/17/17CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 26

LectureForm#1

1 0 0 00 1 0 000

00

11𝑑)

00

𝑑 0 0 00 𝑑 0 000

00

𝑑1

00

Equivalent

Page 27: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

Now introduce clipping planes• Text introduces n, the near clipping plane.• Also introduces f, the far clipping plane.• Sets what first called d to n. • The handling of z now carries information?

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 27

n 0 0 00 n 0 00 0 n+ f − fn0 0 1 0

"

#

$$$$

%

&

''''

nxny

zn+ zf − fnz

"

#

$$$$$

%

&

'''''

=

n 0 0 00 n 0 00 0 n+ f − fn0 0 1 0

"

#

$$$$

%

&

''''

xyz1

"

#

$$$$

%

&

''''

Page 28: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

VisualizeViewVolume(View1)

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 28

Page 29: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

VisualizeViewVolume(View2)

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 29

Page 30: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

ConsiderSomeKeyPoints

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 30

00𝑛

00𝑓

11𝑓1

1𝑛

Page 31: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

TheAlgebra

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 31

The1,1cornerofthenearclippingplanemapsto1,1onimageplane.The1,1corneronthefarclippingplanecomestowardtheopticalaxisandbecomesn/fontheimageplane.

Page 32: Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection •Light rays pass through the focal point. –a.k.a. Eye, principal reference point,

VisualizeFrustumChange

10/17/17 CSU CS 410, Fall 2017, © Ross Beveridge & Bruce Draper 32

Becomesarectangle(topdownview)withspacetowardthebackbeingcompressedtofitlargerareaintosamewidth.

(1,0,n)

(1,0,0)