Presentation is loading. Please wait.

Presentation is loading. Please wait.

02/26/02 (c) 2002 University of Wisconsin, CS 559 Last Time Canonical view pipeline Orthographic projection –There was an error in the matrix for taking.

Similar presentations


Presentation on theme: "02/26/02 (c) 2002 University of Wisconsin, CS 559 Last Time Canonical view pipeline Orthographic projection –There was an error in the matrix for taking."— Presentation transcript:

1 02/26/02 (c) 2002 University of Wisconsin, CS 559 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

2 02/26/02 (c) 2002 University of Wisconsin, CS 559 Today Perspective viewing –Simple case –Completely general case

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

4 02/26/02 (c) 2002 University of Wisconsin, CS 559 Distant Objects Are Smaller

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

6 02/26/02 (c) 2002 University of Wisconsin, CS 559 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

7 02/26/02 (c) 2002 University of Wisconsin, CS 559 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

8 02/26/02 (c) 2002 University of Wisconsin, CS 559 Basic Perspective Projection If you know P(x v,y v,z v ) and d, what is P(x s,y s )? –Where does a point in view space end up on the screen? xvxv yvyv -z v d P(x v,y v,z v ) P(x s,y s )

9 02/26/02 (c) 2002 University of Wisconsin, CS 559 Basic Case Similar triangles gives: yvyv -z v P(x v,y v,z v ) P(x s,y s ) View Plane d

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

11 02/26/02 (c) 2002 University of Wisconsin, CS 559 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: z v =n, z v =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

12 02/26/02 (c) 2002 University of Wisconsin, CS 559 Clipping Planes xvxv -z v Near Clip Plane Far Clip Plane View Volume Left Clip Plane Right Clip Plane f n l r

13 02/26/02 (c) 2002 University of Wisconsin, CS 559 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

14 02/26/02 (c) 2002 University of Wisconsin, CS 559 Clipping Planes xvxv -z v Near Clip Plane Far Clip Plane View Volume Left Clip Plane Right Clip Plane f FOV

15 02/26/02 (c) 2002 University of Wisconsin, CS 559 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

16 02/26/02 (c) 2002 University of Wisconsin, CS 559 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 (l,b,n) (r,t,n) (l,b,n) (r,t,n)

17 02/26/02 (c) 2002 University of Wisconsin, CS 559 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

18 02/26/02 (c) 2002 University of Wisconsin, CS 559 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

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

20 02/26/02 (c) 2002 University of Wisconsin, CS 559 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:

21 02/26/02 (c) 2002 University of Wisconsin, CS 559 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

22 02/26/02 (c) 2002 University of Wisconsin, CS 559 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

23 02/26/02 (c) 2002 University of Wisconsin, CS 559 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)

24 02/26/02 (c) 2002 University of Wisconsin, CS 559 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 3D must be > -1 –In homogeneous screen space, same as: x screen > -w screen In general, a point, p, is “inside” a plane if: –You represent the plane as n x x+n y y+n z z+d=0, with (n x,n y,n z ) pointing inward –And n x p x +n y p y +n z p z +d>0

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

26 02/26/02 (c) 2002 University of Wisconsin, CS 559 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?)

27 02/26/02 (c) 2002 University of Wisconsin, CS 559 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…

28 02/26/02 (c) 2002 University of Wisconsin, CS 559 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

29 02/26/02 (c) 2002 University of Wisconsin, CS 559 Sutherland-Hodgman (4) InsideOutside s p Output p InsideOutside s p Output i InsideOutside s p No output InsideOutside s p Output i,p i i

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

31 02/26/02 (c) 2002 University of Wisconsin, CS 559 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

32 02/26/02 (c) 2002 University of Wisconsin, CS 559 Inside/Outside in Screen Space In screen space, clip planes are x s =±1, y s =±1, z s =0, z s =1 Inside/Outside reduces to comparisons before perspective divide

33 02/26/02 (c) 2002 University of Wisconsin, CS 559 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)

34 02/26/02 (c) 2002 University of Wisconsin, CS 559 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


Download ppt "02/26/02 (c) 2002 University of Wisconsin, CS 559 Last Time Canonical view pipeline Orthographic projection –There was an error in the matrix for taking."

Similar presentations


Ads by Google