CS 330 Programming Languages 12 / 05 / 2006 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 03 / 08 / 2010 Instructor: Michael Eckmann.
-
Upload
felicity-rodgers -
Category
Documents
-
view
216 -
download
0
Transcript of CS 325 Introduction to Computer Graphics 03 / 08 / 2010 Instructor: Michael Eckmann.
CS 325Introduction to Computer Graphics
03 / 08 / 2010
Instructor: Michael Eckmann
Michael Eckmann - Skidmore College - CS 325 - 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 325 - Spring 2010
View volume
Michael Eckmann - Skidmore College - CS 325 - Spring 2010
3d 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 = zmin
, 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 325 - Spring 2010
3d 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 325 - Spring 2010
3d Clipping• Trivially accept if both endpoints have outcodes of
000000.
• Trivially reject if logical AND of the outcodes of the
endpoints is NOT 000000.
• Calculate intersection with borders of clipping planes if
can't trivially accept or reject.
Michael Eckmann - Skidmore College - CS 325 - Spring 2010
3d Clipping• the parametric equation of a line is:
• x = x0 + t (x
1 – x
0)
• y = y0 + t (y
1 – y
0)
• z = z0 + 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, y0 + t (y
1 – y
0) = z
0 + t (z
1 –
z0) 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 325 - Spring 2010
3d 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 325 - Spring 2010
3d 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 = y0 + t (y
1 – y
0)
• z = z0 + 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 325 - Spring 2010
Visible Surface Determination• Types
• Image precisionfor (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 precisionfor (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 325 - 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 325 - 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 325 - 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. For points in front, plane equation is > 0.
• Let's see how the normal vector and the plane equation can be
calculated now.
Michael Eckmann - Skidmore College - CS 325 - 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 325 - 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 = 2nd vertex minus the 1st vertex
• V2 = last vertex minus the 1st 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 325 - 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 325 - 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 (x1,y
1,z
1) and solve for D:
• D = - ( Ax1 + 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 325 - 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 325 - 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*PRPx+B*PRP
y+C*PRP
z+D < 0 it is a
backface and we remove it from processing.
Michael Eckmann - Skidmore College - CS 325 - 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 Vview
● N > 0.
• Why is that true?
Michael Eckmann - Skidmore College - CS 325 - 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.