Presentation is loading. Please wait.

Presentation is loading. Please wait.

Viewing and Perspective Kurt Akeley CS248 Lecture 9 23 October 2007

Similar presentations


Presentation on theme: "Viewing and Perspective Kurt Akeley CS248 Lecture 9 23 October 2007"— Presentation transcript:

1 Viewing and Perspective Kurt Akeley CS248 Lecture 9 23 October 2007 http://graphics.stanford.edu/courses/cs248-07/

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

3 CS248 Lecture 9Kurt Akeley, Fall 2007 Planar geometric projections Straight lines project to straight lines p 1, p 2, and c define a plane n The intersection of this plane and the plane of projection is a line But distances may be distorted Center of projection (aka point of projection, viewpoint) p1p1 p2p2 Plane of projection c

4 CS248 Lecture 9Kurt Akeley, Fall 2007 Taxonomy of planar geometric projections Planar geometric ParallelPerspective 1-point2-point3-pointOrthographicOblique CabinetTopCavalierFrontSide True projection type Viewing transformation

5 CS248 Lecture 9Kurt Akeley, Fall 2007 The vertex pipeline Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations struct { float x,y,z,w; float nx,ny,nz; float r,g,b,a; } vertex; Framebuffer

6 CS248 Lecture 9Kurt Akeley, Fall 2007 OpenGL coordinate systems Vertex operations Transform v o by M Transform n o by M -1 Transform v e by P Object coordinates Eye coordinates (lighting calculations) Clip coordinates vovo veve vcvc nono nene “Model-view” transformation (non-rigid) Projection transformation (non-rigid)

7 CS248 Lecture 9Kurt Akeley, Fall 2007 The vertex pipeline Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations struct { float x,y,z,w; float nx,ny,nz; float r,g,b,a; } vertex; Framebuffer struct { float x,y,z,w; float r,g,b,a; } clipvertex;

8 CS248 Lecture 9Kurt Akeley, Fall 2007 OpenGL coordinate systems Vertex operations Transform v e by P Object coordinates Eye coordinates (lighting calculations) Clip coordinates (clip to unit cube) vovo veve vcvc nono nene Model-view transformation Projection transformation vdvd Divide by w c Map to Window Transform v o by M Transform n o by M -1 Homogenize Normalized device coordinates vwvw Window coordinates Viewport transformation Primitive operations Primitive assembly

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

10 CS248 Lecture 9Kurt Akeley, Fall 2007 Orthographic Projection (the complete sequence)

11 CS248 Lecture 9Kurt Akeley, Fall 2007 Viewing transformation Puts eye at origin looking down the -z axis, +x to the right Transformation is rigid, one rotation and one translation n GLU helper routine is available (next slide) x y z

