coordinate systems - students.cs.ubc.ca

5
University of British Columbia CPSC 314 Computer Graphics Sep-Dec 2009 Tamara Munzner (guest lecturer) Viewing/Projections Week 5, Wed Oct 6 2 News assignment 1 posted 3 Viewing (Review?) 4 Using Transformations three ways modelling transforms place objects within scene (shared world) affine transformations viewing transforms place camera rigid body transformations: rotate, translate projection transforms change type of camera projective transformation 5 Rendering Pipeline Scene graph Object geometry Modelling Transforms Viewing Transform Projection Transform 6 Scene graph Object geometry Modelling Transforms Viewing Transform Projection Transform Rendering Pipeline result all vertices of scene in shared 3D world coordinate system 7 Scene graph Object geometry Modelling Transforms Viewing Transform Projection Transform Rendering Pipeline result scene vertices in 3D view (camera) coordinate system 8 Scene graph Object geometry Modelling Transforms Viewing Transform Projection Transform Rendering Pipeline result 2D screen coordinates of clipped vertices 9 Viewing and Projection need to get from 3D world to 2D image projection: geometric abstraction what eyes or cameras do two pieces viewing transform: where is the camera, what is it pointing at? perspective transform: 3D to 2D flatten to image 10 Rendering Pipeline Geometry Database Model/View Transform. Lighting Perspective Transform. Clipping Scan Conversion Depth Test Texturing Blending Frame- buffer 11 Rendering Pipeline Geometry Database Model/View Transform. Lighting Perspective Transform. Clipping Scan Conversion Depth Test Texturing Blending Frame- buffer 12 OpenGL Transformation Storage modeling and viewing stored together possible because no intervening operations perspective stored in separate matrix specify which matrix is target of operations common practice: return to default modelview mode after doing projection operations glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_PROJECTION); 13 Coordinate Systems result of a transformation names convenience mouse: leg, head, tail standard conventions in graphics pipeline object/modelling world camera/viewing/eye screen/window raster/device 14 Projective Rendering Pipeline OCS - object/model coordinate system WCS - world coordinate system VCS - viewing/camera/eye coordinate system CCS - clipping coordinate system NDCS - normalized device coordinate system DCS - device/display/screen coordinate system OCS OCS O2W O2W VCS VCS CCS CCS NDCS NDCS DCS DCS modeling modeling transformation transformation viewing viewing transformation transformation projection projection transformation transformation viewport viewport transformation transformation perspective perspective divide divide object world viewing device normalized device clipping W2V W2V V2C V2C N2D N2D C2N C2N WCS WCS 15 Projections I 16 Pinhole Camera ingredients box, film, hole punch result picture www.kodak.com www.pinhole.org www.debevec.org/Pinhole

Upload: others

Post on 26-May-2022

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Coordinate Systems - students.cs.ubc.ca

University of British ColumbiaCPSC 314 Computer Graphics

Sep-Dec 2009

Tamara Munzner(guest lecturer)

Viewing/Projections

Week 5, Wed Oct 6

2

News• assignment 1 posted

3

Viewing(Review?)

4

Using Transformations• three ways

• modelling transforms• place objects within scene (shared world)• affine transformations

• viewing transforms• place camera• rigid body transformations: rotate, translate

• projection transforms• change type of camera• projective transformation

5

Rendering Pipeline

Scene graphObject geometry

ModellingTransforms

ViewingTransform

ProjectionTransform

6

Scene graphObject geometry

ModellingTransforms

ViewingTransform

ProjectionTransform

Rendering Pipeline

• result• all vertices of scene in shared

3D world coordinate system

7

Scene graphObject geometry

ModellingTransforms

ViewingTransform

ProjectionTransform

Rendering Pipeline

• result• scene vertices in 3D view

(camera) coordinate system

8

Scene graphObject geometry

ModellingTransforms

ViewingTransform

ProjectionTransform

Rendering Pipeline

• result• 2D screen coordinates of

clipped vertices

9

Viewing and Projection

• need to get from 3D world to 2D image• projection: geometric abstraction

