CS 325 Introduction to Computer Graphics 03 / 08 / 2010 Instructor: Michael Eckmann.

Slides:



Advertisements
Similar presentations
Computer Graphics - Rasterization -
Advertisements

Computer Graphics CLIPPING.
3D Clipping & Viewing process
Objectives Define Clipping Various clipping methods. Line clipping methods.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
Computer Graphics Lecture 8 Arbitrary Viewing II: More Projection, Clipping and Mathematics of 3D Viewing.
10/10/02 (c) 2002 University of Wisconsin, CS 559 Last Time Finished viewing: Now you know how to: –Define a region of space that you wish to view – the.
Hidden Surface Removal CSE 581. Visibility Assumption: All polygons are opaque What polygons are visible with respect to your view frustum?  Outside:
CHAPTER 12 Height Maps, Hidden Surface Removal, Clipping and Level of Detail Algorithms © 2008 Cengage Learning EMEA.
Viewing & Clipping In 2D. 2 of 44 Contents Windowing Concepts Clipping –Introduction –Brute Force –Cohen-Sutherland Clipping Algorithm Area Clipping –Sutherland-Hodgman.
CMPE 466 COMPUTER GRAPHICS Chapter 8 2D Viewing Instructor: D. Arifler Material based on - Computer Graphics with OpenGL ®, Fourth Edition by Donald Hearn,
Introduction to Computer Graphics Chapter 6 – 2D Viewing Pt 2 1.
Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 111 Today’s class Clipping Parametric and point-normal form of lines Intersecting.
Chapter 6: Vertices to Fragments Part 2 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley Mohan Sridharan Based on Slides.
Vertices and Fragments I CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
CS 325 Introduction to Computer Graphics 04 / 09 / 2010 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 02 / 24 / 2010 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 02 / 26 / 2007 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 04 / 06 / 2007 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 04 / 04 / 2007 Instructor: Michael Eckmann.
Vertices and Fragments III Mohan Sridharan Based on slides created by Edward Angel 1 CS4395: Computer Graphics.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Clipping.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Implementation I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Graphics Pipeline Clipping CMSC 435/634. Graphics Pipeline Object-order approach to rendering Sequence of operations – Vertex processing – Transforms.
Hidden Surface Removal
CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.
CS 450: Computer Graphics REVIEW: OVERVIEW OF POLYGONS
CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann.
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.
CS 325 Introduction to Computer Graphics 02 / 17 / 2010 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 04 / 26 / 2010 Instructor: Michael Eckmann.
CS 480/680 Computer Graphics Shading in OpenGL Dr. Frederick C Harris, Jr. Fall 2013.
Hidden Surface Removal 1.  Suppose that we have the polyhedron which has 3 totally visible surfaces, 4 totally invisible/hidden surfaces, and 1 partially.
Windows, Viewports, and Clipping
1Computer Graphics Implementation II Lecture 16 John Shearer Culture Lab – space 2
Implementation II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
CS 376 Introduction to Computer Graphics 02 / 23 / 2007 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 03 / 22 / 2010 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 03 / 21 / 2007 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 02 / 22 / 2010 Instructor: Michael Eckmann.
Implementation II.
CS 325 Introduction to Computer Graphics 02 / 26 / 2010 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 03 / 29 / 2010 Instructor: Michael Eckmann.
Computer Graphics I, Fall 2010 Implementation II.
1Computer Graphics Implementation 1 Lecture 15 John Shearer Culture Lab – space 2
Graphics Graphics & Graphical Programming Lecture 23 - Viewing & Clipping.
Visible surface determination. Problem outline Given a set of 3D objects and a viewing specification, we wish to determine which lines or surfaces are.
CS 325 Introduction to Computer Graphics 03 / 10 / 2010 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 02 / 21 / 2007 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 04 / 07 / 2010 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 02 / 14 / 2007 Instructor: Michael Eckmann.
Visible-Surface Detection Methods. To identify those parts of a scene that are visible from a chosen viewing position. Surfaces which are obscured by.
Lecture 9 From Vertices to Fragments. Objectives Introduce basic implementation strategies Clipping Rasterization hidden-surface removal.
Visible Surface Detection
Computer Graphics Implementation II
Computer Graphics CC416 Week 13 Clipping.
Transformations contd.
Computer Graphics Shading in OpenGL
3D rezanje 3D Clipping view frustrum clipping planes clipped.
3D Clipping.
Graphics Pipeline Clipping
3D Rendering Pipeline Hidden Surface Removal 3D Primitives
Computer Graphics : Viewing In 2D
Implementation II Ed Angel Professor Emeritus of Computer Science
Lecture 13 Clipping & Scan Conversion
© University of Wisconsin, CS559 Fall 2004
3D rezanje 3D Clipping view frustrum clipping planes clipped.
Clipping Clipping Sutherland-Hodgman Clipping
Implementation II Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

