From Vertices to Fragments Lecture 9

advertisement
From Vertices to Fragments
Lecture 9
Objectives
 Introduce basic implementation strategies
 Clipping
 Rasterization
 hidden-surface removal
Basic implementation strategies
 In computer graphics, we start with an application program,
and we end with an image.
 We can consider this process as a black box whose inputs are
the vertices and states defined in the program—geometric
objects, attributes, camera specifications—and whose output
is an array of colored pixels in the frame buffer.
Required Tasks
 There are four major tasks that any graphics system must




perform to render a geometric entity, such as a threedimensional polygon, as that entity passes from definition in
a user program to possible display on an output device:
1. Modeling
2. Geometry processing
3. Rasterization
4. Fragment processing
.
 Figure 6.3 shows how these tasks might be organized in a
pipeline implementation . Regardless of the approach, all
four tasks must be carried out.
Modeling
 The usual results of the modeling process are sets of vertices
that specify a group of geometric objects supported by the
rest of the system.
 We can look at the modeler as a black box that produces
geometric objects and is usually a user program.
.
 There are other tasks that the modeler might perform, for
example, clipping: the process of eliminating parts of objects
that cannot appear on the display because they lie outside the
viewing volume.
Geometry processing
 Geometry processing works with vertices. The goals of the
geometry processor are to determine which geometric
objects can appear on the display and to assign shades or
colors to the vertices of these objects.
 Four processes are required: projection , primitive assembly,
clipping, and shading.
Geometry processing
 The first step in geometry processing is to change
representations from object coordinates to camera or eye
coordinates using the model-view transformation.
 The second step is to transform vertices using the projection
transformation from VCS (View Coordinates System) to a
NDCS (Normalized Device Coordinates System ) in which
objects that might be visible are contained in a cube centered
at the origin. Vertices are now represented in clip coordinates
Geometry processing
 Geometric objects are transformed by a sequence of
transformations that may reshape and move them (modeling)
or may change their representations (viewing).
front-end processing
 View volume
primitives that fit within a specified volume, and can appear
on the display after rasterization.
 primitive assembly
The process of grouping vertices into objects before clipping
can take place.
front-end processing
 hidden-surface removal
Note that even though an object lies inside the view
volume, it will not be visible if it is obscured by other
objects. Algorithms for hidden-surface removal
or visible-surface determination are based on the threedimensional spatial relationships among objects.
 This step is normally carried out as part of fragment
processing.
Rasterisation
 Rasterisation is the task of taking an image described in a vector
graphics format (shapes) and converting it into a raster image
(pixels or dots) for output on a video display or printer, or for
storage in a bitmap file format . It the transformation of geometric
primitives (line segments, circles, polygons) into a raster image
representation, i. e. pixel positions the estimation of an
appropriate set of pixel positions to represent a geometric
primitive.
Clipping
 The process of determining which primitives, or parts
of primitives , fit within the clipping or view volume defined
by the application program.
 We shall concentrate on clipping of line segments and
polygons because they are the most common primitives to
pass down the pipeline.
Line-segment clipping
 A clipper decides which primitives, or parts of primitives,
can possibly appear on the display and be passed on to the
rasterizer. Primitives that fit within the specified view
volume pass through the clipper, or are accepted.
 Primitives that cannot appear on the display are eliminated,
or rejected or culled.
 Primitives that are only partially within the view volume
must be clipped such that any part lying outside the volume
is removed.
Clipping
 Easy for line segments and polygons
 Hard for curves and text
 Convert to lines and polygons first
Clipping 2D Line Segments
 Brute force approach: compute intersections with all sides of
clipping window
 Inefficient: one division per intersection
Line Clipping
 Line clipping operations should comprise the following cases:
 Totally plotted.
 Partially plotted.
 Not plotted at all
Line Clipping
 Note that even though neither of two vertices is within the