• what eyes or cameras do• two pieces

• viewing transform:• where is the camera, what is it pointing at?

• perspective transform: 3D to 2D• flatten to image

10

Rendering Pipeline

GeometryDatabase

Model/ViewTransform. Lighting Perspective

Transform. Clipping

ScanConversion

DepthTestTexturing Blending

Frame-buffer

11

Rendering Pipeline

GeometryDatabase

Model/ViewTransform. Lighting Perspective

Transform. Clipping

ScanConversion

DepthTestTexturing Blending

Frame-buffer

12

OpenGL Transformation Storage• modeling and viewing stored together

• possible because no intervening operations• perspective stored in separate matrix

• specify which matrix is target of operations• common practice: return to default modelview

mode after doing projection operations glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_PROJECTION);

13

Coordinate Systems• result of a transformation• names

• convenience• mouse: leg, head, tail

• standard conventions in graphics pipeline• object/modelling• world• camera/viewing/eye• screen/window• raster/device

14

Projective Rendering Pipeline

OCS - object/model coordinate system

WCS - world coordinate system

VCS - viewing/camera/eye coordinatesystem

CCS - clipping coordinate system

NDCS - normalized device coordinatesystem

DCS - device/display/screen coordinatesystem

OCSOCS O2WO2W VCSVCS

CCSCCS

NDCSNDCS

DCSDCS

modelingmodelingtransformationtransformation

viewingviewingtransformationtransformation

projectionprojectiontransformationtransformation

viewportviewporttransformationtransformation

perspectiveperspectivedividedivide

object world viewing

device

normalizeddevice

clipping

W2VW2V V2CV2C

N2DN2D

C2NC2N

WCSWCS

15

Projections I

16

Pinhole Camera

• ingredients• box, film, hole punch

• result• picture www.kodak.com

www.pinhole.org

www.debevec.org/Pinhole

Page 2: Coordinate Systems - students.cs.ubc.ca

17

Pinhole Camera

• theoretical perfect pinhole• light shining through tiny hole into dark space

yields upside-down picture

film plane

perfectpinhole

one rayof projection

18

Pinhole Camera

• non-zero sized hole• blur: rays hit multiple points on film plane

film plane

actualpinhole

multiple raysof projection

19

Real Cameras• pinhole camera has small aperture (lens

opening)• minimize blur

• problem: hard to get enough light toexpose the film

• solution: lens• permits larger apertures• permits changing distance to film

plane without actually moving it• cost: limited depth of field where

image is in focus

apertureaperture

lenslensdepthdepth

ofoffieldfield

http://en.wikipedia.org/wiki/Image:DOF-ShallowDepthofField.jpg20

Graphics Cameras

• real pinhole camera: image inverted

imageimageplaneplane

eyeeye point point

computer graphics camera: convenient equivalent

imageimageplaneplane

eyeeye point point

center ofcenter ofprojectionprojection

21

General Projection

• image plane need not be perpendicular to view plane

imageimageplaneplane

eyeeye point point

imageimageplaneplane

eyeeye point point

22

Perspective Projection

• our camera must model perspective

23

Perspective Projection

• our camera must model perspective

24

Projective Transformations

• planar geometric projections• planar: onto a plane• geometric: using straight lines• projections: 3D -> 2D

• aka projective mappings

25

Projective Transformations• properties• lines mapped to lines and triangles to triangles• parallel lines do NOT remain parallel

• e.g. rails vanishing at infinity

• affine combinations are NOT preserved• e.g. center of a line does not map to center of

projected line (perspective foreshortening)

26

Perspective Projection

• project all geometry• through common center of projection (eye point)• onto an image plane

xxzz xxzz

yy

xx

-z-z

27

Perspective Projection

how tall shouldthis bunny be?

projectionplane

center of projection(eye point)

28

Basic Perspective Projection

similar trianglessimilar triangles

zz

P(x,y,z)P(x,y,z)

P(P(xx’’,,yy’’,,zz’’))

zz’’==dd

yy

• nonuniform foreshortening• not affine

butbut!

y'

d=y

z" y '=

