CS488 Implementation of projections Luc R ENAMBOT 1 3D Graphics - - PowerPoint PPT Presentation

cs488
SMART_READER_LITE
LIVE PREVIEW

CS488 Implementation of projections Luc R ENAMBOT 1 3D Graphics - - PowerPoint PPT Presentation

CS488 Implementation of projections Luc R ENAMBOT 1 3D Graphics Convert a set of polygons in a 3D world into an image on a 2D screen After theoretical view Implementation 2 Transformations P(X,Y,Z) 3D Object Coordinates Modeling


slide-1
SLIDE 1

CS488

Implementation of projections

Luc RENAMBOT

1

slide-2
SLIDE 2

3D Graphics

  • Convert a set of polygons in a 3D

world into an image on a 2D screen

  • After theoretical view
  • Implementation

2

slide-3
SLIDE 3

Transformations

3

P(X,Y,Z) Modeling Transformation Viewing Transformation Projection Transformation Window-to-Viewport Transformation P’(X’,Y’)

3D Object Coordinates 3D World Coordinates 3D Camera Coordinates 2D Screen Coordinates 2D Image Coordinates

slide-4
SLIDE 4

3D Rendering Pipeline

4

3D Geometric Primitives Modeling Transformation Lighting Viewing Transformation Projection Transformation Clipping Scan Conversion Image

Transform into 3D world coordinate system Illuminate according to lighting and reflectance Transform into 3D camera coordinate system Transform into 2D camera coordinate system Clip primitives outside camera’s view Draw pixels (including texturing, hidden surface, etc.)

slide-5
SLIDE 5

Orthographic Projection

5

slide-6
SLIDE 6

Perspective Projection

6

F B

slide-7
SLIDE 7

Viewing Reference Coordinate system

7

slide-8
SLIDE 8

Projection Reference Point

8

Projection Reference Point (PRP) Center of Window (CW) View Reference Point (VRP) View-Plane Normal (VPN)

slide-9
SLIDE 9

Implementation

  • Lots of Matrices
  • Orthographic matrix
  • Perspective matrix
  • 3D World → Normalize to the canonical

view volume → Clip against canonical view volume → Project onto projection plane → Translate into viewport

9

slide-10
SLIDE 10

Canonical View Volumes

  • Used because easy to clip against and

calculate intersections

  • Strategies: convert view volumes into “easy”

canonical view volumes

  • Transformations called Npar and Nper

10

slide-11
SLIDE 11

Parallel Canonical Volume

  • Defined by 6 planes
  • X = -1 and X = 1
  • Y = -1 and

Y = 1

  • Z = 0 and Z = -1

11

X or Y

  • Z

1

  • 1
  • 1

Front Plane Back Plane

slide-12
SLIDE 12

Perspective Canonical Volume

  • Defined by 6 planes
  • X = Z and X = -Z
  • Y = Z and

Y = -Z

  • Z = Zmin and Z = -1

12

X or Y

  • Z

1

  • 1
  • 1

Front Plane Back Plane

slide-13
SLIDE 13

Normalizing Transformation

  • Nper: normalizing transformation for

perspective projection: it transforms the world-coordinate positions such that the view volume becomes the perspective projection canonical view volume

  • Npar: normalizing transformation for parallel

projection in order to transform world- coordinate positions such that the view volume is transformed into the canonical view volume

13

slide-14
SLIDE 14

Implementation

  • Two methods
  • Main difference being whether clipping is

performed in world coordinates or homogeneous coordinates

  • See p.279 in white book
  • The second way is more general

14

slide-15
SLIDE 15

Method 1

  • Clipping is performed in world coordinates
  • 1. Extend 3D coordinates to homogeneous coordinates
  • 2. Apply Npar or Nper to normalize the homogeneous

coordinates

  • 3. Divide by W to go back to 3D coordinates
  • 4. Clip in 3D against the appropriate view volume
  • 5. Extend 3D coordinates to homogeneous coordinates
  • 6. Perform projection using either Mort or Mper (with d=1)
  • 7. Translate and Scale into device coordinates
  • 8. Divide by W to go to 2D coordinates

15