12 CS248 Lecture 9Kurt Akeley, Fall 2007 gluLookAt gluLookAt(double ex, double ey, double ez, // eye double cx, double cy, double cz, // center double ux, double uy, double uz); // up

13 CS248 Lecture 9Kurt Akeley, Fall 2007 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 CS248 Lecture 9Kurt Akeley, Fall 2007 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 CS248 Lecture 9Kurt Akeley, Fall 2007 The orthographic view volume xexe yeye zeze

16 CS248 Lecture 9Kurt Akeley, Fall 2007 Clip testing v c is within the unit cube centered at the origin if: Assuming w c is positive, this is equivalent to: xcxc ycyc zczc

17 CS248 Lecture 9Kurt Akeley, Fall 2007 Clipping arithmetic Points outside the unit cube are discarded Lines (or edges) that straddle a face of the unit cube are clipped n A new vertex is location is computed at the intersection n Appropriate attribute values are assigned to this vertex p1p1 p2p2 p

18 CS248 Lecture 9Kurt Akeley, Fall 2007 Clipping details The calculation of p must be invariant to the order of p 1 and p 2 n An edge shared by two triangles must not “crack” n 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 n E.g., Sutherland-Hodgman n Later in this lecture n SGI paid royalties on this

19 CS248 Lecture 9Kurt Akeley, Fall 2007 Homogenization Divide by w c : Discard w d :

20 CS248 Lecture 9Kurt Akeley, Fall 2007 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 CS248 Lecture 9Kurt Akeley, Fall 2007 The vertex pipeline Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations struct { float x,y,z,w; float nx,ny,nz; float r,g,b,a; } vertex; Framebuffer struct { float x,y,z,w; float r,g,b,a; } clipvertex; struct { float x,y,z; float r,g,b,a; } winvertex; struct { winvertex v0,v1,v2 } triangle;

22 CS248 Lecture 9Kurt Akeley, Fall 2007 Window coordinates Window coordinates are: n Continuous, not discrete n Not homogeneous n Can be used directly for rasterization n 3-D, not 2-D n Projection did not reduce 3-D to 2-D n 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 CS248 Lecture 9Kurt Akeley, Fall 2007 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 CS248 Lecture 9Kurt Akeley, Fall 2007 Perspective Projection

25 CS248 Lecture 9Kurt Akeley, Fall 2007 Change only the projection matrix Vertex operations Transform v e by P Object coordinates Eye coordinates (lighting calculations) Clip coordinates (clip to unit cube) vovo veve vcvc nono nene Model-view transformation Projection transformation vdvd Divide by w c Map to Window Transform v o by M Transform n o by M -1 Homogenize Normalized device coordinates vwvw Window coordinates Viewport transformation Primitive operations Primitive assembly

26 CS248 Lecture 9Kurt Akeley, Fall 2007 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 CS248 Lecture 9Kurt Akeley, Fall 2007 Perspective projection Specify a frustum: glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(l,r,b,t,n,f); n and f are distances, not coordinates. Both must be positive.

28 CS248 Lecture 9Kurt Akeley, Fall 2007 The frustum xexe yeye zeze

29 CS248 Lecture 9Kurt Akeley, Fall 2007 Where does projection happen? There are two ways to think about this: n In the projection transformation n “Thinking homogeneously” Setting w c = –z e warps the eye-coordinate system –From a frustum in eye coordinates –To the unit cube in clip coordinates n Homogenization doesn’t really change anything further n Hence “projection transformation” During homogenization and the discarding of the w d n “Thinking geometrically” Dividing by –z e causes the projection n This is where coordinates are reduced from 4D to 3D

30 CS248 Lecture 9Kurt Akeley, Fall 2007 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 CS248 Lecture 9Kurt Akeley, Fall 2007 Rasterization revisited Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations struct { float x,y,z,w; float nx,ny,nz; float r,g,b,a; } vertex; Framebuffer struct { float x,y,z,w; float r,g,b,a; } clipvertex; struct { float x,y,z; float r,g,b,a; } winvertex; struct { winvertex v0,v1,v2 } triangle;

32 CS248 Lecture 9Kurt Akeley, Fall 2007 Planar geometric projection Straight lines project to straight lines n Only vertexes need to be transformed n That’s why we’re interested in lines and polygons But distances and parameterizations are warped:

33 CS248 Lecture 9Kurt Akeley, Fall 2007 Incorrect attribute interpolation f2f2 f1f1 f f2f2 f1f1 F f Linear interpolation

34 CS248 Lecture 9Kurt Akeley, Fall 2007 Linear (barycentric) attribute evaluation (x 0, y 0, f 0 ) (x 1, y 1, f 1 ) (x 2, y 2, f 2 ) (x, y, f ) a2a2 a1a1 a0a0

35 CS248 Lecture 9Kurt Akeley, Fall 2007 Perspective-correct attribute evaluation (x 0, y 0, w 0, f 0 ) (x 1, y 1, w 1, f 1 ) (x 2, y 2, w 2, f 2 ) (x, y, f ) a2a2 a1a1 a0a0 Requires a division for each fragment All w ’s are w c ’s

36 CS248 Lecture 9Kurt Akeley, Fall 2007 Rasterization requires access to w c Vertex assembly Primitive assembly Rasterization Fragment operations Display Vertex operations Application Primitive operations struct { float x,y,z,w; float nx,ny,nz; float r,g,b,a; } vertex; Framebuffer struct { float x,y,z,w; float r,g,b,a; } clipvertex; struct { float x,y,z,w_c; float r,g,b,a; } winvertex; struct { winvertex v0,v1,v2 } triangle;

37 CS248 Lecture 9Kurt Akeley, Fall 2007 OpenGL coordinate systems Vertex operations Transform v e by P Object coordinates Eye coordinates (lighting calculations) Clip coordinates (clip to unit cube) vovo veve vcvc nono nene Model-view transformation Projection transformation v d, w c Divide by w c Map to Window Transform v o by M Transform n o by M -1 Homogenize Normalized device coordinates v w, w c Window coordinates Viewport transformation Primitive operations Primitive assembly

38 CS248 Lecture 9Kurt Akeley, Fall 2007 Sutherland-Hodgman clipping Approach: clip against each plane in sequence Simplified example clips a triangle to a square, 2-D frustum:

39 CS248 Lecture 9Kurt Akeley, Fall 2007 Near-plane clipping Is required … To limit z w values to the range of the depth buffer To avoid division by w c = 0 n To avoid rendering objects behind the viewpoint But clipping assuming w c > 0 accomplishes this too

40 CS248 Lecture 9Kurt Akeley, Fall 2007 The “direction” of a projection Yes, we spoke of a view direction in eye coordinates Specifically, down the –z e axis, +x e to the right And yes, the plane of projection is perpendicular to the –z e 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): n 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. n 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 CS248 Lecture 9Kurt Akeley, Fall 2007 Projection does not imply viewing direction!

42 CS248 Lecture 9Kurt Akeley, Fall 2007 Wide field-of-view display Assume equal-size pixels Problem: n Center-field pixels are most important (foveal gaze) n But wide-field pixels have much greater “resolution”

43 CS248 Lecture 9Kurt Akeley, Fall 2007 Ratio of perceived pixel sizes Field of view (degrees) Ratio of perceived size of center pixel to edge pixel

44 CS248 Lecture 9Kurt Akeley, Fall 2007 Piece-wise linear projection Note: there is one view direction, but three planes of projection

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

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

47 CS248 Lecture 9Kurt Akeley, Fall 2007 End


Download ppt "Viewing and Perspective Kurt Akeley CS248 Lecture 9 23 October 2007"

Similar presentations


Ads by Google