y # d

z

!

x'

d=x

z" x '=

x # d

z

!

z'= d

29

Perspective Projection• desired result for a point [x, y, z, 1]T projected

onto the view plane:

• what could a matrix look like to do this?

dzdz

y

z

dyy

dz

x

z

dxx

z

y

d

y

z

x

d

x

==!

==!

=

==

',','

',

'

30

Simple Perspective Projection Matrix

!!!!!!!

"

#

$$$$$$$

%

&

d

dz

y

dz

x

/

/

31

Simple Perspective Projection Matrix

!!!!!!!

"

#

$$$$$$$

%

&

d

dz

y

dz

x

/

/ is homogenized version of

where w = z/d!!!!

"

#

$$$$

%

&

dz

z

y

x

/

32

Simple Perspective Projection Matrix

!!!!

"

#

$$$$

%

&

!!!!

"

#

$$$$

%

&

=

!!!!

"

#

$$$$

%

&

10100

0100

0010

0001

/

z

y

x

ddz

z

y

x!!!!!!!

"

#

$$$$$$$

%

&

d

dz

y

dz

x

/

/ is homogenized version of

where w = z/d!!!!

"

#

$$$$

%

&

dz

z

y

x

/

Page 3: Coordinate Systems - students.cs.ubc.ca

33

Perspective Projection

• expressible with 4x4 homogeneous matrix• use previously untouched bottom row

• perspective projection is irreversible• many 3D points can be mapped to same

(x, y, d) on the projection plane• no way to retrieve the unique z values

34

Moving COP to Infinity

• as COP moves away, lines approach parallel• when COP at infinity, orthographic view

35

Orthographic Camera Projection• camera’s back plane

parallel to lens• infinite focal length• no perspective

convergence

• just throw away z values

!!!

"

#

$$$

%

&

=

!!!

"

#

$$$

%

&

0

y

x

z

y

x

p

p

p

!!!!

"

#

$$$$

%

&

!!!!

"

#

$$$$

%

&

=

!!!!

"

#

$$$$

%

&

11000

0000

0010

0001

1

z

y

x

z

y

x

p

p

p

36

Perspective to Orthographic• transformation of space• center of projection moves to infinity• view volume transformed

• from frustum (truncated pyramid) toparallelepiped (box)

-z-z

xx

-z-z

xx

FrustumFrustum ParallelepipedParallelepiped

37

View Volumes

• specifies field-of-view, used for clipping• restricts domain of z stored for visibility test

z

perspective view volumeperspective view volume orthographic view volumeorthographic view volume

x=left

x=right

y=top

y=bottom z=-near z=-farxVCS x

z

VCS

yy

x=lefty=top

x=right

z=-farz=-neary=bottom

38

Demo: Perspective and Ortho Volumes

• Nate Robins tutorial (projection)• http://www.xmission.com/~nate/tutors.html

39

Canonical View Volumes• standardized viewing volume representation

perspective orthographic orthogonal parallel

x or y

-z

1

-1

-1frontplane

backplane

x or y

-zfrontplane

backplane

x or y = +/- z

40

Why Canonical View Volumes?

• permits standardization• clipping

• easier to determine if an arbitrary point isenclosed in volume with canonical viewvolume vs. clipping to six arbitrary planes

• rendering• projection and rasterization algorithms can be

reused

41

Normalized Device Coordinates

• convention• viewing frustum mapped to specific

parallelepiped• Normalized Device Coordinates (NDC)• same as clipping coords

• only objects inside the parallelepiped getrendered

• which parallelepiped?• depends on rendering system

42

Normalized Device Coordinates

left/right x =+/- 1, top/bottom y =+/- 1, near/far z =+/- 1

-z-z

xx

FrustumFrustum

z=-nz=-n z=-fz=-f

rightright

leftleft zz

xx

x= -1x= -1z=1z=1

x=1x=1

Camera coordinatesCamera coordinates NDCNDC

z= -1z= -1

43

Understanding Z

• z axis flip changes coord system handedness• RHS before projection (eye/view coords)• LHS after projection (clip, norm device coords)

x

z

VCS

yx=left

y=top

x=right

z=-farz=-neary=bottom

x

z

NDCS

y

(-1,-1,-1)

(1,1,1)

44

Understanding Znear, far always positive in OpenGL calls

glOrthoglOrtho(left,right,(left,right,botbot,top,near,far);,top,near,far); glFrustumglFrustum(left,right,(left,right,botbot,top,near,far);,top,near,far); glPerspectiveglPerspective((fovyfovy,aspect,near,far);,aspect,near,far);

orthographic view volumeorthographic view volume

x

z

VCS

yx=left

y=top

x=right

z=-farz=-neary=bottom

perspective view volumeperspective view volume

x=left

x=right

y=top

y=bottom z=-near z=-farxVCS

y

45

Understanding Z

• why near and far plane?• near plane:

• avoid singularity (division by zero, or verysmall numbers)

• far plane:• store depth in fixed-point representation

(integer), thus have to have fixed range ofvalues (0…1)

• avoid/reduce numerical precision artifacts fordistant objects

46

Orthographic Derivation

• scale, translate, reflect for new coord sys

x

z

VCS

yx=left

y=top

x=right

z=-farz=-neary=bottom

x

z

NDCS

y

(-1,-1,-1)

(1,1,1)

47

Orthographic Derivation

• scale, translate, reflect for new coord sys

x

z

VCS

yx=left

y=top

x=right

z=-farz=-neary=bottom

x

z

NDCS

y

(-1,-1,-1)

(1,1,1)

byay +!='1'

1'

!="=

="=

yboty

ytopy

48

Orthographic Derivation

• scale, translate, reflect for new coord sys

byay +!='1'

1'

!="=

="=

yboty

ytopy

bottop

bottopb

bottop

topbottopb

bottop

topb

btopbottop

!

!!=

!

"!!=

!

"!=

+!

=

