Viewing/Projections III Week 4, Wed Jan 31 - - PowerPoint PPT Presentation

viewing projections iii week 4 wed jan 31
SMART_READER_LITE
LIVE PREVIEW

Viewing/Projections III Week 4, Wed Jan 31 - - PowerPoint PPT Presentation

University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Viewing/Projections III Week 4, Wed Jan 31 http://www.ugrad.cs.ubc.ca/~cs314/Vjan2007 News extra TA coverage in lab to answer questions Wed 2-3:30


slide-1
SLIDE 1

University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner http://www.ugrad.cs.ubc.ca/~cs314/Vjan2007

Viewing/Projections III Week 4, Wed Jan 31

slide-2
SLIDE 2

2

News

  • extra TA coverage in lab to answer questions
  • Wed 2-3:30
  • Thu 12:30-2
  • my office hours reminder (in lab also)
  • Wed (today) 11-12
  • Fri 11-12
slide-3
SLIDE 3

3

Reading for Today

  • FCG Chapter 7 Viewing
  • FCG Section 6.3.1 Windowing Transforms
  • RB rest of Chap Viewing
  • RB rest of App Homogeneous Coords
slide-4
SLIDE 4

4

Reading for Next Time

  • RB Chap Color
  • FCG Sections 3.2-3.3
  • FCG Chap 20 Color
  • FCG Chap 21 Visual Perception
slide-5
SLIDE 5

5

Review: Graphics Cameras

  • real pinhole camera: image inverted

image image plane plane eye eye point point

ν computer graphics camera: convenient equivalent

image image plane plane eye eye point point center of center of projection projection

slide-6
SLIDE 6

6

Review: Basic Perspective Projection

similar triangles similar triangles

→ = z y d y'

z d y y ⋅ = '

z z P(x,y,z) P(x,y,z) P( P(x x’ ’,y ,y’ ’, ,z z’ ’) ) z z’ ’=d =d y y

z d x x ⋅ = ' d z = '

          1 1 1 1 d

                  d d z y d z x / /

          d z z y x /

homogeneous homogeneous coords coords

slide-7
SLIDE 7

7

Review: Orthographic Cameras

  • center of projection at infinity
  • no perspective convergence
  • just throw away z values

                        =             1 1 1 1 1 z y x z y x

p p p

slide-8
SLIDE 8

8

Review: Transforming View Volumes

x z

NDCS

y

(-1,-1,-1) (1,1,1)

  • rthographic view volume
  • rthographic view volume

x z VCS y x=left y=top x=right z=-far z=-near y=bottom perspective view volume perspective view volume x=left x=right y=top y=bottom z=-near z=-far x VCS y

slide-9
SLIDE 9

9

Orthographic Derivation

  • scale, translate, reflect for new coord sys

x z

VCS

y x=left y=top x=right z=-far z=-near y=bottom x z

NDCS

y

(-1,-1,-1) (1,1,1)

slide-10
SLIDE 10

10

Orthographic Derivation

  • scale, translate, reflect for new coord sys

x z

VCS

y x=left y=top x=right z=-far z=-near y=bottom x z

NDCS

y

(-1,-1,-1) (1,1,1)

b y a y + ⋅ = ' 1 ' 1 ' − = → = = → = y bot y y top y

slide-11
SLIDE 11

11

Orthographic Derivation

  • scale, translate, reflect for new coord sys

b y a y + ⋅ = ' 1 ' 1 ' − = → = = → = y bot y y top y

