COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

Similar documents
Graphics and Interaction Rendering pipeline & object modelling

Renderer Implementation: Basics and Clipping. Overview. Preliminaries. David Carr Virtual Environments, Fundamentals Spring 2005

Incremental Form. Idea. More efficient if we look at d k, the value of the decision variable at x = k

Chapter 8: Implementation- Clipping and Rasterization

From Vertices to Fragments: Rasterization. Reading Assignment: Chapter 7. Special memory where pixel colors are stored.

Graphics (Output) Primitives. Chapters 3 & 4

Scan Conversion. CMP 477 Computer Graphics S. A. Arekete

Lecture outline Graphics and Interaction Scan Converting Polygons and Lines. Inside or outside a polygon? Scan conversion.

Announcements. Midterms graded back at the end of class Help session on Assignment 3 for last ~20 minutes of class. Computer Graphics

OpenGL Graphics System. 2D Graphics Primitives. Drawing 2D Graphics Primitives. 2D Graphics Primitives. Mathematical 2D Primitives.

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

COMP371 COMPUTER GRAPHICS

COMP30019 Graphics and Interaction Rendering pipeline & object modelling

Lecture outline. COMP30019 Graphics and Interaction Rendering pipeline & object modelling. Introduction to modelling

Computer Graphics 7 - Rasterisation

Rasterization, or What is glbegin(gl_lines) really doing?

Rasterization: Geometric Primitives

CS 248 Assignment 2 Polygon Scan Converter. CS248 Presented by Abe Davis Stanford University October 17, 2008

(Refer Slide Time: 00:02:00)

The Traditional Graphics Pipeline

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

From Ver(ces to Fragments: Rasteriza(on

UNIT 2 GRAPHIC PRIMITIVES

Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling

Polygon Filling. Can write frame buffer one word at time rather than one bit. 2/3/2000 CS 4/57101 Lecture 6 1

The Traditional Graphics Pipeline

The Traditional Graphics Pipeline

Chapter 3. Sukhwinder Singh

Computer Graphics. - Rasterization - Philipp Slusallek

Visibility: Z Buffering

CSC Computer Graphics

Einführung in Visual Computing

Topic #1: Rasterization (Scan Conversion)

Scan Conversion. Drawing Lines Drawing Circles

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14

Overview. Pipeline implementation I. Overview. Required Tasks. Preliminaries Clipping. Hidden Surface removal

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Hidden surface removal. Computer Graphics

CS 543: Computer Graphics. Rasterization

Output Primitives Lecture: 3. Lecture 3. Output Primitives. Assuming we have a raster display, a picture is completely specified by:

CEng 477 Introduction to Computer Graphics Fall 2007

Werner Purgathofer

Hidden Surfaces II. Week 9, Mon Mar 15

Department of Computer Sciences Graphics Fall 2003 (Lecture 2) Pixels

Topics. From vertices to fragments

(Refer Slide Time: 00:03:51)

Computer Graphics and GPGPU Programming

8. Hidden Surface Elimination

2D Graphics Primitives II. Additional issues in scan converting lines. 1)Endpoint order. Want algorithms to draw the same pixels for each line

From Vertices To Fragments-1

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

4.5 VISIBLE SURFACE DETECTION METHODES

Visible-Surface Detection Methods. Chapter? Intro. to Computer Graphics Spring 2008, Y. G. Shin

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Computer Graphics

CS 130 Final. Fall 2015

CSCI 420 Computer Graphics Lecture 14. Rasterization. Scan Conversion Antialiasing [Angel Ch. 6] Jernej Barbic University of Southern California

Fall CSCI 420: Computer Graphics. 7.1 Rasterization. Hao Li.

8. Hidden Surface Elimination

Lets assume each object has a defined colour. Hence our illumination model is looks unrealistic.

Clipping. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

CSCI 4620/8626. Coordinate Reference Frames

EF432. Introduction to spagetti and meatballs

CHAPTER 1 Graphics Systems and Models 3

Rasterization. Rasterization (scan conversion) Digital Differential Analyzer (DDA) Rasterizing a line. Digital Differential Analyzer (DDA)

Computer Graphics (CS 543) Lecture 10: Rasterization and Antialiasing

CS 248 Assignment 2 Polygon Scan Conversion. CS248 Presented by Michael Green Stanford University October 20, 2004

Identifying those parts of a scene that are visible from a chosen viewing position, and only process (scan convert) those parts

Institutionen för systemteknik

CS 4204 Computer Graphics

Tópicos de Computação Gráfica Topics in Computer Graphics 10509: Doutoramento em Engenharia Informática. Chap. 2 Rasterization.

RASTERIZING POLYGONS IN IMAGE SPACE

CS488 2D Graphics. Luc RENAMBOT

Midterm Exam Fundamentals of Computer Graphics (COMP 557) Thurs. Feb. 19, 2015 Professor Michael Langer

1 Introduction to Graphics

Rendering. Basic Math Review. Rasterizing Lines and Polygons Hidden Surface Remove Multi-pass Rendering with Accumulation Buffers.

From 3D World to 2D Screen. Hendrik Speleers

Triangle Rasterization

Visible Surface Detection Methods

Line Drawing. Introduction to Computer Graphics Torsten Möller / Mike Phillips. Machiraju/Zhang/Möller

Chapter - 2: Geometry and Line Generations

CS4620/5620: Lecture 14 Pipeline

Display Technologies: CRTs Raster Displays

Computer Graphics. Lecture 9 Hidden Surface Removal. Taku Komura

9. Visible-Surface Detection Methods

Pipeline Operations. CS 4620 Lecture 10

Course Title: Computer Graphics Course no: CSC209

The Graphics Pipeline. Interactive Computer Graphics. The Graphics Pipeline. The Graphics Pipeline. The Graphics Pipeline: Clipping

Realtime 3D Computer Graphics Virtual Reality

CSCI 4620/8626. Computer Graphics Clipping Algorithms (Chapter 8-5 )

Introduction to Computer Graphics (CS602) Lecture 05 Line Drawing Techniques

Computer Graphics 10 - Shadows

CS488. Visible-Surface Determination. Luc RENAMBOT

Digital Differential Analyzer Bresenhams Line Drawing Algorithm

Computer Graphics. Bing-Yu Chen National Taiwan University

CS602 Midterm Subjective Solved with Reference By WELL WISHER (Aqua Leo)

Line Drawing. Foundations of Computer Graphics Torsten Möller

MET71 COMPUTER AIDED DESIGN

In today s lecture we ll have a look at: A simple technique The mid-point circle algorithm

CS 4731: Computer Graphics Lecture 21: Raster Graphics: Drawing Lines. Emmanuel Agu

Transcription:

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines Department of Computer Science and Software Engineering The

Lecture outline Introduction Scan conversion Scan-line algorithm Edge coherence Bresenham s algorithm Edge coherence (revisited) Z buffering High Performance Visible Surface Detection

Scan conversion How are polygons and lines drawn onto a digital image? Aim: understanding polygonal filling and line drawing algorithms. Reading: Foley Sections 3.2 Scan converting lines and Section 3.5 Filling polygons. Additional reading: 3.3 Scan converting circles.

Inside or outside a polygon? Filling polygons requires a way of determining whether a point is inside or outside a polygon. See if you can think up a technique for determining whether you are inside or outside a two-dimensional polygon from a completely arbitrary point (imagine you have no way of knowing whether you are inside or out initially)? Hint: imagine you are standing at a point q and watching another point p that can reside at any vertex of polygon P.

Filling polygons using winding numbers Filling polygons requires a way of determining whether a point is inside or outside a polygon. One technique is known as winding numbers. Imagine you are standing at a point q while watching another point p traverse a polygon P counterclockwise (the point moves from vertex to vertex around the perimeter of the polygon). If q is inside, you would turn a full circle, 2π radians, if q is outside the sum of your total angular turn will be zero 0.

The winding number of q with respect to P is the number of revolutions point p makes around polygon P: the total signed angular turn divided by 2π. q P For polygon P, exterior points q have winding number 0: a total angular turn of 0.

Angle θ can be determined from dot or cross project v i v i+1 = v i v i+1 cosθ i and P[i+1] e v i v i+1 = v i v i+1 sinθ i P[i] V i+1 i v i q Angle θ i is the angle subtended by e from q

The odd-even test The odd-even test follow an arbitrary ray or along scan line and count the number of times a boundary is crossed, either an odd or even number of times.

Describe each of the two coloured lines and which direction they are going in and what happens to their parity. notice for the top most line starting outside and skimming the top of the polygon, it stays outside because the single pixel is a special case of a horizontal line (more in next slides).

Selection of inside model Let s now compare the winding-number model to the odd-even test model according to our desidera for issues in numerical methods (numerical precision and computational complexity). Winding numbers work in case when q lies on the perimeter of P, but the odd-even case needs to treat these as special case (e.g. when horizontal scan line intersects a horizontal polygonal edge). However, winding numbers require floating point numbers that is the winding angle will not always be 0 or 2π because of round-off error.

In terms of computational complexity, both algorithms are of order O(n) in the worst case, where n is the number of polygon vertices for winding numbers of pixels for the odd-even test. However, the winding-number algorithm depends critically on floating-point computations and trigonometric computations, which is means it is significantly slower on standard hardware (up to 20 times slower according to research by Haines in 1992). For filling polygons in images, the odd-even test is superior as it only requires a parity bit and can be easily implemented by stepping along the scan lines of image rows and columns.

Scan-line filling The scan-line method is an efficient way of filling-in polygons, based on the odd-even test by crossing segments. Segments are sorted to allow for an orderly progression that determines whether inside or outside.

Figure 1.14 (Rowe), using scan line to determine the interior points of a polygon B C F scan line D A Question: does scan-line filling work for non-simple and multiple-boundary polygons? E

The first intersection occurs when the scan line crosses edge AB, so the parity becomes odd at that point. The second intersection occurs with edge AF, so the parity becomes even. We can therefore say that points along the scan line between edges AB and AF are interior, points between edges AF and EF are exterior, and points between EF and DE are interior. Scan-line filing does work for both non-simple and multiple boundary polygons (provided you start scanning from outside.

Basic scan-line algorithm 1. Find intersections of scan lines with edges of polygon(s) 2. Sort the intersections by increasing x coordinate 3. fill in-between pixel extrema using odd-even parity rule

Pixel extrema (a) (b) Span extrema Other pixels in the span

Special cases 1. Given an intersection with an arbitrary, fractional x value, how do we determine which pixel on either side of the intersection is interior? 2. How do we deal with intersections at integer pixel coordinates? 3. How do we deal with shared vertices? 4. How do we deal with horizontal edges?

Special case solutions 1. If inside and approaching fraction intersection to the right round x coordinate down; else if outside round up. 2. If leftmost pixel (has integer coordinate) define as interior; else if right most coordinate (has integer coordinate) define to be exterior. 3. Count the y min vertex of an edge in parity but not the y max vertex (therefore vertex y max is only drawn if it is the y min vertex for the adjacent edge) For example vertex A in 3.14, is counted one in the parity calculation because it is the y min vertex for edge FA but the y max vertex for edge AB (Thus, both edges and spans are treated as intervals that are closed at their minimum value and open at their maximum value).

Horizontal edges G F I H E J C D A B

The bucket-sorted edge table right for the polygon on the left (Foley Figures 3.14 and 3.18). 12 10 8 6 4 2 D F Scan line a b c d E C A B y coordinate 11 10 9 8 7 6 5 4 3 2 l l l l l l l EF DE 5 6 9 7 2 11 7 4 CD 11 13 0 AB l FA 9 2 0 l BC l 2 4 6 8 10 12 14 1 0 l y max 3 7 x min 5 2 1 m 5 7 6 4 l

Active edge table for scan line 9 (above) and 10 (below) (Foley Figures 3.14 and 3.19). 12 10 8 6 4 2 D F Scan line a b c d E C A B 2 4 6 8 10 12 14 AET pointer FA 9 2 0 y 1 max x m EF DE CD 5 6 9 2 2 11 10 11 13 0 l 4 AET pointer DE 11 12 6 4 (a) (b) CD 11 13 0 l

Need to fill discreet pixel locations, but don t want to have to check all edges from all polygons for large scenes - would take too much computationally! Therefore sort edge locations based on x and y coordinates and use a hash-table like approach of retrieving them, relative to what location you are presently scanning (or filling). Foley s Figure 3.18 is shown along side figure 3.14 to indicate the associated bucket-sorted edge table generated (ahead of actual filling operation) for this polygon.

Scan-line polygon filling algorithm 1 Create a data structure for edges, containing the minimum and maximum y values (y min and y max, respectively) for each edge, and the x value corresponding to y min, called x min. 2 Create an edge table in which the edges are listed, sorted in ascending order by their y min value. Omit any horizontal edges from the table. 3 Set scan line value y scan to the minimum y min value for all edges (that is, to the lowest y value reached by the polygon). 4 Create an active edge table, containing all the edges currently intersected by the scan line. 5 Add to the active edge table (and delete from the master edge table) any edges whose y min value is equal to the current y scan.

Scan-line polygon filling algorithm 6 Sort the active edge table in ascending order on x. 7 Traverse active edge table, taking pairs of edges and drawing all pixels between x value for the first edge in a pair and the x value in the second edge in the same pair. 8 Move to the next scan line by incrementing y scan by 1. 9 Delete any edges from the active edge table if their y max value is equal to y scan. 10 Determine where scan line intersects edge (see edge coherence slide in next lecture). 11 While either master edge table or the active edge table has edges, goto step 5.

Define a data structure for representing an edge. It must be remembered that x min is not necessarily the minimum x value on the edge it is the x value that corresponds to the point with minimum y value. The edge table lists edges, as represented by the data structures defined in step 1. In practice, an array or linked list is used for the edge table. (Omitting horizontal edges, like in previous diagram, treat as a special outside case). This is easily done by taking the y min value from the first entry in the edge table, since the table was sorted on y min. We begin scanning the polygon at this point (only start scanning at top of polygon). Like the original edge table, this second active edge table is usually implemented as an array or linked list (only need to do this once).

Edges are therefore distributed between active edge table and master edge table (loops from step 11, so do this at beginning of each scan line). Sorting the edges in the active edge table means they are listed in the order that they are intersected by the scan line (as it travels left to right). Traversing active edge table For example, with the scan line positioned as shown in Fig 1.14, pixels along this line between edges AB and AF would be drawn from the first pair of edges in the active edge table, then pixels between EF and ED. (Note that the active edge table will always contain an even number of edges). Move to next scan line.

Delete edges from active edge table Note that we do not draw the pixel corresponding to the y max value before deleting the edge this is consistent with the rule ed in determining the parity of a pixel. Determine edge coherence Repeat algorithm by going back to step 5 and repeating, while either master edge table or the active edge table has edges.

Edge coherence Many edges that intersect scan line i also intersect scan line i + 1 Can incrementally calculate intersection x i+1 = x i + a m, where m is the slope of the edge Can avoid fractional arithmetic by computing an integer decision variable and checking only its sign to decide when to increment x (as we will see later in lecture)

Scan converting lines Involves turning on the correct pixels, either in display or in [ an ] x0 image. Assume line segment is described by its start point y [ ] 0 x1 and end point. y 1

First attempt Choose function y = mx + b, and use the following basic iterative algorithm that steps through the range of x values [x 0..x 1 ]: For each x compute corresponding (real) y value from the line equation. Round that y value to the nearest [ ] pixel (grid) position and x switch on, or set pixel at that position. y

Example: Drawing y = 7x + 2 (Rowe fig 1.4). (0,40) Increasing x Increasing y First, the problem that floating point arithmetic is computationally complex therefore slow to compute, particularly since this needs to be done very frequently, and Second, the problem of discretisation in determining which pixel to turn on, one or both?

The problem: a line with slope m > 1 will have gaps in it. Solution: m > 1 draw x as function of y m 1 draw y as function of x (as above)

Refinement Reduce line generation to one very special case, like 0 m 1 Handle all other cases as symmetries of the special case, by parameterised subroutines explicit transformations duplicating code Leads to kind of line generation algorithm where step is always 0 or 1. Further refinement: Bresenham s algorithm and variants only integer arithmetic, only addition/ subtraction.

Bresenham s algorithm Bresenham s insight was to step horizontally, accumulating error until error gets big enough to force a step upwards. For integer coordinates all quantities are ratios with 2 or x = x 1 x 0 in the denominator, multiplying everything by 2 x, makes everything integer. Essential insight: For integer coordinates, all quantities are ratios with 2 or x = x 1 x 0 in the denominator. Multiplying everything by 2 x, makes everything integer. Step horizontally, accumulating error, until error gets big enough to force a step upwards.

At each step, choose between two pixels based on the sign of the decision variable calculated in the previous iteration: then it updates the decision variable by adding the error to the old value, depending on the choice of pixel.

The recursive problem Assuming starting point (x 0, y 0 ) is provided, the recursive problem is given (x k, y k ) to find y value for subscript position x k + 1, y = m(x k + 1) + b y is either y k or y k + 1, assuming that algorithm is drawing line from left to right as in first case (positive slope < 1). Initially, y = mx k + b, next row we get y = m(x k + 1) + b and either y = y + k or y = y k + 1.

d 2 y k + 1 (x k, y k ) d 1 y k d 1 = y y k = m(x k + 1) + b y k d 2 = y k + 1 y = y k + 1 m(x k + 1) b d 1 d 2 = 2m(x k + 1) + 2b 2y k 1 The sign of the difference d 1 d 2 determines which pixel to choose: if difference is negative then y k is closer to actual line (y), if it is positive y k + 1 is closer. How are non-integer calculations eliminated?

Bresenham requires that the endpoints of line segments (x 0, y 0 ) and (x n, y n ) are provided, therefore the slope m can be expressed as a ratio of integers, m = y x, substitution gives d 1 d 2 = 2m(x k + 1) + 2b 2y k 1 x(d 1 d 2 ) = 2 yx k 2 xy k + [2 y + x(2b 1)] As x is always 1 and [2 y + x(2b 1)] does not depend on pixel index k, we can write C = 2 y + x(2b 1). The pixel choice parameter p k can now be defined as p k = x(d 1 d 2 ) = 2 yx k 2 xy k + C If p k is positive, we choose y k + 1; if negative, y k. Now how do we get rid of C?

The answer is to use recursion for calculating a series of p k values, the pixel choice at the next location is determined by p k+1, and C can be eliminated by subtraction, as follows p k = x(d 1 d 2 ) = 2 yx k 2 xy k + C p k+1 = 2 yx k+1 2 xy k+1 + C p k+1 p k = 2 y(x k+1 x k ) 2 x(y k+1 y k ) and since algorithm steps along x axis, x k+1 = x + k + 1, can recursively define a relationship for choosing pixels as p k+1 = p k + 2 y 2 x(y k+1 y k ) Note that all quantities in this equation are integers.

For initialisation, a starting value for the first pixel, p 0, is required, using equation (see earlier) x(d 1 d 2 ) = 2 yx k 2 xy k + [2 y + x(2b 1)] and using starting point of the line (x 0, y o ) and substituting the following for b b = y 0 mx 0 = y 0 ( y/ x)x 0 we obtain p 0 = 2 y x

Bresenham s algorithm 1. Provide endpoints (x 0, y 0 ) and (x n, y n ) of line. 2. Calculate constants 2 y and 2 y 2 x, where y = y n y 0 and x = x n x 0. 3. Plot the origin (x 0, y 0 ). 4. Calculate the pixel choice parameter p k, and if pk < 0, plot (x k + 1, y k ) and p k+1 = p k + 2 y otherwise plot (x k + 1, y k + 1) and p k+1 = p k + 2 y 2 x 5. Repeat step 4, until x n is reached.

Implementation of Bresenham s algorithm Implementation of Bresenham s algorithm for drawing lines based on mathematical equation y = mx + b for either (i) positive slope < 1 (only this case covered here) (ii) negative slope > 1, or (iii) positive slope 1. For the discrete case, subscript k is added to pixel x k, the equation for a line then becomes y = mx k + b however, in general y will not be an integer.

/ / Bresenham s a l g o r i t h m f o r l i n e drawing void drawbresenhamline ( Graphics g, Point s t a r t, Point end ) { / / Implements case f o r slope < 1 i f ( m_slopelt1 ) { x = m_x0 + 1; y = m_y0 ; while ( x < m_x1) { i f ( m_param < 0) { m_param += m_twodeltay ; } else { m_param += m_twodydx ; y += m_slopesign ; } drawpixel ( g, x, y ) ; x ++; }

Edge coherence (revisited) In principle, finding the intersection of the point between a scan line and a polygon edge just involves substituting y = y scan into equation for a line and solving for s. However, it suffers from same problem as drawing lines, in that it involves floating point arithmetic. It turns out that there is a more efficient algorithm which allows us to calculate the x value on a scan line directly from the x value on the previous scan line (like Bresenham s algorithm), based on the edge coherence property of a polygon.

The idea behind coherence is that most geometric figures have regions where properties are relatively consistent. In edge coherence, this means that non-horizontal edge in a polygon will be intersected by more than one scan line and therefore should be able to generate intersection points iteratively, rather than using the line equation at each step. Suggests a recursive algorithm closely related to Bresenham s line drawing algorithm.

Edge coherence algorithm 1. When a scan line is added to the active edge table, initialise x to x min and the increment to 0. Calculate and store x and y. 2. When a scan line is increased by 1, add x to the increment. 3. If the magnitude of the slope is greater than or equal to 1, compare the magnitude of the increment with y. If it is less than y, leave x as it is. Otherwise, increase x by 1, and subtract (add) y to the increment if the increment is positive (negative). 4. If magnitude of slope is less than 1, determine number of pixels to increase x by dividing magnitude of increment by y (ignoring remainder). The remainder (positive if increment is positive, and negative if it is negative) becomes new value of the increment.

Z Buffer As well as pixel frame buffer, keep a parallel Z buffer, which at each point records the depth of corresponding pixel. The Z buffer is initialised to some representation of infinite depth. The frame buffer initialised to background colour then pixel writes take pixel value, x, y, and Z. Updates only take place at (x, y) only if new depth is closer.

Z Buffer Depth must be in camera coordinates, any order-preserving function of true depth will do (pseudo-depth is OK). Z buffer must have sufficient bits to resolve depth finely enough and may use some bits of frame buffer, if enough bits are available, and display lookup tables can be manipulated. Can use buffer with higher spatial resolution, and block-average down for antialiasing.

The z-buffer drawing (a) first and (b) second polygons 0 0 0 0 0 0 0 0 5 5 5 5 5 5 5 5 5 5 5 5 5 5 0 0 0 0 0 0 0 0 0 5 5 5 5 5 5 5 5 5 5 5 5 0 0 0 0 0 0 0 0 0 0 5 5 5 5 5 5 5 5 5 5 0 0 0 0 0 0 0 0 0 0 0 + 5 5 5 5 = 5 5 5 5 0 0 0 0 0 0 0 0 0 0 0 0 5 5 5 5 5 5 0 0 0 0 0 0 0 0 0 0 0 0 0 5 5 5 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 5 0 0 0 0 0 0 0 (a) 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 5 5 5 5 5 5 0 5 5 5 5 5 5 5 0 5 5 5 5 5 5 0 0 3 5 5 5 5 5 5 0 0 5 5 5 5 5 0 0 0 4 3 5 5 5 5 5 0 0 0 5 5 5 5 0 0 0 0 + 5 4 3 = 5 5 5 5 0 0 0 0 5 5 5 0 0 0 0 0 6 5 4 3 6 5 5 3 0 0 0 0 5 5 0 0 0 0 0 0 7 6 5 4 3 7 6 5 4 3 0 0 0 5 0 0 0 0 0 0 0 8 7 6 5 4 3 8 7 6 5 4 3 0 0 (b) 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Assume looking down the z axis. Depends on spatial resolution (must have sufficient bits to resolve depth finely enough).

Interpolation of z values along edges for scan lines y 1 y z 1 y z a = z 1 (z 1 z 2 ) 1 y s y 1 y 2 y s z a z p z b Scan line y z b = z 1 (z 1 z 3 ) 1 y s y 1 y 3 y 2 z 2 y 3 z 3 x b x p z p = z b (z b z a ) x b x a

Pros and cons of the z buffer + simple to implement. + implementable in hardware (generally is). + works for all kinds of objects (not just polyhedra). - extra storage needed for Z buffer. - many accesses to Z buffer and frame buffer bad for display through a communications link. - limited to space and depth resolution of buffers.

Properties of Z-buffers for each polygon or object in scene (piecewise Z buffering). (z-buffer) for each scan line (single-scan-line Z buffering If shading computation is time-consuming, a rough front-to back depth sort of objects to display closest one first improves efficiency (can use radix sort for this, at resolution of z-buffer). Don t calculate shading for hidden surfaces important if using Phong illumination model as we will see later.

Rendering pipeline for z-buffer (revisited) db traversal Modeling transformation Trivial accept/reject Lighting Viewing transformation Clipping Divide by W, map to 3D viewport Rasterization Display (Foley Figure 14.41)

Rendering pipeline for z-buffer - the steps See page 521 of Foley: db traversal & modelling transformation transform all (relatively defined) polygons or polygonal meshes to their correct location. Trivial accept/reject: Entirely outside & back face culling Lighting: calculate intensity (for vertices only: need to do in 3D before perspective projection) Viewing transformation: perspective transformation (e.g. perspective foreshortening). Clipping: clip to viewport (involves creation of new vertices on border). Map to viewport: Change of coordinate systems (Divide by W: based on homogeneous coordinate system). Rasterisation: scan-line drawing polygons (including z-buffering & shading interpolation)

Rendering pipeline for z-buffer and Phong shading db traversal Modeling transformation Trivial accept/reject Viewing transformation Clipping Divide by W, map to 3D viewport Rasterization (including lighting) Display Using the Phong illumination model, lighting cannot be calculated early in the pipeline why? (Foley Figure 14.42),

Rendering pipeline for z-buffer and Phong shading See pages 522-523 of Foley: Viewing transformation: Need to calculate lighting after viewing transformation, why? because Phong illumination is dependent on viewer orientation. Clipping: because Phong shading interpolates surface normals, rather than intensities, the vertices cannot be lit early in the pipeline Rasterisation: lighting equation must be calculated for every pixel.

High performance visible surface determination Many methods and variations of visible surface determination are possible, which performs best depends on hardware available, and nature of graphics drawn, E.g. for a scene made of many small polygons, Z buffering might be best, for a scene made of a few large polygons, binary space partition techniques (BSPs) might be better. The Z-buffer idea can also be used for a variety of tasks, such as piecewise Z buffering (for example polygon-by polygon), or single-scan-line Z buffering (pixel-by-pixel).

Summary Polygons can be filled using a scan-line approach based on the odd-even to determine whether inside or outside. Efficient scan-line algorithms rely on bucket (hash) sorting edges and maintaining active-edge tables. This allows only edges of relevant polygons to be checked. Efficient line drawing algorithms typically utilise the edge coherence property to calculate the value of the pixel on the current scan line from the value on previous scan line. Bresenham s insight was how to rely only on integer operations, thus avoiding floating point arithmetic.

Summary Edge-coherence properties can be utilised in polygon filling algorithms, to decide whether x values in the active-edge table need incrementing (Can use same approach for drawing circles and ellipses) The Rendering pipeline, based on z-buffering, is the basis of Hidden surface removal OpenGL. Various techniques exist for high performance visible surface detection, including binary space partition (BSP) and piecewise (polygon-by-polygon) Z buffering and single-scane-line (pixel-by-pixel) buffering.