CS 325 Introduction to Computer Graphics 03 / 08 / 2010 Instructor: Michael Eckmann

Michael Eckmann - Skidmore College - CS Spring 2010 Today’s Topics Questions/comments? 3d view volume clipping Visible Surface determination –back face culling –depth buffer (aka z-buffer)‏

Michael Eckmann - Skidmore College - CS Spring 2010 View volume

Michael Eckmann - Skidmore College - CS Spring d Clipping The view volume on the last slide has 6 faces For a canonical view volume the faces are the on the following planes: x = z, x = -z, y = z, y = -z, z = z min, z = -1 the 2 vertical faces (the front and back clipping planes) are on z = z min, z = -1 the two side faces are on x = z, x = -z the top and bottom faces are on y = z, y = -z the view volume lives totally in -z, so which plane is the top face on? y = z or y = -z ?

Michael Eckmann - Skidmore College - CS Spring d Clipping Cohen Sutherland's extension into 3d from 2d. A six bit (as opposed to 4 in 2d) outcode is used here. 1 = true, 0 = false –Bit 1 = above view volume (y > -z)‏ –Bit 2 = below view volume (y < z)‏ –Bit 3 = right of view volume (x > -z)‏ –Bit 4 = left of view volume (x < z)‏ –Bit 5 = behind view volume (z < -1)‏ –Bit 6 = in front of view volume (z > z min )‏ This leads to 27 different outcode volumes See drawing on board.

Michael Eckmann - Skidmore College - CS Spring d Clipping Trivially accept if both endpoints have outcodes of Trivially reject if logical AND of the outcodes of the endpoints is NOT Calculate intersection with borders of clipping planes if can't trivially accept or reject.

Michael Eckmann - Skidmore College - CS Spring d Clipping the parametric equation of a line is: x = x 0 + t (x 1 – x 0 )‏ y = y 0 + t (y 1 – y 0 )‏ z = z 0 + t (z 1 – z 0 ), 0 <= t <= 1 Calculating the intersections of lines with the unit slope planes of the cvv is easy. For example, for the y = z plane, y 0 + t (y 1 – y 0 ) = z 0 + t (z 1 – z 0 ) and we can solve for t. We'll then know the y and z coordinates of the intersection (z = y), so just use t to find the x coordinate.

Michael Eckmann - Skidmore College - CS Spring d Clipping Then, once we have the x y and z coordinates of the intersection we can determine if the intersection is actually on a face of the view volume or the intersection is not on a face of the view volume –if the intersection is not on a face, then we exclude the portion of the line outside that plane (away from the view volume) and recalculate the region code of the intersection –if the intersection is on a face, we keep that intersection as a final endpoint and exclude the portion of the line outside that plane, recalculate region code too. Another nice feature of this algorithm is that when given two endpoints of the line segment and their region codes, even if we can't trivially accept or reject them, we can tell which planes they intersect (when corresponding bits are different.) Therefore, we only have to clip that line against those planes.

Michael Eckmann - Skidmore College - CS Spring d Clipping Calculating the intersections at unit slopes is easier than at arbitrary slopes, hence the decision to normalize to a canonical view volume. x = x 0 + t (x 1 – x 0 )‏ y = y 0 + t (y 1 – y 0 )‏ z = z 0 + t (z 1 – z 0 ), 0 <= t <= 1 Recall an arbitrary plane is Ax + By + Cz + D = 0 (the equation of a plane.) It should be obvious that more calculations are involved in finding the intersection of a line with an arbitrary plane than with simple planes like y = z, z = -1, etc.

Michael Eckmann - Skidmore College - CS Spring 2010 Visible Surface Determination Types Image precision for (each pixel in display)‏ { Find closest object that is pierced by the projector through that pixel Draw the pixel at the appropriate color in frame buffer } Object precision for (each object in world)‏ { Determine parts of object whose view is unobstructed by other parts of it or by other objects Save the visible parts } Go through all the visible parts and display at proper resolution in frame buffer Some combination of image and object precision

Michael Eckmann - Skidmore College - CS Spring 2010 Visible Surface Determination The visible surface determination algorithms we'll discuss are: Back Face Culling (removal)‏ Depth Buffer method (aka z-buffer)‏ –A-Buffer method Depth Sort BSP Tree Scanline Algorithm

