computer graphics cs 543 lecture 5 part 2 projection part
play

Computer Graphics (CS 543) Lecture 5 (part 2): Projection (Part 2): - PowerPoint PPT Presentation

Computer Graphics (CS 543) Lecture 5 (part 2): Projection (Part 2): Derivation Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI) Parallel Projection normalization find 4x4 matrix to transform user specified


  1. Computer Graphics (CS 543) Lecture 5 (part 2): Projection (Part 2): Derivation Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI)

  2. Parallel Projection  normalization  find 4x4 matrix to transform user ‐ specified view volume to canonical view volume (cube) User ‐ specified View Volume Canonical View Volume glOrtho (left, right, bottom, top,near, far)

  3. Parallel Projection: Ortho  Parallel projection: 2 parts Translation: centers view volume at origin 1.

  4. Parallel Projection: Ortho Scaling: reduces user ‐ selected cuboid to canonical 2. cube (dimension 2, centered at origin)

  5. Parallel Projection: Ortho Translation lines up midpoints: E.g. midpoint of x = (right + left)/2  Thus translation factors:  ‐ (right + left)/2, ‐ (top + bottom)/2, ‐ (far+near)/2  Translation matrix:     1 0 0 ( right left ) / 2       0 1 0 ( top bottom ) / 2     0 0 1 ( far near ) / 2       0 0 0 1

  6. Parallel Projection: Ortho Scaling factor: ratio of ortho view volume to cube dimensions  Scaling factors: 2/(right ‐ left), 2/(top ‐ bottom), 2/(far ‐ near)  Scaling Matrix M2:    2   0 0 0    right left   2 0 0 0    top bottom   2   0 0 0    far near     0 0 0 1

  7. Parallel Projection: Ortho Concatenating Translation x Scaling , we get Ortho Projection matrix   2       0 0 0 1 0 0 ( right left ) / 2      right left       2 0 1 0 ( top bottom ) / 2 0 0 0    X   top bottom     0 0 1 ( far near ) / 2 2     0 0 0      far near   0 0 0 1     0 0 0 1    2 right left  0 0     right left right left    2 top bottom    0 0     top bottom top bottom P = ST =    2 far near   0 0     near far far near     0 0 0 1

  8. Final Ortho Projection  Set z =0  Equivalent to the homogeneous coordinate transformation   1 0 0 0   0 1 0 0   M orth =   0 0 0 0     0 0 0 1  Hence, general orthogonal projection in 4D is P = M orth ST

  9. Perspective Projection  Projection – map the object from 3D space to 2D screen y z x Perspective( ) Frustrum ( )

  10. Perspective Projection: Classical Projectors Object in 3 space Projected image VRP COP Projection plane y (x,y,z) Based on similar triangles: (x’,y’,z’) (0,0,0) y’ N = y -z - z + z -N N y’ = y x -z -z Eye (COP) Near Plane (VOP)

  11. Perspective Projection: Classical  So (x*,y*) projection of point, (x,y,z) unto near plane N is given as: Projectors Object in 3 space     N N    Projected image *, * , x y x y     z z   VRP COP  Numerical example: Q. Where on the viewplane does P = (1, 0.5, ‐ 1.5) lie for a near plane at N = 1?       N N 1 1          x *, y * x , y 1 , 0 . 5 ( 0 . 666 , 0 . 333 )       1 . 5 1 . 5 z z  

  12. Pseudodepth  Classical perspective projection projects (x,y) coordinates to (x*, y*), drops z coordinates Map to sam e ( x* ,y* ) Projectors Com pare their z values? Object in 3 space Projected image (0,0,0) VRP z COP  But we need z to find closest object (depth testing)!!!

  13. Perspective Transformation  Perspective transformation maps actual z distance of perspective view volume to range [ –1 to 1] ( Pseudodepth ) for canonical view volume Actual view volum e W e w ant perspective Actual depth Transform ation and NOT classical projection!! Near Far Canonical view volum e Pseudodepth Set scaling z Pseudodepth = az + b Next solve for a and b 1 -1

  14. Perspective Transformation  We want to transform viewing frustum volume into canonical view volume (1, 1, -1) y z (-1, -1, 1) x Canonical View Volume

  15. Perspective Transformation using Pseudodepth    N az b   N    x *, y *, z * x , y ,      z z z    Choose a, b so as z varies from Near to Far , pseudodepth varies from –1 to 1 (canonical cube) Actual view volum e Boundary conditions  Actual depth z* = ‐ 1 when z = ‐ N  Z z* = 1 when z = ‐ F  Near Far Pseudodepth Canonical view volum e Z* -1 1

  16. Transformation of z: Solve for a and b  Solving:  az b  z *  z  Use boundary conditions  z* = ‐ 1 when z = ‐ N………(1)  z* = 1 when z = ‐ F………..(2)  Set up simultaneous equations   aN b        1 N aN b ........( 1 ) N   aF b      1 F aF b ........( 2 ) F

  17. Transformation of z: Solve for a and b     N aN b ........( 1 )    F aF b ........( 2 )  Multiply both sides of (1) by ‐ 1   N aN b ........( 3 )  Add eqns (2) and (3)    F N aN aF    F N ( F N )    a .........( 4 )   N F F N  Now put (4) back into (3)

  18. Transformation of z: Solve for a and b  Put solution for a back into eqn (3)   N aN b ........( 3 )   N ( F N )    N b  F N   ( ) N F N     b N  F N          2 2 N ( F N ) N ( F N ) NF N NF N 2 NF     b    F N F N F N  So    ( F N ) 2 FN   a b   F N F N

  19. What does this mean?  Original point z in original view volume, transformed into z* in canonical view volume Actual view Original volum e  az b vertex z value  * z  z Near Far  where   ( F N )  a  Transform ed F N Canonical view vertex z* value volum e  2 FN  b  F N -1 1

  20. Homogenous Coordinates  Want to express projection transform as 4x4 matrix  Previously, homogeneous coordinates of P = (Px,Py,Pz) => (Px,Py,Pz,1)  Introduce arbitrary scaling factor, w, so that P = (wPx, wPy, wPz, w) ( Note: w is non ‐ zero)  For example, the point P = (2,4,6) can be expressed as  (2,4,6,1)  or (4,8,12,2) where w=2  or (6,12,18,3) where w = 3, or….  To convert from homogeneous back to ordinary coordinates, first divide all four terms by w and discard 4 th term

  21. Perspective Projection Matrix  Recall Perspective Transform    N az b   N    x *, y *, z * x , y ,      z z z     We have: N az b N    y * y x * x z *    z z z  In matrix form:   N   x        N 0 0 0 wx wNx   z        N        0 N 0 0 wy wNy y            z  0 0 a b wz w ( az b )          az b                 0 0 1 0 w wz  z     1 Perspective Transform ed Original Transform ed Vertex Transform Matrix Vertex vertex after dividing by 4 th term

  22. Perspective Projection Matrix   N   x        N 0 0 0 wP wNP   z       x x   N       0 N 0 0 wP wNP y   y   y        z    0 0 a b wP w ( aP b )        az b z z                 0 0 1 0 wP w  z   z   1    ( F N ) 2 FN   a b   F N F N  In perspective transform matrix, already solved for a and b :  So, we have transform matrix to transform z values

  23. Perspective Projection Not done yet!! Can now transform z!  Also need to transform the x = (left, right) and y = (bottom, top)  ranges of viewing frustum to [ ‐ 1, 1] Similar to glOrtho, we need to translate and scale previous matrix  along x and y to get final projection transform matrix we translate by  y –(right + left)/2 in x  top ‐ (top + bottom)/2 in y  Scale by:  2/(right – left) in x  2/(top – bottom) in y  x 1 -1 bottom right left

  24. Perspective Projection  Translate along x and y to line up center with origin of CVV –(right + left)/2 in x  ‐ (top + bottom)/2 in y   Multiply by translation matrix:     1 0 0 ( right left ) / 2   y     0 1 0 ( top bottom ) / 2 top   0 0 1 0       0 0 0 1 x Line up centers 1 -1 Along x and y bottom right left

Recommend


More recommend