1 / 57

CS559: Computer Graphics

CS559: Computer Graphics. Lecture 10: Projection and Rasterization Li Zhang Spring 2010. Last time: 3D Affine Transform. Alternative Representations. Specify the axis and the angle (OpenGL method) Hard to compose multiple rotations.

jtrevino
Télécharger la présentation

CS559: Computer Graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS559: Computer Graphics Lecture 10: Projection and Rasterization Li Zhang Spring 2010

  2. Last time: 3D Affine Transform

  3. Alternative Representations • Specify the axis and the angle (OpenGL method) • Hard to compose multiple rotations A rotation by an angle around axis specified by the unit vector is given by http://mathworld.wolfram.com/RodriguesRotationFormula.html

  4. 3D Geometry Pipeline Model Space (Object Space) Eye Space (View Space) World Space Projective, Scale Translation Rotation Translation Rotation Translation Resizing

  5. 3D Geometry Pipeline (cont’d) Normalized Projection Space Image Space (pixels) Raster Space Screen Space (2D) Project Scale Translation

  6. How to specify eye coordinate? • Give eye location e • Give target position p • Give upward direction u OpenGL has a helper command: gluLookAt (eyex, eyey, eyez, px, py, pz, upx, upy, upz )

  7. Projections • Projections transform points in n-space to m-space, where m<n. • In 3-D, we map points from 3-space to the projection plane (PP) (a.k.a., image plane) along rays emanating from the center of projection (COP): • There are two basic types of projections: • Perspective – distance from COP to PP finite • Parallel – distance from COP to PP infinite

  8. Parallel projections • For parallel projections, we specify a direction of projection (DOP) instead of a COP. • We can write orthographic projection onto the z=0 plane with a simple matrix, such that x’=x, y’=y. • Normally, we do not drop the z value right away. Why not?

  9. Today: Derivation of perspective projection Consider the projection of a point onto the projection plane: By similar triangles, we can compute how much the x and y coordinates are scaled:

  10. Homogeneous coordinates and perspective projection Now we can re-write the perspective projection as a matrix equation: Orthographic projection

  11. Vanishing points What happens to two parallel lines that are not parallel to the projection plane? Think of train tracks receding into the horizon... The equation for a line is: After perspective transformation we get:

  12. Vanishing points (cont'd) Dividing by w: Letting t go to infinity: We get a point! What happens to the line l = q + tv? Each set of parallel lines intersect at a vanishing point on the PP. Q: How many vanishing points are there?

  13. Vanishing points

  14. Vanishing points

  15. Vanishing points

  16. General Projective Transformation The perspective projection is an example of a projective transformation.

  17. Properties of perspective projections Here are some properties of projective transformations: • Lines map to lines • Parallel lines do not necessarily remain parallel • Ratios are not preserved One of the advantages of perspective projection is that size varies inversely with distance – looks realistic. A disadvantage is that we can't judge distances as exactly as we can with parallel projections.

  18. 3D Geometry Pipeline Model Space (Object Space) Eye Space (View Space) World Space Projective, Scale Translation Rotation Translation Rotation Translation Resizing

  19. Clipping and the viewing frustum The center of projection and the portion of the projection plane that map to the final image form an infinite pyramid. The sides of the pyramid are clipping planes. Frequently, additional clipping planes are inserted to restrict the range of depths. These clipping planes are called the near and far or the hither and yon clipping planes. All of the clipping planes bound the viewing frustum.

  20. Clipping and the viewing frustum • Notice that it doesn’t really matter where the image plane is located, once you define the view volume • You can move it forward and backward along the z axis and still get the same image, only scaled Usually d = near

  21. Clipping Planes The left/right/top/bottom planes are defined according to where they cut the near clip plane Left Clip Plane Near Clip Plane xv Far Clip Plane View Volume l n -zv f r Right Clip Plane Need 6 parameters, Or, define the left/right and top/bottom clip planes by the field of view

  22. Field of View Assumes a symmetric view volume Left Clip Plane Near Clip Plane xv Far Clip Plane View Volume FOV -zv f Right Clip Plane Need 4 parameters, Or, define the near, far, fov, aspect ratio

  23. Focal Distance to FOV • You must have the image size to do this conversion • Why? Same d, different image size, different FOV height/2 d FOV/2 d

  24. Perspective Parameters • We have seen three different ways to describe a perspective camera • Clipping planes, Field of View, Focal distance, • The most general is clipping planes – they directly describe the region of space you are viewing • For most graphics applications, field of view is the most convenient • You can convert one thing to another

  25. Perspective Projection Matrices • We want a matrix that will take points in our perspective view volume and transform them into the orthographic view volume • This matrix will go in our pipeline before an orthographic projection matrix (r,t,f) (r,t,f) (r,t,n) (r,t,n) (l,b,n) (l,b,n)

  26. Mapping Lines y • We want to map all the lines through the center of projection to parallel lines • This converts the perspective case to the orthographic case, we can use all our existing methods • The relative intersection points of lines with the near clip plane should not change • The matrix that does this looks like the matrix for our simple perspective case -z n f

  27. How to get this mapping? y -z n f

  28. Properties of this mapping y -z n f If z = n, M(x,y,z,1) = [x,y,z,1] near plane is unchanged If x/z = c1, y/z = c2, then x’=n*c1, y’=n*c2 bending converging rays to parallel rays If z1 < z2, z1’ < z2’ z ordering is preserved

  29. General Perspective

  30. To Canonical view volume • Perspective projection transforms a pyramid volume to an orthographic view volume (r,t,f) (r,t,f) (r,t,n) (r,t,n) (l,b,n) (l,b,n) Rotate, translate (-1,1,-1) (1,-1,1) Canonical view volume [-1,1]^3

  31. Orthographic View to Canonical Matrix

  32. Orthographic View to Canonical Matrix

  33. Complete Perspective Projection • After applying the perspective matrix, we map the orthographic view volume to the canonical view volume:

  34. 3D Geometry Pipeline Model Space (Object Space) Eye Space (View Space) World Space Projective, Scale Translation Rotation Translation Rotation Translation Resizing

  35. 3D Geometry Pipeline (cont’d) Normalized Projection Space Image Space (pixels) Raster Space Screen Space (2D) Project Scale Translation

  36. Canonical  Window Transform (1,1) (xmax,ymax) (xmin,ymin) (-1,-1)

  37. Canonical  Window Transform (1,1) (xmax,ymax) (xmin,ymin) (-1,-1)

  38. Mapping of Z is nonlinear • Many mappings proposed: all have nonlinearities • Advantage: handles range of depths (10cm – 100m) • Disadvantage: depth resolution not uniform • More close to near plane, less further away • Common mistake: set near = 0, far = infty. Don’t do this. Can’t set near = 0; lose depth resolution.

  39. 3D Geometry Pipeline Rotation Translation Rotation Translation Resizing Eye Space (View Space) World Space Model Space (Object Space) Image Space (pixels) Raster Space Screen Space (2D) Canonical View Space

  40. Canonical  Window Transform (xmax, ymax)=(nx-0.5,ny-0.5) ny-1 (1,1) (-1,-1) nx-1 (xmin,ymin)=(-0.5,-0.5)

  41. Polygons are basic shape primitives • Any 3D shape can be approximated by a polygon using a locally linear (planar) approximation. To improve the quality of fit, we need only increase the number of edges

  42. Line Drawing (x1, y1) (x0, y0)

  43. Line Drawing for x = x0 to x1 do y=y0+(∆y/∆x)(x-x0) draw(x,round(y)) (x1, y1) (x0, y0)

  44. Line Drawing y = y0 for x = x0 to x1 do draw(x,y) if (some condition) then y=y+1 (x1, y1) (x0, y0)

  45. Implicit Line Drawing y = y0 for x = x0 to x1 do draw(x,y) if (some condition) then y=y+1 (x1, y1) (x0, y0) f(x+1,y+0.5)<0

  46. Implicit Line Drawing y = y0 for x = x0 to x1 do draw(x,y) if (some condition) then y=y+1 (x1, y1) (x0, y0) f(x+1,y+0.5)<0 Incremental Evaluation

  47. Implicit Line Drawing y = y0 for x = x0 to x1 do draw(x,y) if (some condition) then y=y+1 else d=f(x+1,y+0.5) (x1, y1) (x0, y0) d<0 D=d-∆y+∆x D=d-∆y Incremental Evaluation

  48. Implicit Line Drawing y = y0 for x = x0 to x1 do draw(x,y) if (some condition) then y=y+1 else d=2f(x+1,y+0.5) (x1, y1) (x0, y0) d<0 D=d-2∆y+2∆x D=d-2∆y Incremental Evaluation Integer operation

  49. Implicit Line Drawing y = y0 for x = x0 to x1 do draw(x,y) if (some condition) then y=y+1 else d=2f(x+1,y+0.5) (x1, y1) (x0, y0) d<0 D=d-2∆y+2∆x D=d-2∆y

  50. Implicit Line Drawing y = y0 for x = x0 to x1 do draw(x,y) if (some condition) then y=y+1 else d=2f(x+1,y+0.5) d<0 D=d-2∆y+2∆x D=d-2∆y

More Related