2)(

21

21

bbota

btopa

+!="

+!=

1

1

bottopa

topbota

topabota

botatopa

botabtopab

!=

+!=

"!!"!=!!

"!!="!

"!!="!=

2

)(2

)()1(1

11

1,1

Page 4: Coordinate Systems - students.cs.ubc.ca

49

Orthographic Derivation

• scale, translate, reflect for new coord sys

x

z

VCS

yx=left

y=top

x=right

z=-farz=-neary=bottom

byay +!='1'

1'

!="=

="=

yboty

ytopy

bottop

bottopb

bottopa

!

+!=

!=

2

same idea for right/left, far/near same idea for right/left, far/near 50

Orthographic Derivation

• scale, translate, reflect for new coord sys

P

nearfar

nearfar

nearfar

bottop

bottop

bottop

leftright

leftright

leftright

P

!!!!!!!!!!

"

#

$$$$$$$$$$

%

&

'

+'

'

'

'

+'

'

'

+'

'

=

1000

200

02

0

002

'

51

Orthographic Derivation

• scale, translate, reflect for new coord sys

P

nearfar

nearfar

nearfar

bottop

bottop

bottop

leftright

leftright

leftright

P

!!!!!!!!!!

"

#

$$$$$$$$$$

%

&

'

+'

'

'

'

+'

'

'

+'

'

=

1000

200

02

0

002

'

52

Orthographic Derivation

• scale, translate, reflect for new coord sys

P

nearfar

nearfar

nearfar

bottop

bottop

bottop

leftright

leftright

leftright

P

!!!!!!!!!!

"

#

$$$$$$$$$$

%

&

'

+'

'

'

'

+'

'

'

+'

'

=

1000

200

02

0

002

'

53

Orthographic Derivation

• scale, translate, reflect for new coord sys

P

nearfar

nearfar

nearfar

bottop

bottop

bottop

leftright

leftright

leftright

P

!!!!!!!!!!

"

#

$$$$$$$$$$

%

&

'

+'

'

'

'

+'

'

'

+'

'

=

1000

200

02

0

002

'

54

Orthographic OpenGL

glMatrixModeglMatrixMode(GL_PROJECTION);(GL_PROJECTION);glLoadIdentityglLoadIdentity();();glOrthoglOrtho(left,right,(left,right,botbot,top,near,far);,top,near,far);

55

Demo

• Brown applets: viewing techniques• parallel/orthographic camera transformations

• http://www.cs.brown.edu/exploratories/freeSoftware/catalogs/viewing_techniques.html

56

Projections II

57

Asymmetric Frusta

• our formulation allows asymmetry• why bother?

-z-z

xx

FrustumFrustumrightright

leftleft-z-z

xx

FrustumFrustum

z=-nz=-n z=-fz=-f

rightright

leftleft

58

Asymmetric Frusta

• our formulation allows asymmetry• why bother? binocular stereo

• view vector not perpendicular to view plane

Right EyeRight Eye

Left EyeLeft Eye

59

Simpler Formulation

• left, right, bottom, top, near, far• nonintuitive• often overkill

• look through window center• symmetric frustum

• constraints• left = -right, bottom = -top

60

Field-of-View Formulation

• FOV in one direction + aspect ratio (w/h)• determines FOV in other direction• also set near, far (reasonably intuitive)

-z-z

xx

FrustumFrustum

z=-nz=-n z=-fz=-f

ααfovx/2fovx/2

fovy/2fovy/2hh

ww

61

Perspective OpenGL

glMatrixMode(GL_PROJECTION);glLoadIdentity();

glFrustum(left,right,bot,top,near,far); orglPerspective(fovy,aspect,near,far);

62

Demo: Frustum vs. FOV

• Nate Robins tutorial (take 2):• http://www.xmission.com/~nate/tutors.html

63

Projective Rendering Pipeline

OCS - object/model coordinate system

WCS - world coordinate system

VCS - viewing/camera/eye coordinatesystem

CCS - clipping coordinate system

NDCS - normalized device coordinatesystem

DCS - device/display/screen coordinatesystem

OCSOCS O2WO2W VCSVCS

CCSCCS

NDCSNDCS

DCSDCS

modelingmodelingtransformationtransformation

viewingviewingtransformationtransformation

projectionprojectiontransformationtransformation

viewportviewporttransformationtransformation

perspectiveperspectivedividedivide

object world viewing

device

normalizeddevice

clipping

W2VW2V V2CV2C

N2DN2D

C2NC2N

WCSWCS

64

Projection Normalization

• warp perspective view volume to orthogonalview volume

• render all scenes with orthographic projection!• aka perspective warp

x

z=α z=d

x

z=0 z=d

Page 5: Coordinate Systems - students.cs.ubc.ca

65

Perspective Normalization

• perspective viewing frustum transformed tocube

• orthographic rendering of cube produces sameimage as perspective rendering of originalfrustum

66

Predistortion

67

Demos

• Tuebingen applets from Frank Hanisch• http://www.gris.uni-tuebingen.de/projects/grdev/doc/html/etc/

AppletIndex.html#Transformationen

68

Projective Rendering Pipeline

OCS - object/model coordinate system

WCS - world coordinate system

VCS - viewing/camera/eye coordinatesystem

CCS - clipping coordinate system

NDCS - normalized device coordinatesystem

DCS - device/display/screen coordinatesystem

OCSOCS O2WO2W VCSVCS

CCSCCS

NDCSNDCS

DCSDCS

modelingmodelingtransformationtransformation

viewingviewingtransformationtransformation

projectionprojectiontransformationtransformation

viewportviewporttransformationtransformation

perspectiveperspectivedividedivide

object world viewing

device

normalizeddevice

clipping

W2VW2V V2CV2C

N2DN2D

C2NC2N

WCSWCS

69

Separate Warp From Homogenization

• warp requires only standard matrix multiply• distort such that orthographic projection of distorted

objects is desired persp projection• w is changed

• clip after warp, before divide• division by w: homogenization

CCSCCSNDCSNDCS

alter walter w / w/ w

VCSVCSprojectionprojection

transformationtransformation

viewing normalizeddevice

clipping

perspectiveperspectivedivisiondivision

V2CV2C C2NC2N