Lecture 16: Projection and Camerascs410/yr2017fa/more_progress/... · Perspective Projection...

Post on 29-Mar-2020

2 views 0 download

transcript

Lecture 16:Projection and Cameras

October 17, 2017

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:

Perspective…

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

OrthographicProjection

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

Ifnotforthefog,youcouldseeforever…

andnothingeverwouldlooksmaller.

Orthographic/PerspectiveThinkAboutRays

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

IsPerspectiveAlwaysBetter?

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

No!Technicalprograms,includingforexampleMaple,oftenfavororthographicprojection.

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)

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

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

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

PinholeProjectionFliptheBearintheBox

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

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

HumanEye- 4yearoldview

DrawingbyBryceBeveridgein2006

RoomObscura

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

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

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

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

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

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

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

PerspectiveProjectionForm#2

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

P

Pyv

Od Pz

𝑣𝑑 =

𝑃,𝑑 + 𝑃.

𝑣 = 𝑃,𝑑

𝑑 + 𝑃.

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.

Letdistancedgotoinfinity.

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

Formulation#1

Formulation#2

Recallformulation#2whenconsideringhowprojectionchangeswithincreasedfocallength.

XY01

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

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

!

"

####

$

%

&&&&

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

!

"

####

$

%

&&&&

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

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

"

#

$$$$

%

&

''''

VisualizeViewVolume(View1)

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

VisualizeViewVolume(View2)

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

ConsiderSomeKeyPoints

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

00𝑛

00𝑓

11𝑓1

1𝑛

TheAlgebra

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

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

VisualizeFrustumChange

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

Becomesarectangle(topdownview)withspacetowardthebackbeingcompressedtofitlargerareaintosamewidth.

(1,0,n)

(1,0,0)