slide-16
SLIDE 16

Method 2

  • Clipping is performed in homogeneous coordinates
  • 1. Extend 3D coordinates to homogeneous

coordinates

  • 2. Apply Npar or Nper' to normalize the

homogeneous coordinates

  • 3. Clip in homogeneous coordinates
  • 4. Translate and Scale into device coordinates
  • 5. Divide by W to go to 2D coordinates

16

slide-17
SLIDE 17

Step 1

  • Extend 3D coordinates to

homogeneous coordinates

  • This is easy: we just take (x, y, z) for every

point and add a W=1 (x, y, z, 1)

  • As we did previously, we are going to use

homogeneous coordinates to make it easy to compose multiple matrices

17

slide-18
SLIDE 18

Step 2

  • Normalizing the homogeneous

coordinates

  • We normalize the homogeneous coordinates

so we can clip against the canonical view volumes

  • Manipulate the world so that the parts of the

world that are in the existing view volume are in the new canonical view volume

  • We want to create Npar and Nper, matrices to

perform this normalization

18

slide-19
SLIDE 19

Computing Npar

  • 1. Translate

VRP to the origin

  • 2. Rotate

VRC so n-axis (VPN) is z-axis, u-axis is x-axis, and v-axis is y-axis

  • 3. Shear so direction of projection is parallel to

z-axis (only needed for oblique parallel projections - that is where the direction of projection is not normal to the view plane)

  • 4. Translate and Scale into canonical view

volume

19

slide-20
SLIDE 20

Step 2.1

  • Translate

VRP to the origin

➡T(-VRP)

20

slide-21
SLIDE 21

Step 2.2

  • Rotate

VRC

  • Rz =

VPN / || VPN ||

  • so Rz is a unit length vector in the direction of the

VPN

  • Rx =

VUP x Rz / || VUP x Rz ||

  • so Rx is a unit length vector perpendicular to Rz and

Vup

  • Ry = Rz x Rx
  • so Ry is a unit length vector perpendicular to the plane

formed by Rz and Rx

21

slide-22
SLIDE 22

Rotation Matrix

  • Where rab is ath element of Rb
  • VPN now rotated into Z axis, U into X

axis and V into Y axis

  • PRP now in world coordinates

22

Rx =     r1x r2x r3x r1y r2y r3y r1z r2z r3z 1    

slide-23
SLIDE 23

Step 2.3

  • Shear so direction of projection is parallel

to z-axis (only needed for oblique parallel projections - that is where the direction of projection is not normal to the view plane) makes DOP coincident with the z axis

  • Direction of projection
  • DOP is now CW - PRP

23

slide-24
SLIDE 24

Step 2.3 (cont)

  • DOP = CW - PRP

24

    DOPx DOPy DOPx     =     (umax + umin)/2 (vmax + vmin)/2 1     −     PRPu PRPv PRPn 1    

  • We need DOP as:

    DOP ′

z

1    

  • Shear matrix

    1 −DOPx/DOPz 1 −DOPy/DOPz 1 1    

slide-25
SLIDE 25

Step 2.4

  • Translate and Scale the sheared volume

into canonical view volume

25

Tpar = T   −(umax + umin)/2 −(vmax + vmin)/2 −F   Spar = S   2/(umax − umin) 2/(vmax − vmin) 1/(F − B)  

slide-26
SLIDE 26

Computing Npar

  • Npar = Spar * Tpar * SHpar * R * T(-VRP)
  • Scaling to fit volume
  • Translation into volume
  • Shear transformation
  • Rotation of axis
  • Translation to origin

26

slide-27
SLIDE 27

Computing Nper

  • 1. Translate

VRP to the origin

  • 2. Rotate

VRC so n-axis (VPN) is z-axis, u-axis is x-axis, and v-axis is y-axis

  • 3. Translate so that the center of projection

(PRP) is at the origin

  • 4. Shear so the center line of the view volume is

the z-axis

  • 5. Scale into canonical view volume

27

slide-28
SLIDE 28

Step 2.1

  • Translate

VRP to the origin is the same as step 2.1 for Npar

  • T(-VRP)

28