bot top bot top b bot top top bot top b bot top top b b top bot top − − − = − ⋅ − − = − ⋅ − = + − = 2 ) ( 2 1 2 1

b bot a b top a + ⋅ = − + ⋅ = 1 1

bot top a top bot a top a bot a bot a top a bot a b top a b − = + − = ⋅ − − ⋅ − = − − ⋅ − − = ⋅ − ⋅ − − = ⋅ − = 2 ) ( 2 ) ( ) 1 ( 1 1 1 1 , 1

slide-12
SLIDE 12

12

Orthographic Derivation

  • scale, translate, reflect for new coord sys

x z

VCS

y x=left y=top x=right z=-far z=-near y=bottom

b y a y + ⋅ = ' 1 ' 1 ' − = → = = → = y bot y y top y bot top bot top b bot top a − + − = − = 2

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

slide-13
SLIDE 13

13

Orthographic Derivation

  • scale, translate, reflect for new coord sys

P near far near far near far bot top bot top bot top left right left right left right P                         − + − − − − + − − − + − − = 1 2 2 2 '

slide-14
SLIDE 14

14

Orthographic Derivation

  • scale, translate, reflect for new coord sys

P near far near far near far bot top bot top bot top left right left right left right P                         − + − − − − + − − − + − − = 1 2 2 2 '

slide-15
SLIDE 15

15

Orthographic Derivation

  • scale, translate, reflect for new coord sys

P near far near far near far bot top bot top bot top left right left right left right P                         − + − − − − + − − − + − − = 1 2 2 2 '

slide-16
SLIDE 16

16

Orthographic Derivation

  • scale, translate, reflect for new coord sys

P near far near far near far bot top bot top bot top left right left right left right P                         − + − − − − + − − − + − − = 1 2 2 2 '

slide-17
SLIDE 17

17

Orthographic OpenGL

glMatrixMode glMatrixMode(GL_PROJECTION); (GL_PROJECTION); glLoadIdentity glLoadIdentity(); (); glOrtho glOrtho(left,right, (left,right,bot bot,top,near,far); ,top,near,far);

slide-18
SLIDE 18

18

Demo

  • Brown applets: viewing techniques
  • parallel/orthographic cameras
  • projection cameras
  • http://www.cs.brown.edu/exploratories/freeSoftware/catalogs

/viewing_techniques.html

slide-19
SLIDE 19

19

Projections II

slide-20
SLIDE 20

20

Asymmetric Frusta

  • our formulation allows asymmetry
  • why bother?
  • z
  • z

x x Frustum Frustum

right right left left

  • z
  • z

x x Frustum Frustum z=-n z=-n z=-f z=-f

right right left left

slide-21
SLIDE 21

21

Asymmetric Frusta

  • our formulation allows asymmetry
  • why bother? binocular stereo
  • view vector not perpendicular to view plane

Right Eye Right Eye Left Eye Left Eye

slide-22
SLIDE 22

22

Simpler Formulation

  • left, right, bottom, top, near, far
  • nonintuitive
  • often overkill
  • look through window center
  • symmetric frustum
  • constraints
  • left = -right, bottom = -top
slide-23
SLIDE 23

23

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

x x Frustum Frustum z=-n z=-n z=-f z=-f α α

fovx fovx/2 /2 fovy fovy/2 /2

h h w w

slide-24
SLIDE 24

24

Perspective OpenGL

glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(left,right,bot,top,near,far);

  • r

glPerspective(fovy,aspect,near,far);

slide-25
SLIDE 25

25

Demo: Frustum vs. FOV

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

26

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

  • bject

world viewing device normalized device clipping W2V W2V V2C V2C N2D N2D C2N C2N WCS WCS

slide-27
SLIDE 27

27

Projection Normalization

  • warp perspective view volume to orthogonal

view volume

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

Z

x z=α z=d

Z

x z=0 z=d

slide-28
SLIDE 28

28

Perspective Normalization

  • perspective viewing frustum transformed to

cube

  • orthographic rendering of cube produces same

image as perspective rendering of original frustum

slide-29
SLIDE 29

29

Predistortion

slide-30
SLIDE 30

30

Demos

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

AppletIndex.html#Transformationen

slide-31
SLIDE 31

31

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

  • bject

world viewing device normalized device clipping W2V W2V V2C V2C N2D N2D C2N C2N WCS WCS

slide-32
SLIDE 32

32

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

CCS CCS NDCS NDCS

alter w alter w / w / w

VCS VCS

projection projection transformation transformation

viewing normalized device clipping

perspective perspective division division

V2C V2C C2N C2N

slide-33
SLIDE 33

33

Perspective Divide Example

  • specific example
  • assume image plane at z = -1
  • a point [x,y,z,1]T projects to [-x/z,-y/z,-z/z,1]T ≡

[x,y,z,-z]T

  • z
  • z

            1 z y x             − z z y x

slide-34
SLIDE 34

34

Perspective Divide Example

            − − − ≡             − =             ⋅             − =                           1 1 / / 1 1 1 1 1 1 z y z x z z y x z y x z y x T

alter w alter w / w / w projection projection transformation transformation perspective perspective division division

  • after homogenizing, once again w=1
slide-35
SLIDE 35

Perspective Normalization

  • matrix formulation
  • warp and homogenization both preserve

relative depth (z coordinate)

                      − ⋅ − =                             − ⋅ − − d z d d z y x z y x d d d d d α α α α α ) ( 1 1 1 1                       − − =           z d d d z y d z x z y x

p p p

α α 1 / /

2

slide-36
SLIDE 36

36

Demo

  • Brown applets: viewing techniques
  • parallel/orthographic cameras
  • projection cameras
  • http://www.cs.brown.edu/exploratories/freeSoftware/catalogs

/viewing_techniques.html

slide-37
SLIDE 37

37

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

  • bject

world viewing device normalized device clipping W2V W2V V2C V2C N2D N2D C2N C2N WCS WCS

slide-38
SLIDE 38

38

NDC to Device Transformation

  • map from NDC to pixel coordinates on display
  • NDC range is x = -1...1, y = -1...1, z = -1...1
  • typical display range: x = 0...500, y = 0...300
  • maximum is size of actual screen
  • z range max and default is (0, 1), use later for visibility

x x y y viewport viewport NDC NDC 500 300

  • 1

1 1

  • 1

x x y y

glViewport(0,0,w,h); glDepthRange(0,1); // depth = 1 by default

slide-39
SLIDE 39

39

Origin Location

  • yet more (possibly confusing) conventions
  • OpenGL origin: lower left
  • most window systems origin: upper left
  • then must reflect in y
  • when interpreting mouse position, have to flip your

y coordinates

x x y y viewport viewport NDC NDC 500 300

  • 1

1 1

  • 1

x x y y

slide-40
SLIDE 40

40

N2D Transformation

  • general formulation
  • reflect in y for upper vs. lower left origin
  • scale by width, height, depth
  • translate by width/2, height/2, depth/2
  • FCG includes additional translation for pixel centers at

(.5, .5) instead of (0,0) x x y y viewport viewport NDC NDC 500 300

  • 1

1 1

  • 1

height width x x y y

slide-41
SLIDE 41

41

N2D Transformation

                  + − + − − + =                         −                                     − − =             1 2 ) 1 ( 2 1 ) 1 ( 2 1 ) 1 ( 1 1 1 1 1 1 2 2 2 1 2 1 2 1 2 1 2 1 2 1 1

N N N N N N D D D

z depth y height x width z y x depth height width depth height width z y x

x x y y viewport viewport NDC NDC 500 300

  • 1

1 1

  • 1

height width x x y y

slide-42
SLIDE 42

42

Device vs. Screen Coordinates

  • viewport/window location wrt actual display not available

within OpenGL

  • usually don’t care
  • use relative information when handling mouse events, not

absolute coordinates

  • could get actual display height/width, window offsets from OS
  • loose use of terms: device, display, window, screen...

x x display display viewport viewport 1024 768 300 500 display height display width x offset y offset y y viewport viewport x x y y

slide-43
SLIDE 43

43

Perspective Example

tracks in VCS: left x=-1, y=-1 right x=1, y=-1 view volume left = -1, right = 1 bot = -1, top = 1 near = 1, far = 4

z=-1 z=-4 x z VCS top view

  • 1
  • 1

1 1

  • 1

NDCS (z not shown) real midpoint xmax-1 DCS (z not shown) ymax-1 x=-1 x=1

slide-44
SLIDE 44

44

Projective Rendering Pipeline

OCS - object coordinate system WCS - world coordinate system VCS - viewing coordinate system CCS - clipping coordinate system NDCS - normalized device coordinate system DCS - device coordinate system

OCS OCS WCS WCS VCS VCS CCS CCS NDCS NDCS DCS DCS

modeling modeling transformation transformation viewing viewing transformation transformation projection projection transformation transformation viewport viewport transformation transformation alter w alter w / w / w

  • bject

world viewing device normalized device clipping

perspective perspective division division glVertex3f(x,y,z) glVertex3f(x,y,z) glTranslatef glTranslatef(x,y,z) (x,y,z) glRotatef glRotatef( (th th,x,y,z) ,x,y,z) .... .... gluLookAt gluLookAt(...) (...) glFrustum glFrustum(...) (...) glutInitWindowSize glutInitWindowSize(w,h) (w,h) glViewport glViewport(x,y,a,b) (x,y,a,b)

O2W O2W W2V W2V V2C V2C N2D N2D C2N C2N

slide-45
SLIDE 45

45

Coordinate Systems

viewing (4-space, W=1) clipping (4-space parallelepiped, with COP moved backwards to infinity

normalized device (3-space parallelepiped)

device (3-space parallelipiped) projection matrix divide by w scale & translate projection matrix

slide-46
SLIDE 46

46

Perspective To NDCS Derivation

x z

NDCS

y

(-1,-1,-1) (1,1,1)

x=left x=right y=top y=bottom z=-near z=-far x

VCS

y z

slide-47
SLIDE 47

47

Perspective Derivation

simple example earlier: simple example earlier: complete: shear, scale, projection-normalization complete: shear, scale, projection-normalization

                        − =             1 1 ' ' ' ' z y x D C B F A E w z y x                         =             1 / 1 1 1 1 ' ' ' ' z y x d w z y x

slide-48
SLIDE 48

48

Perspective Derivation

earlier: earlier: complete: shear, scale, projection-normalization complete: shear, scale, projection-normalization

                        − =             1 1 ' ' ' ' z y x D C B F A E w z y x                         =             1 / 1 1 1 1 ' ' ' ' z y x d w z y x

slide-49
SLIDE 49

49

Perspective Derivation

earlier: earlier: complete: shear, scale, projection-normalization complete: shear, scale, projection-normalization

                        − =             1 1 ' ' ' ' z y x D C B F A E w z y x                         =             1 / 1 1 1 1 ' ' ' ' z y x d w z y x

slide-50
SLIDE 50

50

Perspective Derivation

                        − =             1 1 ' ' ' ' z y x D C B F A E w z y x

z w D Cz z Bz Fy y Az Ex x − = + = + = + = ' ' ' '

, ) ( 1 , 1 , 1 , 1 , ' 1 , ' ' ' , ' B near top F B z y F z z B z y F z Bz Fy w Bz Fy w Bz Fy w y Bz Fy y − − − = − − = − + − = − + = + = + = + = 1 ' / ' 1 ' / ' 1 ' / ' 1 ' / ' 1 ' / ' 1 ' / ' − = → − = = → − = − = → = = → = − = → = = → = w z far z w z near z w y bottom y w y top y w x right x w x left x B near top F − = 1

slide-51
SLIDE 51

51

Perspective Derivation

  • similarly for other 5 planes
  • 6 planes, 6 unknowns

                  − − − − + − − + − − + − 1 2 ) ( 2 2 n f fn n f n f b t b t b t n l r l r l r n

slide-52
SLIDE 52

52

Perspective Example

                  − − − − + − − + − − + − 1 2 ) ( 2 2 n f fn n f n f b t b t b t n l r l r l r n

view volume

  • left = -1, right = 1
  • bot = -1, top = 1
  • near = 1, far = 4

            − − − 1 3 / 8 3 / 5 1 1

slide-53
SLIDE 53

53

Perspective Example

            −             − − − =             − − − − 1 1 1 1 3 / 8 3 / 5 1 1 3 / 8 3 / 5 1 1

VCS VCS VCS

z z z

VCS NDCS VCS NDCS VCS NDCS

z z z y z x 3 8 3 5 / 1 / 1 + = = − =

/ w / w

slide-54
SLIDE 54

54

OpenGL Example

glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluPerspective( 45, 1.0, 0.1, 200.0 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glTranslatef( 0.0, 0.0, -5.0 ); glPushMatrix() glTranslate( 4, 4, 0 ); glutSolidTeapot(1); glPopMatrix(); glTranslate( 2, 2, 0); glutSolidTeapot(1);

OCS2 OCS2 O2W O2W VCS VCS

modeling modeling transformation transformation viewing viewing transformation transformation projection projection transformation transformation

  • bject

world viewing W2V W2V V2C V2C WCS WCS

  • transformations that

are applied first are specified last

OCS1 OCS1 WCS WCS VCS VCS W2O W2O W2O W2O CCS CCS clipping CCS CCS OCS OCS