Michael Eckmann - Skidmore College - CS Spring 2010 Back Face Culling (removal)‏ This is a technique to remove unseen faces (polygons) from convex, solid (completely closed) polyhedra If one polyhedron occludes another or if a polyhedron is concave then back face culling isn't enough to remove all the invisible surfaces. Example drawings on board. –A convex polyhedron –A concave polyhedron –A polyhedron that occludes another polyhedron

Michael Eckmann - Skidmore College - CS Spring 2010 Back Face Culling (removal)‏ If we are working in a Right Handed Coordinate system and we specify a polygon by listing its vertices in counter-clockwise order, we can determine whether or not it is back facing or front facing by doing the following: Compute the plane equation for a face with the surface normal pointing out of the front. End up with Ax+By+Cz+D with specific values for A B C and D. Recall that the plane equation will equal 0 if the x,y,z is on the plane, non-zero otherwise. For points behind the plane, the plane equation will be 0. Let's see how the normal vector and the plane equation can be calculated now.

Michael Eckmann - Skidmore College - CS Spring 2010 Back Face Culling (removal)‏ Given counter-clockwise order of vertices allows us to compute the normal to the plane defined by those vertices. The direction of the normal is important --- we want it to point out of the front face. Example: Given a rectangle with vertices P1, P2, P3, P4 in counterclockwise order to compute the normal to the plane that that rectangle is on, in the direction pointing out of its front face we can do the following: [P2 – P1] x [P4 – P1] Let's see a drawing on the board. Note well: To determine the direction of a vector when subtracting two points (a-b) the direction is from b to a (not a to b).

Michael Eckmann - Skidmore College - CS Spring 2010 Back Face Culling (removal)‏ So a general way to generate the normal vector with direction out of the front face, given counter-clockwise order of vertices, the two vectors V1 and V2 are: V1 = 2 nd vertex minus the 1 st vertex V2 = last vertex minus the 1 st vertex Then take cross product: V1 x V2 = N N is a normal vector to the plane containing the vertices and is in the direction pointing out of the front face.

Michael Eckmann - Skidmore College - CS Spring 2010 Back Face Culling (removal)‏ Now that we have N, the next step is to find the plane equation. How can we do that now?

Michael Eckmann - Skidmore College - CS Spring 2010 Back Face Culling (removal)‏ Now that we have N, the next step is to find the plane equation. How can we do that now? N = (A, B, C) so A, B and C are known. The plane equation is: Ax + By + Cz + D = 0. D is the only unknown. To find D, just plug in the coordinates of one of the vertices (x 1,y 1,z 1 ) and solve for D: D = - ( Ax 1 + By 1 + C z 1 )‏ Now we have the equation of the plane on which the polygon lies and the normal to that plane is pointing out of the front face.

Michael Eckmann - Skidmore College - CS Spring 2010 Back Face Culling (removal)‏ How do we use this plane equation now to determine if the polygon is front facing or backfacing (in relation to the PRP (or CoP))?

Michael Eckmann - Skidmore College - CS Spring 2010 Back Face Culling (removal)‏ How do we use this plane equation now to determine if the polygon is front facing or backfacing (in relation to the PRP (or CoP))? We plug in the PRP (Projection Reference Point) which is the Center of Projection (CoP) when dealing with perspective projections to the plane equation and if A*PRP x +B*PRP y +C*PRP z +D < 0 it is a backface and we remove it from processing.

Michael Eckmann - Skidmore College - CS Spring 2010 Back Face Culling (removal)‏ The text shows that we can simplify this idea by just taking the dot product of a View vector (in direction from PRP) and the Surface Normal to the plane containing the polygon and it's a backface if this dot product is > 0. That is, a polygon is a backface if V view ● N > 0. Why is that true?

Michael Eckmann - Skidmore College - CS Spring 2010 Back Face Culling (removal)‏ A polygon is a backface if V view ● N > 0. Why is that true? Recall: V1. V2 = |V1| |V2|cosA The only thing affecting the sign of the dot product is the cosA (note: the magnitudes are always positive)‏ When A = [0, 90), then cosA > 0 When A = (90, 180], then cosA < 0 When A = 90, cosA = 0 Let's see this on the drawing on the board.

Back Face Culling (removal)‏ Further simplification is when the View vector is parallel to (and in the direction of) the -z axis. That is, the negative z axis, and pointing away from the origin. THIS ONLY WORKS IF YOU TRANSFORM THE PERSPECTIVE TO PARALLEL!!! This simplification can be used if after we transformed our arbitrary view volume to the perspective canonical view volume we then transform the perspective canonical view volume to a parallel-projection canonical view volume. See handout (p275). If we do this, our projectors all have a direction of projection of [0,0,-1]. And so, if the z coordinate of the plane normal is < 0, then it is back facing. The z-coordinate of the plane normal in the next diagram is named C.