Download presentation
Presentation is loading. Please wait.
Published byKory King Modified over 9 years ago
1
Vertices and Fragments I CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel
2
Objectives Chapter 7. Implementation of rendering pipeline. – Clipping: viewing volume. – Rasterization: fragments from valid objects. – Hidden-surface removal: occlusions, blocked surfaces. This lecture: – Clipping. – Scan conversion. CS4395: Computer Graphics 2
3
Overview At end of the geometric pipeline, vertices have been assembled into primitives. Must clip out primitives that are outside the view frustum: – Algorithms represent primitives by lists of vertices. Must compute pixels that can be affected by each primitive: – Fragment generation. – Rasterization or scan conversion. CS4395: Computer Graphics 3
4
Required Tasks Clipping. Rasterization or scan conversion. Transformations. Some tasks deferred until fragment processing: – Hidden surface removal. – Anti-aliasing. CS4395: Computer Graphics 4
5
Rasterization Meta Algorithms Consider two approaches to render a scene with opaque objects. For every pixel, determine object that projects on the pixel and is closest to the viewer. Compute the shade of this pixel. – Ray tracing paradigm. For every object, determine pixels it covers and shade them: – Pipeline approach. – Must keep track of depths. CS4395: Computer Graphics 5
6
Clipping 2D against clipping window. 3D against clipping volume. Easy for line segments and polygons. Hard for curves and text: – Convert to lines and polygons first CS4395: Computer Graphics 6
7
Clipping 2D Line Segments Brute force approach: compute intersections with all sides of clipping window. – Inefficient: one division per intersection CS4395: Computer Graphics 7
8
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. CS4395: Computer Graphics 8 x = x max x = x min y = y max y = y min
9
The Cases Case 1: endpoints of line segment inside all four lines. – Draw (accept) the line segment. Case 2: endpoints outside all lines and on same side of a line. – Discard (reject) the line segment. CS4395: Computer Graphics 9 x = x max x = x min y = y max y = y min
10
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. CS4395: Computer Graphics 10 x = x max x = x min y = y max
11
Defining Outcodes For each endpoint, define an outcode: Outcodes divide space into 9 regions. Computation of outcode requires at most 8 subtractions per line segment. CS4395: Computer Graphics 11 b0b1b2b3b0b1b2b3 b 0 = 1 if y > y max, 0 otherwise b 1 = 1 if y < y min, 0 otherwise b 2 = 1 if x > x max, 0 otherwise b 3 = 1 if x < x min, 0 otherwise
12
Using Outcodes Consider the 5 cases below. AB: outcode(A) = outcode(B) = 0000. – Accept line segment. CS4395: Computer Graphics 12
13
Using Outcodes CD: outcode (C) = 0000, outcode(D) 0 (0010). – 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 intersections. CS4395: Computer Graphics 13
14
Using Outcodes EF: outcode(E) logically ANDed with outcode(F) (bitwise) 0. – Both outcodes have a 1 bit in the same place (0010, 0010). – Line segment is outside of corresponding side of clipping window. – Reject. CS4395: Computer Graphics 14
15
Using Outcodes GH, IJ have similar outcodes: (1001, 1000) and (0001, 1000). – Reject GH but what about IJ (logical AND returns zero) ? Shorten line segment by intersecting with sides of window. Compute outcode of intersection (new endpoint of shortened line segment). Re-execute algorithm. CS4395: Computer Graphics 15
16
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 side 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. CS4395: Computer Graphics 16
17
Cohen Sutherland in 3D Use 6-bit outcodes. When needed, clip line segment against planes. CS4395: Computer Graphics 17
18
Liang-Barsky Clipping Consider the parametric form of a line segment: As parameter changes from 0 to 1, move from p 1 to p 2. We can distinguish between the cases by looking at the values of where the extended line segment crosses the lines that determine the window. CS4395: Computer Graphics 18 p1p1 p2p2
19
Liang-Barsky Clipping In (a): 4 > 3 > 2 > 1 – Intersect right, top, left, bottom: shorten. In (b): 4 > 2 > 3 > 1 – Intersect right, left, top, bottom: reject. CS4395: Computer Graphics 19
20
Advantages Can accept or reject as easily as with Cohen- Sutherland. Using values of , we do not have to use algorithm recursively as with C-S. Extends to 3D. CS4395: Computer Graphics 20
21
Clipping and Normalization General clipping in 3D requires intersection of line segments against arbitrary plane. Example: oblique view. CS4395: Computer Graphics 21
22
Plane-Line Intersections CS4395: Computer Graphics 22
23
Normalized Form CS4395: Computer Graphics 23 before normalizationafter normalization Normalization is part of viewing (pre-clipping), but after normalization clip against sides of right parallelepiped. Typical intersection calculation now requires only a floating point subtraction, e.g. is x > x max ? top view
24
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. CS4395: Computer Graphics 24
25
Tessellation and Convexity Replace non-convex (concave) polygons with a set of triangular polygons (a tessellation). Also makes fill easier. Tessellation code in GLU library. CS4395: Computer Graphics 25
26
Line Clipping as a Black Box Consider line segment clipping as a process that takes in two vertices and produces either no vertices or the vertices of a clipped line segment. CS4395: Computer Graphics 26
27
Pipeline Clipping of Line Segments Clipping against each side of window is independent of other sides. Can use four independent clippers in a pipeline. CS4395: Computer Graphics 27
28
Pipeline Clipping of Polygons Three dimensions: add front and back clippers! Strategy used in SGI Geometry Engine. Small increase in latency. CS4395: Computer Graphics 28
29
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. CS4395: Computer Graphics 29
30
Bounding Boxes Can usually determine accept or reject decisions based only on bounding box. CS4395: Computer Graphics 30 reject accept requires detailed clipping
31
Clipping and Visibility Clipping has much in common with hidden-surface removal. In both cases, we are trying to remove objects that are not visible to the camera. Often we can use visibility or occlusion testing early in the process to eliminate as many polygons as possible before going through the entire pipeline. CS4395: Computer Graphics 31
32
Summary More information: Sections 7.4-7.7. What next: – Rasterization. – Hidden surface removal. CS4395: Computer Graphics 32
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.