1 / 47

Viewing and Perspective

This lecture explores the concepts of projection, surface of projection, planar geometric projections, and viewing transformations in computer graphics. It also covers the vertex pipeline, primitive assembly, rasterization, and fragment operations involved in transforming points from one coordinate system to another. The lecture provides insights into various coordinate systems, such as object coordinates, eye coordinates, clip coordinates, normalized device coordinates, and window coordinates. Additionally, it discusses orthographic projection and the process of clipping lines and triangles. The importance of homogenization and viewport transformation is also highlighted.

lisetted
Download Presentation

Viewing and Perspective

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. Viewing and Perspective Kurt Akeley CS248 Lecture 9 23 October 2007 http://graphics.stanford.edu/courses/cs248-07/

  2. Projection Projection • Transforms points from an n to an n-1 coordinate system • Other definitions? … Surface of projection • Typically a plane (“planar”) • Curved in special cases • E.g., dome simulator Projectors (connect points through the center of projection) • Typically straight lines (“geometric”) • Curved in special cases • Cartographic (e.g., Mercator) • Fish-eye lens (e.g., Omnimax) Image courtesy of Wikipedia Image courtesy of Wikipedia

  3. Planar geometric projections Straight lines project to straight lines • p1, p2, and c define a plane • The intersection of this plane and the plane of projection is a line But distances may be distorted p1 p2 c Center of projection(aka point of projection, viewpoint) Plane of projection

  4. Taxonomy of planar geometric projections Planar geometric Parallel Perspective Orthographic Oblique 1-point 2-point 3-point Top Front Side Cabinet Cavalier True projection type Viewing transformation

  5. The vertex pipeline Application struct { float x,y,z,w; float nx,ny,nz; float r,g,b,a;} vertex; Vertex assembly Vertex operations Primitive assembly Primitive operations Rasterization Fragment operations Framebuffer Display

  6. OpenGL coordinate systems no vo Object coordinates “Model-view” transformation(non-rigid) Transform vo by MTransform no by M-1 Eye coordinates(lighting calculations) ne ve Vertex operations Transform ve by P Projection transformation(non-rigid) vc Clip coordinates

  7. The vertex pipeline struct { float x,y,z,w; float nx,ny,nz; float r,g,b,a;} vertex; Application Vertex assembly Vertex operations struct { float x,y,z,w; float r,g,b,a;} clipvertex; Primitive assembly Primitive operations Rasterization Fragment operations Framebuffer Display

  8. OpenGL coordinate systems Object coordinates no vo Transform vo by MTransform no by M-1 Model-view transformation Vertex operations Eye coordinates(lighting calculations) ne ve Transform ve by P Projection transformation vc Primitive assembly Clip coordinates(clip to unit cube) Divide by wc Homogenize Normalized device coordinates vd Primitive operations Map to Window Viewport transformation vw Window coordinates

  9. Coordinates systems are convenient Object coordinates • Defined by modeler Eye coordinates • Eye is at the origin, looking down the -z axis, +x to the right • Convenient for lighting calculations Clip coordinates • Unit cube (+/- 1) centered at the origin • Convenient for clipping calculations (plane equations are trivial) Normalized device coordinates • Homogenized clip coordinates • Convenient for rasterization and frame buffer arithmetic Window coordinates • Pixels are unit squares, origin at lower-left corner of window • Z values fill available depth-buffer range

  10. Orthographic Projection(the complete sequence)

  11. Viewing transformation Puts eye at origin looking down the -z axis, +x to the right Transformation is rigid, one rotation and one translation • GLU helper routine is available (next slide) y x z

  12. gluLookAt gluLookAt(double ex, double ey, double ez, // eye double cx, double cy, double cz, // center double ux, double uy, double uz); // up

  13. Light positions Specified position is transformed by the modelview matrix glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(ex,ey,ez,cx,cy,cz,ux,uy,uz); // now in world coordinates Float vec[4] = {px, py, pz, pw}; glLightfv(GL_POSITION, vec, 4); // specify in world coordinates … glMultMatrixf(…); glLightfv(GL_POSITION, vec, 4); // specify in object coordinates

  14. Orthographic projection Only scaling is required But the interface supports scaling and translation: glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(l,r,b,t,n,f); n and f are signed distances, not coordinates

  15. The orthographic view volume ye xe ze

  16. Clip testing vc is within the unit cube centered at the origin if: Assuming wc is positive, this is equivalent to: yc xc zc

  17. Clipping arithmetic Points outside the unit cube are discarded Lines (or edges) that straddle a face of the unit cube are clipped • A new vertex is location is computed at the intersection • Appropriate attribute values are assigned to this vertex p2 p p1

  18. Clipping details The calculation of p must be invariant to the order of p1 and p2 • An edge shared by two triangles must not “crack” • Easiest implementation is canonical: • Sort the vertexes into canonical order, then compute p Line clipping never generates more than two vertexes Triangle clipping can generate a vertex for each clipping plane • E.g., Sutherland-Hodgman • Later in this lecture • SGI paid royalties on this

  19. Homogenization Divide by wc: Discard wd:

  20. Viewport transformation Transform the [-1,1] range device coordinates to window coordinates: glViewport(int l, int b, int w, int h); glDepthRange(double n, double f); glViewport(0, 0, 10, 6); glDepthRange(0.0, 1.0); One pixel

  21. The vertex pipeline struct { float x,y,z,w; float nx,ny,nz; float r,g,b,a;} vertex; Application Vertex assembly Vertex operations struct { float x,y,z,w; float r,g,b,a;} clipvertex; Primitive assembly Primitive operations struct { winvertex v0,v1,v2 } triangle; Rasterization struct { float x,y,z; float r,g,b,a;} winvertex; Fragment operations Framebuffer Display

  22. Window coordinates Window coordinates are: • Continuous, not discrete • Not homogeneous • Can be used directly for rasterization • 3-D, not 2-D • Projection did not reduce 3-D to 2-D • 3-D homogeneous was reduced to 3-D non-homogeneous • But this was done by homogenization, not by the projection transformation Where did the parallel “projection” happen?

  23. Oblique projection glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(l,r,b,t,n,f); float s = 0.5; // Cabinet float m[16] = {1,0,0,0, 0,1,0,0, -s,-s,1,0, 0,0,0,1}; glMultMatrixf(m);

  24. Perspective Projection

  25. Change only the projection matrix Object coordinates no vo Transform vo by MTransform no by M-1 Model-view transformation Vertex operations Eye coordinates(lighting calculations) ne ve Transform ve by P Projection transformation vc Primitive assembly Clip coordinates(clip to unit cube) Divide by wc Homogenize Normalized device coordinates vd Primitive operations Map to Window Viewport transformation vw Window coordinates

  26. Orthographic projection Only scaling is required But the interface supports scaling and translation: glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(l,r,b,t,n,f);

  27. Perspective projection Specify a frustum: n and f are distances, not coordinates. Both must be positive. glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(l,r,b,t,n,f);

  28. The frustum ye xe ze

  29. Where does projection happen? There are two ways to think about this: • In the projection transformation • “Thinking homogeneously” • Setting wc= –ze warps the eye-coordinate system • From a frustum in eye coordinates • To the unit cube in clip coordinates • Homogenization doesn’t really change anything further • Hence “projection transformation” • During homogenization and the discarding of the wd • “Thinking geometrically” • Dividing by –ze causes the projection • This is where coordinates are reduced from 4D to 3D

  30. Remaining topics Perspective-correct attribute parameterization Sutherland-Hodgman clipping Near-plane clipping The “direction” of a projection Wide field-of-view projection (planar doesn’t work well)

  31. Rasterization revisited struct { float x,y,z,w; float nx,ny,nz; float r,g,b,a;} vertex; Application Vertex assembly Vertex operations struct { float x,y,z,w; float r,g,b,a;} clipvertex; Primitive assembly Primitive operations struct { winvertex v0,v1,v2 } triangle; Rasterization struct { float x,y,z; float r,g,b,a;} winvertex; Fragment operations Framebuffer Display

  32. Planar geometric projection Straight lines project to straight lines • Only vertexes need to be transformed • That’s why we’re interested in lines and polygons But distances and parameterizations are warped:

  33. Incorrect attribute interpolation f1 Linearinterpolation f1 f f F f2 f2

  34. a2 a0 a1 Linear (barycentric) attribute evaluation (x1, y1, f1) (x, y, f ) (x0, y0, f0) (x2, y2, f2)

  35. a2 a0 a1 Perspective-correct attribute evaluation (x1, y1, w1, f1) (x, y, f ) All w’s are wc’s (x0, y0, w0, f0) (x2, y2, w2, f2) Requires a division for each fragment

  36. Rasterization requires access to wc struct { float x,y,z,w; float nx,ny,nz; float r,g,b,a;} vertex; Application Vertex assembly Vertex operations struct { float x,y,z,w; float r,g,b,a;} clipvertex; Primitive assembly Primitive operations struct { winvertex v0,v1,v2 } triangle; Rasterization struct { float x,y,z,w_c; float r,g,b,a;} winvertex; Fragment operations Framebuffer Display

  37. OpenGL coordinate systems Object coordinates no vo Transform vo by MTransform no by M-1 Model-view transformation Vertex operations Eye coordinates(lighting calculations) ne ve Transform ve by P Projection transformation vc Primitive assembly Clip coordinates(clip to unit cube) Divide by wc Homogenize Normalized device coordinates vd , wc Primitive operations Map to Window Viewport transformation vw , wc Window coordinates

  38. Sutherland-Hodgman clipping Approach: clip against each plane in sequence Simplified example clips a triangle to a square, 2-D frustum:

  39. Near-plane clipping Is required … • To limit zw values to the range of the depth buffer • To avoid division by wc= 0 • To avoid rendering objects behind the viewpoint • But clipping assuming wc> 0 accomplishes this too

  40. The “direction” of a projection Yes, we spoke of a view direction in eye coordinates • Specifically, down the –ze axis, +xe to the right And yes, the plane of projection is perpendicular to the –ze axis by convention But, once the projection has been specified, it is not valid to treat it as implying a true viewing direction (the orientation of the eye): • Parallel projections have a meaningful direction that is distinct from the normal to the plane of projection, but this direction is not the view direction. • Perspective projections have no meaningful direction at all. Once specified, they are fully characterized by a center of projection and a plane of projection. The normal to the plane of projection has no meaning. Bottom line: once a projection has been specified, it implies nothing about the orientation of the viewer’s eye. Only the location of the eye’s optical center is specified (the center of projection).

  41. Projection does not imply viewing direction!

  42. Wide field-of-view display Assume equal-size pixels Problem: • Center-field pixels are most important (foveal gaze) • But wide-field pixels have much greater “resolution”

  43. Ratio of perceived pixel sizes Ratio of perceived size of center pixel to edge pixel Field of view (degrees)

  44. Piece-wise linear projection Note: there is one view direction, but three planes of projection

  45. Summary Perspective projection can be understood two different ways: • Warping of eye coordinates by the projection transformation • Consistent with orthographic transformation • Consistent with 3-D result • Consistent with name “projection transformation” • Division by -ze and discarding of wd • Consistent with attribute evaluation Perspective projection warps distances and attribute evaluation • Must interpolate only “projected” values • Requires division for attributes of each fragment Projections do not specify the true orientation of the viewer’s eye • Perspective projections don’t really have a direction • Parallel projections do, but it’s not the viewing direction

  46. Assignments Reading assignment for Thursday’s class • FvD 17.4 • OpenGL chapter 9 • Optional: Heckbert, P., A Survey of Texture Mapping,IEEE Computer Graphics, 6:11, pp. 56-67, 1986. Project 2: • Due tonight at midnight Midterm • Monday 7 pm to 9 pm, Gates B01

  47. End

More Related