window , certain part of the line segment may be still within
.
There are many different techniques for clipping line in 2D:
The fundamental are :
1-Line equation
2-Intersection computation
Next we will discuss Cohen-Sutherland Algorithm.
Cohen-Sutherland Algorithm
 It is not the most efficient algorithm .
 It is the most commonly used .
 The key technique is 4 bit code
 TBRL where:
 T is set (to 1 ) if y > top
 B is set (to 1 ) if y < Bottom
 R is set (to 1 ) if x > right
 L is set (to 1 ) if x < left
Cohen-Sutherland Algorithm
 Idea: eliminate as many cases as possible without computing
intersections
 Start with four lines that determine the sides of the clipping
window
y = ymax
x = xmin
x = xmax
y = ymin
21
The Cases
 Case 1: both endpoints of line segment inside all four lines
 Draw (accept) line segment as is
y = ymax
x = xmin
x = xmax
y = ymin
 Case 2: both endpoints outside all lines and on same side
of a line
 Discard (reject) the line segment
22
The Cases
 Case 3: One endpoint inside, one outside
 Must do at least one intersection
 Case 4: Both outside
 May have part inside
 Must do at least one intersection
y = ymax
x = xmin
23
x = xmax
Defining Outcodes
 The first bit is set to 1 if the point is above the viewport eg
1001
 The Second bit is set to 1 if the point is under the viewport eg 0101
 The third bit is set to 1 if the point is right the viewport eg
0010
 The forth bit is set to 1 if the point is left the viewport eg
0001
24
E © Addison-4Angel: Interactive Computer Graphics
2005Wesley
Using Outcodes
 Consider the 5 cases below
 AB: outcode(A) = outcode(B) = 0
 Accept line segment
25
E © Addison-4Angel: Interactive Computer Graphics
2005Wesley
Using Outcodes
 CD: outcode (C) = 0, outcode(D)  0
 Compute intersection
 Location of 1 in outcode(D) determines which edge to intersect
with
 Note if there were a segment from A to a point in a region with
2 ones in outcode, we might have to do two interesections
26
E © Addison-4Angel: Interactive Computer Graphics
2005Wesley
Using Outcodes
 EF: outcode(E) logically ANDed with outcode(F) (bitwise) 
0
 Both outcodes have a 1 bit in the same place
 Line segment is outside of corresponding side of clipping
window
 reject
27
E © Addison-4Angel: Interactive Computer Graphics
2005Wesley
Using Outcodes
 GH and IJ: same outcodes, neither zero but logical AND
yields zero
 Shorten line segment by intersecting with one of sides of
window
 Compute outcode of intersection (new endpoint of
shortened line segment)
 Re-execute algorithm
28
E © Addison-4Angel: Interactive Computer Graphics
2005Wesley
Efficiency
 In many applications, the clipping window is small relative to
the size of the entire data base
 Most line segments are outside one or more sides of the
window and can be eliminated based on their outcodes
 Inefficiency when code has to be re-executed for line
segments that must be shortened in more than one step
29
E © Addison-4Angel: Interactive Computer Graphics
2005Wesley
Cohen Sutherland in 3D
 Use 6-bit outcodes
 When needed, clip line segment against planes
30
E © Addison-4Angel: Interactive Computer Graphics
2005Wesley
Polygon Clipping
 Not as simple as line segment clipping
 Clipping a line segment yields at most one line segment
 Clipping a polygon can yield multiple polygons
 However, clipping a convex polygon can yield at most one
other polygon
31
E © Addison-4Angel: Interactive Computer Graphics
2005Wesley
Pipeline Clipping of Polygons
 Three dimensions: add front and back clippers
 Strategy used in SGI(Silicon Graphics International) Geometry
Engine.
 Small increase in latency
32
E © Addison-4Angel: Interactive Computer Graphics
2005Wesley
Bounding Boxes
 Rather than doing clipping on a complex polygon, we can
use an axis-aligned bounding box or extent
 Smallest rectangle aligned with axes that encloses the polygon
 Simple to compute: max and min of x and y
33
E © Addison-4Angel: Interactive Computer Graphics
2005Wesley
Bounding Boxes
Can usually determine accept/reject based only on bounding
box
reject
accept
requires detailed
clipping
34
Download