viewing
play

Viewing http://www.ugrad.cs.ubc.ca/~cs314/Vjan2013 Reading for This - PowerPoint PPT Presentation

University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2013 Tamara Munzner Viewing http://www.ugrad.cs.ubc.ca/~cs314/Vjan2013 Reading for This Module FCG Chapter 7 Viewing FCG Section 6.3.1 Windowing Transforms RB rest


  1. Projective Transformations • planar geometric projections • planar: onto a plane • geometric: using straight lines • projections: 3D -> 2D • aka projective mappings • counterexamples? 38

  2. 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) 39

  3. Perspective Projection • project all geometry • through common center of projection (eye point) • onto an image plane x y -z z z x x 40

  4. Perspective Projection projection plane center of projection (eye point) how tall should this bunny be? 41

  5. Basic Perspective Projection similar triangles P(x,y,z) y P(x ’ ,y ’ ,z ’ ) z z ’ =d z ' = d but • nonuniform foreshortening • not affine 42

  6. Perspective Projection • desired result for a point [x, y, z, 1] T projected onto the view plane: x ' x y ' y , = = d z d z x d x y d y � � x ' , y ' , z ' d = = = = = z z d z z d • what could a matrix look like to do this? 43

  7. Simple Perspective Projection Matrix x � � � � z / d � � y � � � � z / d � � � � d � � � � 44

  8. Simple Perspective Projection Matrix x x � � � � � � � � y z / d is homogenized version of � � � � z � � y � � � � � � z / d where w = z/d z / d � � � � � � d � � � � 45

  9. Simple Perspective Projection Matrix x x � � � � � � � � y z / d is homogenized version of � � � � z � � y � � � � � � z / d where w = z/d z / d � � � � � � d � � x 1 0 0 0 x � � � � � � � � � � � � � � y 0 1 0 0 y � � � � � � = z 0 0 1 0 z � � � � � � � � � � � � z / d 0 0 1 d 0 1 � � � � � � 46

  10. 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 47

  11. Moving COP to Infinity • as COP moves away, lines approach parallel • when COP at infinity, orthographic view 48

  12. Orthographic Camera Projection • camera’s back plane x x � � � � parallel to lens p � � � � y y = • infinite focal length � p � � � z 0 � � � � • no perspective � � � � p convergence x 1 0 0 0 x � � � � � � p � � � � � � • just throw away z values y 0 1 0 0 y p � � � � � � = z 0 0 0 0 z � � � � � � p � � � � � � 1 0 0 0 1 1 � � � � � � 49

  13. Perspective to Orthographic • transformation of space • center of projection moves to infinity • view volume transformed • from frustum (truncated pyramid) to parallelepiped (box) x x Frustum Parallelepiped -z -z 50

  14. View Volumes • specifies field-of-view, used for clipping • restricts domain of z stored for visibility test orthographic view volume perspective view volume y=top y=top x=left x=left y y z x=right z VCS z=-near x VCS y=bottom z=-far z=-far x y=bottom x=right z=-near 51

  15. Canonical View Volumes • standardized viewing volume representation perspective orthographic orthogonal parallel x or y x or y = +/- z back x or y plane back 1 front plane front -z plane -z -1 plane -1 52

  16. Why Canonical View Volumes? • permits standardization • clipping • easier to determine if an arbitrary point is enclosed in volume with canonical view volume vs. clipping to six arbitrary planes • rendering • projection and rasterization algorithms can be reused 53

  17. Normalized Device Coordinates • convention • viewing frustum mapped to specific parallelepiped • Normalized Device Coordinates (NDC) • same as clipping coords • only objects inside the parallelepiped get rendered • which parallelepiped? • depends on rendering system 54

  18. Normalized Device Coordinates left/right x =+/- 1, top/bottom y =+/- 1, near/far z =+/- 1 NDC Camera coordinates x x x=1 right Frustum -z z left x= -1 z=1 z= -1 z=-n z=-f 55

  19. Understanding Z • z axis flip changes coord system handedness • RHS before projection (eye/view coords) • LHS after projection (clip, norm device coords) VCS NDCS y=top y (1,1,1) x=left y z (-1,-1,-1) z x x=right x z=-far y=bottom z=-near 56

  20. Understanding Z near, far always positive in OpenGL calls glOrtho(left,right,bot,top,near,far); glFrustum(left,right,bot,top,near,far); glPerspective(fovy,aspect,near,far); orthographic view volume perspective view volume y=top y=top x=left x=left y y z x=right VCS z=-near x VCS y=bottom z=-far z=-far x y=bottom x=right z=-near 57

  21. Understanding Z • why near and far plane? • near plane: • avoid singularity (division by zero, or very small numbers) • far plane: • store depth in fixed-point representation (integer), thus have to have fixed range of values (0…1) • avoid/reduce numerical precision artifacts for distant objects 58

  22. Orthographic Derivation • scale, translate, reflect for new coord sys VCS NDCS y=top y (1,1,1) x=left y z (-1,-1,-1) z x x=right x z=-far y=bottom z=-near 59

  23. Orthographic Derivation • scale, translate, reflect for new coord sys y top y ' 1 = � = y ' a y b = � + y bot y ' 1 = � = � VCS NDCS y=top y (1,1,1) x=left y z (-1,-1,-1) z x x=right x z=-far y=bottom z=-near 60

  24. Orthographic Derivation • scale, translate, reflect for new coord sys y top y ' 1 1 a top b = � = = � + y ' a y b = � + y bot y ' 1 1 a bot b = � = � � = � + 2 1 top b b 1 a top , b 1 a bot = + = � � = � � � top bot � 1 a top 1 a bot � � = � � � 2 top � b 1 = � 1 ( 1 ) a bot ( a top ) top bot � � = � � � � � � ( top bot ) 2 top 2 a ( bot top ) � � � = � + b = top bot � 2 a = top bot � � top bot � b = top bot � 61

  25. Orthographic Derivation • scale, translate, reflect for new coord sys y top y ' 1 = � = y ' a y b = � + y bot y ' 1 = � = � 2 VCS a = top bot � y=top x=left top bot y + b = � z top bot x=right � x z=-far y=bottom z=-near same idea for right/left, far/near 62

  26. Orthographic Derivation • scale, translate, reflect for new coord sys 2 right left + � � 0 0 � � � right left right left � � � � 2 top bot � � + 0 0 � � � top bot top bot � � P ' P = � � � 2 far near � � + 0 0 � � � far near far near � � � � � � 0 0 0 1 � � � � 63

  27. Orthographic Derivation • scale, translate, reflect for new coord sys 2 right left + � � 0 0 � � � right left right left � � � � 2 top bot � � + 0 0 � � � top bot top bot � � P ' P = � � � 2 far near � � + 0 0 � � � far near far near � � � � � � 0 0 0 1 � � � � 64

  28. Orthographic Derivation • scale, translate, reflect for new coord sys 2 right left + � � 0 0 � � � right left right left � � � � 2 top bot � � + 0 0 � � � top bot top bot � � P ' P = � � � 2 far near � � + 0 0 � � � far near far near � � � � � � 0 0 0 1 � � � � 65

  29. Orthographic Derivation • scale, translate, reflect for new coord sys 2 right left + � � 0 0 � � � right left right left � � � � 2 top bot � � + 0 0 � � � top bot top bot � � P ' P = � � � 2 far near � � + 0 0 � � � far near far near � � � � � � 0 0 0 1 � � � � 66

  30. Orthographic OpenGL glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(left,right,bot,top,near,far); 67

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

  32. Projections II 69

  33. Asymmetric Frusta • our formulation allows asymmetry • why bother? x x right right Frustum Frustum -z -z left left z=-n z=-f 70

  34. Asymmetric Frusta • our formulation allows asymmetry • why bother? binocular stereo • view vector not perpendicular to view plane Left Eye Right Eye 71

  35. Simpler Formulation • left, right, bottom, top, near, far • nonintuitive • often overkill • look through window center • symmetric frustum • constraints • left = -right, bottom = -top 72

  36. Field-of-View Formulation • FOV in one direction + aspect ratio (w/h) • determines FOV in other direction • also set near, far (reasonably intuitive) x w h fovx/2 Frustum -z α fovy/2 z=-n z=-f 73

  37. Perspective OpenGL glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(left,right,bot,top,near,far); or glPerspective(fovy,aspect,near,far); 74

  38. Demo: Frustum vs. FOV • Nate Robins tutorial (take 2): • http://www.xmission.com/~nate/tutors.html 75

  39. Projective Rendering Pipeline object world viewing O2W W2V V2C VCS WCS OCS projection modeling viewing transformation transformation transformation clipping C2N CCS OCS - object/model coordinate system perspective WCS - world coordinate system normalized divide device VCS - viewing/camera/eye coordinate N2D system NDCS viewport CCS - clipping coordinate system transformation NDCS - normalized device coordinate device system DCS DCS - device/display/screen coordinate system 76

  40. Projection Warp • warp perspective view volume to orthogonal view volume • render all scenes with orthographic projection! • aka perspective warp x x z=d z= α z=d z=0 Z Z 77

  41. Perspective Warp • perspective viewing frustum transformed to cube • orthographic rendering of cube produces same image as perspective rendering of original frustum 78

  42. Predistortion 79

  43. Projective Rendering Pipeline object world viewing O2W W2V V2C VCS WCS OCS projection modeling viewing transformation transformation transformation clipping C2N CCS OCS - object/model coordinate system perspective WCS - world coordinate system normalized divide device VCS - viewing/camera/eye coordinate N2D system NDCS viewport CCS - clipping coordinate system transformation NDCS - normalized device coordinate device system DCS DCS - device/display/screen coordinate system 80

  44. Separate Warp From Homogenization normalized clipping viewing device V2C C2N CCS VCS NDCS projection perspective transformation division alter w / w • 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 81

  45. 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 x � � x � � � � y � � y � � � � z � � z � � � � 1 � � � � � z � � -z 82

  46. Perspective Divide Example x 1 0 0 0 x x x / z � � � � � � � � � � � � � � � � � � � � � � � � � y 0 1 0 0 y y y / z � � � � � � � � � � � � � T = � = � � � z 0 0 1 0 z z 1 � � � � � � � � � � � � � � � � � � � � � � � � � 1 0 0 1 0 1 z 1 � � � � � � � � � � � � � � • after homogenizing, once again w=1 projection perspective transformation division alter w / w 83

  47. Perspective Normalization • matrix formulation x x � � 1 0 0 0 � � � � x � � � � � � � � y z / d x � � 0 1 0 0 � � p � � � � � � y y � � d d ( z ) d � � � � � � � � � � y � � � � = � 0 0 � = � � p � � z / d � � z d d � � � d � � � � � � � � � � � � z � 2 � d � 1 � � � � � � � � � � p � � z 1 1 0 0 0 � � � � � � � � � � d z � � d � � � � � � d � � • warp and homogenization both preserve relative depth (z coordinate)

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

  49. Perspective To NDCS Derivation VCS NDCS y=top x=left y (1,1,1) y z (-1,-1,-1) x z z=-near y=bottom z=-far x x=right 86

  50. Perspective Derivation x ' 1 0 0 0 x � � � � � � � � � � � � simple example earlier: y ' 0 1 0 0 y � � � � � � = z ' 0 0 1 0 z � � � � � � � � � � � � w ' 0 0 1/ d 0 1 � � � � � � complete: shear, scale, projection-normalization x E 0 A 0 x � � � � � � � � � � � � � y 0 F B 0 y � � � � � � � = z 0 0 C D z � � � � � � � � � � � � � w 0 0 � 1 0 1 � � � � � � � 87

  51. Perspective Derivation x ' 1 0 0 0 x � � � � � � � � � � � � y ' 0 1 0 0 y earlier: � � � � � � = z ' 0 0 1 0 z � � � � � � � � � � � � w ' 0 0 1/ d 0 1 � � � � � � complete: shear, scale, projection-normalization x E 0 A 0 x � � � � � � � � � � � � � y 0 F B 0 y � � � � � � � = z 0 0 C D z � � � � � � � � � � � � � w 0 0 � 1 0 1 � � � � � � � 88

  52. Perspective Derivation x ' 1 0 0 0 x � � � � � � earlier: � � � � � � y ' 0 1 0 0 y � � � � � � = z ' 0 0 1 0 z � � � � � � � � � � � � w ' 0 0 1/ d 0 1 � � � � � � complete: shear, scale, projection-normalization x E 0 A 0 x � � � � � � � � � � � � � y 0 F B 0 y � � � � � � � = z 0 0 C D z � � � � � � � � � � � � � w 0 0 � 1 0 1 � � � � � � � 89

  53. Recorrection: Perspective Derivation L/R sign error x = left � � x / w = � 1 � x ' E 0 A 0 x � � � � � � x ' = Ex + Az � � � � � � x = right � � x / w = 1 � y ' 0 F B 0 y y ' = Fy + Bz � � � � � � = y = top � � y / w = 1 � z ' 0 0 C D z � � � � � � z ' = Cz + D � � � � � � y = bottom � � y / w = � 1 � w ' 0 0 � 1 0 1 w ' = � z � � � � � � z = � near � � z / w = � 1 � z = � far � � z / w = 1 � z axis flip! y ' = Fy + Bz , y ' = Fy + Bz , 1 = Fy + Bz , 1 = Fy + Bz , w ' w ' w ' � z 1 = F y + B z , 1 = F y top � B , 1 = F � B , � z � z � z � ( � near ) 1 = F top � B near 90

  54. Perspective Derivation • similarly for other 5 planes • 6 planes, 6 unknowns 2 n r + l � � 0 0 � � r � l r � l � � 2 n t + b 0 0 � � t � b t � b � � � ( f + n ) � 2 fn � � 0 0 f � n f � n � � 0 0 � 1 0 � � � � 91

  55. Projective Rendering Pipeline object world viewing O2W W2V V2C VCS WCS OCS projection modeling viewing transformation transformation transformation clipping C2N CCS OCS - object/model coordinate system perspective WCS - world coordinate system normalized divide device VCS - viewing/camera/eye coordinate N2D system NDCS viewport CCS - clipping coordinate system transformation NDCS - normalized device coordinate device system DCS DCS - device/display/screen coordinate system 92

  56. 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 glViewport(0,0,w,h); glDepthRange(0,1); // depth = 1 by default 0 500 x y 0 y -1 viewport x NDC 1 1 -1 93 300

  57. 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 0 500 x y 0 y -1 viewport x NDC 1 1 -1 300 94

  58. 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) 0 500 x y 0 y height 1 viewport x NDC -1 width 1 95 -1 300

  59. N2D Transformation width � 1 width width ( x N + 1) � 1 � � � � � � 1 0 0 0 0 0 � � � � � � x D 1 0 0 0 x N � � � � � � 2 2 2 2 � � � � � � height � 1 height height ( � y N + 1) � 1 � � � � � � y D 0 � 1 0 0 y N 0 1 0 0 0 0 � � � � � � � � � � � � = = 2 2 2 2 � � � � � � z D 0 0 1 0 z N � � � � � � depth depth depth ( z N + 1) � � � � � � 0 0 1 0 0 0 � � � � � � 1 0 0 0 1 1 2 2 2 � � � � � � � � � � � � 0 0 0 1 0 0 0 1 1 � � � � � � � � � � � � Display z range is 0 to 1. glDepthRange(n,f) can constrain reminder: further, but depth = 1 is both NDC z range is -1 to 1 max and default 0 500 x y 0 y height 1 viewport x NDC -1 width 1 96 -1 300

  60. 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... 0 1024 x 0 y 0 500 x y offset 0 y display x offset viewport viewport height display 300 768 97 display width

  61. Projective Rendering Pipeline glVertex3f(x,y,z) object world viewing O2W W2V V2C alter w VCS WCS OCS glFrustum(...) projection modeling viewing transformation transformation transformation clipping glTranslatef(x,y,z) gluLookAt(...) C2N / w CCS glRotatef(a,x,y,z) perspective .... normalized division OCS - object coordinate system device glutInitWindowSize(w,h) N2D WCS - world coordinate system glViewport(x,y,a,b) NDCS viewport VCS - viewing coordinate system transformation CCS - clipping coordinate system device DCS NDCS - normalized device coordinate system DCS - device coordinate system 98

  62. Coordinate Systems viewing (4-space, W=1) clipping (4-space parallelepiped, projection with COP moved matrix backwards to infinity normalized device divide by w (3-space parallelepiped) device scale & (3-space translate parallelipiped) framebuffer 99

  63. Perspective Example view volume tracks in VCS: left = -1, right = 1 left x=-1, y=-1 bot = -1, top = 1 right x=1, y=-1 near = 1, far = 4 x=1 x=-1 1 ymax-1 z=-4 real midpoint -1 z=-1 1 -1 xmax-1 0 -1 0 x NDCS DCS (z not shown) (z not shown) z VCS top view 100

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend