1 / 34

Orthographic to Canonical View Pipeline

Learn about the error in the matrix for transforming the simple orthographic volume into the canonical view space and how to correct it. Explore the concepts of perspective viewing, vanishing points, and basic perspective projection.

asbury
Download Presentation

Orthographic to Canonical View Pipeline

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. Last Time • Canonical view pipeline • Orthographic projection • There was an error in the matrix for taking a simple orthographic volume and transforming it into the canonical view space • The slides now online are correct • In Shirley’s chapter on Transformation, note notation errors in the discussion of homogeneous coordinates Local Coordinate Space World Coordinate Space View Space 3D Screen Space Display Space Projection (c) 2002 University of Wisconsin, CS 559

  2. Today • Perspective viewing • Simple case • Completely general case (c) 2002 University of Wisconsin, CS 559

  3. Abstract camera model - box with a small hole in it Pinhole cameras work in practice - camera obscura, etc Perspective Projection (c) 2002 University of Wisconsin, CS 559

  4. Distant Objects Are Smaller (c) 2002 University of Wisconsin, CS 559

  5. Parallel lines meet common to draw film plane in front of the focal point (c) 2002 University of Wisconsin, CS 559

  6. Vanishing points • Each set of parallel lines (=direction) meets at a different point: The vanishing point for this direction • Classic artistic perspective is 3-point persepctive • Sets of parallel lines on the same plane lead to collinear vanishing points: the horizon for that plane • Good way to spot faked images (c) 2002 University of Wisconsin, CS 559

  7. Basic Perspective Projection • Assume you have transformed to view space, with x to the right, y up, and z back toward the viewer • Assume the origin of view space is at the center of projection • Define a focal distance, d, and put the image plane there (note d is negative) • This doesn’t quite fit into our viewing model, but we’ll come back to that (c) 2002 University of Wisconsin, CS 559

  8. Basic Perspective Projection • If you know P(xv,yv,zv) and d, what is P(xs,ys)? • Where does a point in view space end up on the screen? P(xv,yv,zv) P(xs,ys) yv d -zv xv (c) 2002 University of Wisconsin, CS 559

  9. Basic Case • Similar triangles gives: yv P(xv,yv,zv) P(xs,ys) d -zv View Plane (c) 2002 University of Wisconsin, CS 559

  10. Simple Perspective Transformation • Using homogeneous coordinates we can write: (c) 2002 University of Wisconsin, CS 559

  11. Perspective View Volume • Recall the orthographic view volume, defined by a near, far, left, right, top and bottom plane • The perspective view volume is also defined by near, far, left, right, top and bottom planes – the clip planes • Near and far planes are parallel to the image plane: zv=n, zv=f • Other planes all pass through the center of projection (the origin of view space) • The left and right planes intersect the image plane in vertical lines • The top and bottom planes intersect in horizontal lines (c) 2002 University of Wisconsin, CS 559

  12. Clipping Planes Left Clip Plane Near Clip Plane xv Far Clip Plane View Volume l n -zv f r Right Clip Plane (c) 2002 University of Wisconsin, CS 559

  13. Where is the Image Plane? • 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 • But we need to know where it is to define the clipping planes • Assume the left/right/top/bottom planes are defined according to where they cut the near clip plane • Or, define the left/right and top/bottom clip planes by the field of view (c) 2002 University of Wisconsin, CS 559

  14. Clipping Planes Left Clip Plane Near Clip Plane xv Far Clip Plane View Volume FOV -zv f Right Clip Plane (c) 2002 University of Wisconsin, CS 559

  15. OpenGL • gluPerspective(…) • Field of view in the y direction (vertical field-of-view) • Aspect ratio (should match window aspect ratio) • Near and far clipping planes • Defines a symmetric view volume • glFrustum(…) • Give the near and far clip plane, and places where the other clip planes cross the near plane • Defines the general case • Used for stereo viewing, mostly (c) 2002 University of Wisconsin, CS 559

  16. 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 just before the orthographic projection matrix (r,t,n) (l,b,n) (r,t,n) (l,b,n) (c) 2002 University of Wisconsin, CS 559

  17. Mapping Lines • We want to map all the lines through the center of projection to parallel lines • Points on lines through the center of projection map to the same point on the image • Points on parallel lines map orthographically to the same point on the image • If we convert the perspective case to the orthographic case, we can use all our existing methods • The intersection points of lines with the near clip plane should not change • The matrix that does this, not surprisingly, looks like the matrix for our simple perspective case (c) 2002 University of Wisconsin, CS 559

  18. General Perspective • This matrix leaves points with z=n unchanged • It is just like the simple projection matrix, but it does some extra things to z to map the depth properly • We can multiply a homogenous matrix by any number without changing the final point, so the two matrices above have the same effect (c) 2002 University of Wisconsin, CS 559

  19. Complete Perspective Projection • After applying the perspective matrix, we still have to map the orthographic view volume to the canonical view volume: (c) 2002 University of Wisconsin, CS 559

  20. OpenGL Perspective Projection • For OpenGL you give the distance to the near and far clipping planes • The total perspective projection matrix resulting from a glFrustum call is: (c) 2002 University of Wisconsin, CS 559

  21. Near/Far and Depth Resolution • It may seem sensible to specify a very near clipping plane and a very far clipping plane • Sure to contain entire scene • But, a bad idea: • OpenGL only has a finite number of bits to store screen depth • Too large a range reduces resolution in depth - wrong thing may be considered “in front” • See Shirley for a more complete explanation • Always place the near plane as far from the viewer as possible, and the far plane as close as possible (c) 2002 University of Wisconsin, CS 559

  22. Clipping • Parts of the geometry to be rendered may lie outside the view volume • View volume maps to memory addresses • Out-of-view geometry generates invalid addresses • Geometry outside the view volume also behaves very strangely under perspective projection • Triangles can be split into two pieces, for instance • Clipping removes parts of the geometry that are outside the view • Best done in screen space before perspective divide • Before dividing out the homogeneous coordinate (c) 2002 University of Wisconsin, CS 559

  23. Clipping • Points are trivial to clip - just check which side of the clip planes they are on • Many algorithms for clipping lines exist • Next lecture • Two main algorithms for clipping polygons exist • Sutherland-Hodgman (today) • Weiler (next lecture) (c) 2002 University of Wisconsin, CS 559

  24. Clipping Points • A point is inside the view volume if it is on the “inside” of all the clipping planes • The normals to the clip planes are considered to point inward, toward the visible stuff • Now we see why clipping is done in canonical view space • For instance, to check against the left plane: • X coordinate in 3Dmust be > -1 • In homogeneous screen space, same as: xscreen> -wscreen • In general, a point, p, is “inside” a plane if: • You represent the plane as nxx+nyy+nzz+d=0, with (nx,ny,nz) pointing inward • And nxpx+nypy+nzpz+d>0 (c) 2002 University of Wisconsin, CS 559

  25. Polygon-Rectangle Clipping (2D) • Task: Clip a polygon to a rectangle • Easy cases: • Hard Cases: (c) 2002 University of Wisconsin, CS 559

  26. Sutherland-Hodgman Clip (1) • Clip the polygon against each edge of the clip region in turn • Clip polygon each time to line containing edge • Only works for convex clip regions (Why?) (c) 2002 University of Wisconsin, CS 559

  27. Sutherland-Hodgman Clip (2) • To clip a polygon to a line: • Consider the polygon as a list of vertices • One side of the line is inside the clip region, the other outside • Think of the process as rewriting the polygon, one vertex at a time • Check start vertex: if “inside”, emit it, otherwise ignore it • Process vertex list as follows… (c) 2002 University of Wisconsin, CS 559

  28. Sutherland-Hodgman (3) • Look at the next vertex in the list: • polygon edge crosses clip edge going from out to in: emit crossing point, next vertex • polygon edge crosses clip edge going from in to out: emit crossing • polygon edge goes from out to out: emit nothing • polygon edge goes from in to in: emit next vertex (c) 2002 University of Wisconsin, CS 559

  29. Sutherland-Hodgman (4) Inside Outside Inside Outside Inside Outside Inside Outside p s i s p p s i p s Output p Output i No output Output i,p (c) 2002 University of Wisconsin, CS 559

  30. Inside-Outside Testing • Edges store a vector pointing toward the outside of the clip region • Dot products give inside/outside information Outside Inside n x f i s (c) 2002 University of Wisconsin, CS 559

  31. Sutherland-Hodgman (5) • In 3D, clip against planes instead of lines • Six planes to clip against • Inside/Outside test still works • Suitable for hardware implementation • Only need the clip edge, the endpoints of the current edge, and the last output point • Polygon edges are output as they are found, and passed right on to the next clip region edge (c) 2002 University of Wisconsin, CS 559

  32. Inside/Outside in Screen Space • In screen space, clip planes are xs=±1, ys=±1, zs=0, zs=1 • Inside/Outside reduces to comparisons before perspective divide (c) 2002 University of Wisconsin, CS 559

  33. Additional Clipping Planes • Useful for doing things like cut-away views • Use a clip plane to cut off part of the object • Only works if piece to be left behind if convex • OpenGL allows you to do it • Also one way to use OpenGL to identify objects in a region of space (uses the selection mechanism) (c) 2002 University of Wisconsin, CS 559

  34. Other Ways to Reject • If a polygonal object is closed, then no back-facing face is visible • Front-facing faces must occlude all back-facing ones • Reject back-facing polygons in view space • Transform face normal and check • Bounding volumes enclosing many polygons can be checked against the view volume • Done in software in world or view space • Visibility can reject whole chunks of geometry without even looking at them (c) 2002 University of Wisconsin, CS 559

More Related