slide-29
SLIDE 29

Step 2.2

  • Rotate

VRC so n-axis (VPN) is z-axis, u- axis is x-axis, and v-axis is y-axis is the same as step 2.2 for Npar

29

slide-30
SLIDE 30

Step 2.3

  • Translate PRP to the origin
  • T(-PRP)

30

slide-31
SLIDE 31

Step 2.4

  • Shear so the center line of the view

volume is the z-axis

  • The same as step 2.3 for Npar
  • The PRP is now at the origin but the CW

may not be on the Z axis

  • If it isn't then we need to shear to put the

CW onto the Z axis

31

slide-32
SLIDE 32

Step 2.5

  • Scale into the canonical view volume
  • Up until step 2.3, the

VRP was at the origin, afterwards it may not be

  • The new location of the

VRP is:

32

V RP ′ = SHpar ∗ T(−PRP) ∗     1    

  • So

Sper =   2V RP ′

z/[(umax − umin)(V RP ′ z + B)]

2V RP ′

z/[(vmax − vmin)(V RP ′ z + B)]

−1/(V RP ′

z + B))

 

slide-33
SLIDE 33

Computing Nper

  • So finally, we have

Nper = Sper * SHpar * T(-PRP) * R * T(-VRP)

  • Scaling to canonical view
  • Shear to center the line of view of the volume
  • Translate the center of projection to the origin
  • Rotation of

VRC

  • Translate

VRP to origin

33

slide-34
SLIDE 34

Comments

  • Npar and Nper matrices depends only on

the camera parameters

  • If the camera parameters do not change,

these matrices do not need to be recomputed

  • Conversely if there is constant change in the

camera, these matrices will need to be constantly recreated

34

slide-35
SLIDE 35

Comments

  • Now, here is where the 2 methods diverge with method
  • ne going back to 3D coordinates to clip while method

2 remains in homogeneous coordinates.

  • The choice is based on whether W is ensured to be > 0
  • If so method 1 can be used, otherwise method 2 must

be used.

  • With what we have discussed in this class so far, W will

be > 0, and W should remain 1 through the normalization step

  • You get W < 0 when you do fancy stuff like b-splines

35

slide-36
SLIDE 36

Step 3

  • Divide by W to go back to 3D coordinates
  • We just take (x, y, z, W) and divide all the

terms by W to get (x/W, y/W, z/W, 1)

  • We ignore the 1 to go back to 3D

coordinates

  • We probably do not even need to divide by

W as it should still be 1

36

slide-37
SLIDE 37

Step 4

  • Clip in 3D against the appropriate view

volume

  • At this point we want to keep everything

that is inside the canonical view volume, and clip away everything that is outside the canonical view volume

  • Using Cohen-Sutherland algorithm we used in

2D and extend it to 3D, except now there are 6 bits instead of four

37

slide-38
SLIDE 38

Clipping in 3D

  • For the parallel case the 6 bits are:
  • point is above view volume: y > 1
  • point is below view volume: y < -1
  • point is right of view volume: x > 1
  • point is left view volume: x < -1
  • point is behind view volume: Z < -1
  • point is in front of view volume: z > 0

38

slide-39
SLIDE 39

Clipping in 3D

  • For the perspective case the 6 bits are:
  • point is above view volume: y > -z
  • point is below view volume: y < z
  • point is right of view volume: x > -z
  • point is left view volume: x < z
  • point is behind view volume: z < -1
  • point is in front of view volume: z > zmin

39

Equations in book, page 273

slide-40
SLIDE 40

Step 5

  • Back to homogeneous coordinates again
  • This is easy we just take (x, y, z) and add a

W=1

➡(x, y, z, 1)

40

slide-41
SLIDE 41

Step 6

  • Perform Projection
  • Parallel projection
  • Perspective projection

41

slide-42
SLIDE 42

Parallel Projection

  • The projection plane is normal to the z-axis

at z=0.

  • Xp = X and

Yp = Y and Z is set to 0 to do the projection onto the projection plane.

  • Points that are further away in Z still retain

the same X and Y values

  • those values do not change with distance

42

slide-43
SLIDE 43

Parallel Projection

  • Multiplying the Mort matrix and the vector

(X, Y, Z, 1) holding a given point, gives the resulting vector (X, Y, 0, 1)

43

Mort =     1 1 1    

slide-44
SLIDE 44

Perspective Projection

  • Multiplying the Mper matrix and the vector

(X, Y, Z, 1) holding a given point, gives the resulting vector (X, Y, Z, -Z)

44

Mort =     1 1 1 −1    

  • The projected X and

Y values do depend on the Z value. Objects that are further away should appear smaller than similar objects that are closer

slide-45
SLIDE 45

Step 7

  • Translate and Scale into device coordinates
  • All of the points that were in the original view

volume are still within the following range:

  • -1 <= X <= 1
  • -1 <=

Y <= 1

  • -1 <= Z <= 0

45

slide-46
SLIDE 46

Step 7

  • Mapping points into the viewport by moving to

device coordinates

  • Steps:
  • Translate view volume so its corner (-1, -1, -1)

is at the origin

  • Scale to match the size of the 3D viewport

(which keeps the corner at the origin)

  • Translate the origin to the lower left hand

corner of the viewport

46

slide-47
SLIDE 47

Step 7

  • Matrix: view volume to 3D viewport

47

Mvv3dv = T   Xviewmin Y viewmin Zviewmin   ∗ Svv3dv ∗ T   1 1 1  

Svv3dv = S   (Xviewmax − Xviewmin)/2 (Y viewmax − Y viewmin)/2 (Zviewmax − Zviewmin)/1  

  • With
  • Independent of the camera settings
  • Updated only if viewport changes
slide-48
SLIDE 48

Step 8

  • Divide by W to go from homogeneous to 2D

coordinates

  • Just take (x, y, z, W) and divide all the terms by W to

get (x/W, y/W, z/W, 1) and then we ignore the 1 to go back to 3D coordinates

  • Parallel
  • 3D coordinates with Z=0 (proj plane)
  • Perspective: W=-Z
  • So get point (-X/Z, -Y/Z, -1)
  • Z=-1 Plane

48

slide-49
SLIDE 49

Method 2

  • There is still the second method where we

clip in homogeneous coordinates to be more general

  • The normalization step (step 2) is slightly

different here, as both the parallel and perspective projections need to be normalized into the canonical parallel perspective view volume.

49

slide-50
SLIDE 50

Clipping

  • Npar above does this for the parallel case.
  • Nper' for the perspective case is M * Nper.
  • Nper is the normalization given in step 2.

This is the same normalization that needed to be done in step 8 of method 1 before we could convert to 2D coordinates.

50

slide-51
SLIDE 51

Clipping (step 3)

  • Now in both the parallel and perspective

cases the clipping routine is the same.

  • Again we have 6 planes to clip against:
  • X= -W, X= W,

Y= -W, Y= W, Z= -W, Z=0

51

M =     1 1 1/(1 + Zmin) z/(1 + Zmin −1    

slide-52
SLIDE 52

Step 4

  • Translate and Scale into device coordinates
  • translate view volume so its corner (-1, -1, -1) is at the
  • rigin
  • scale to match the size of the 3D viewport (which keeps

the corner at the origin)

  • translate the origin to the lower left hand corner of the

viewport

  • Mvv3dv = T(Xviewmin,

Yviewmin, Zviewmin) * Svv3dv * T(1, 1, 1)

  • Svv3dv = S( (Xviewmax-Xviewmin)/2, (Yviewmax-Yviewmin)/

2, (Zviewmax-Zview.min)/1 )

52

slide-53
SLIDE 53

Step 5

  • Divide by W to go from homogeneous to

2D coordinates

  • In the perspective projection case, dividing

by W will affect the transformation of the points

53

slide-54
SLIDE 54

Next Time

  • Vision and Light

54

slide-55
SLIDE 55

Coming...

  • The Midterm end of the month
  • I will be supplying the paper, so all you need

to bring is a few writing utensils

  • The exam will be closed book, closed note,

closed neighbour, and open mind. No calculators allowed.

  • Please turn off all beepers and portable

telephones before coming to class

55