Presentation is loading. Please wait.

Presentation is loading. Please wait.

10/26/04© University of Wisconsin, CS559 Fall 2004 Last Time Drawing lines Polygon fill rules Midterm Oct 28.

Similar presentations


Presentation on theme: "10/26/04© University of Wisconsin, CS559 Fall 2004 Last Time Drawing lines Polygon fill rules Midterm Oct 28."— Presentation transcript:

1 10/26/04© University of Wisconsin, CS559 Fall 2004 Last Time Drawing lines Polygon fill rules Midterm Oct 28

2 10/26/04© University of Wisconsin, CS559 Fall 2004 Today Filling polygons Anti-aliasing Hidden Surface Removal –Painter’s Algorithm –Z-buffer –A-buffer –Depth Sorting? Homework 4 due

3 10/26/04© University of Wisconsin, CS559 Fall 2004 Sweep Fill Algorithms Algorithmic issues: –Reduce to filling many spans –Which edges define the span of pixels to fill? –How do you update these edges when moving from span to span? –What happens when you cross a vertex?

4 10/26/04© University of Wisconsin, CS559 Fall 2004 Algorithm For each row in the polygon: –Throw away irrelevant edges –Obtain newly relevant edges –Fill span –Update current edges Issues: –How do we update existing edges? –When is an edge relevant/irrelevant? –What are the endpoints of a span All can be resolved by referring to our convention about what polygon a pixel belongs to

5 10/26/04© University of Wisconsin, CS559 Fall 2004 When are Edges Relevant (1) Use figures and convention to determine which edges are needed for which scanlines (rows of pixels) Edges from y min to y max are relevant for what y values? What about horizontal edges? y min y max

6 10/26/04© University of Wisconsin, CS559 Fall 2004 When are Edges Relevant (2) 1 2 3 4 3,4 1,3 1,2 Convex polygon: Always only two edges active

7 10/26/04© University of Wisconsin, CS559 Fall 2004 Spans Fill rows from bottom to top, one at a time Have pixels x min, x max for each span Fill [x min, x max ) –Include x min, exclude x max x min, x max

8 10/26/04© University of Wisconsin, CS559 Fall 2004 Tracking x min and x max Use a variant of the midpoint method, but not quite the same –Which pixel, with respect to the edge, do we wish to choose for x min and x max ? –What is the decision variable?

9 10/26/04© University of Wisconsin, CS559 Fall 2004 yiyi y i +1 x i +1 Midpoint Method For Polygon Edges Consider a left edge with slope [0-1] Always want to choose point on line or below Consider the point (x i +1,y i +1). Is it above or below the line? xixi Choose (x i +1,y i +1) yiyi y i +1 x i +1xixi Choose (x i +1,y i )

10 10/26/04© University of Wisconsin, CS559 Fall 2004 Sweep Fill Details For convex polygons there are always 2 edges, a left and a right –Fixes the amount of memory required, good for hardware Can generate memory addresses (for pixel writes) efficiently –You know address of leftmost pixel, and address of rightmost, can fill all in between quickly Other values may also be updated, such as z, w or color information –Use a midpoint-like rule for these too –Modern hardware, with floating point frame buffers, just interpolates

11 10/26/04© University of Wisconsin, CS559 Fall 2004 Extending to Arbitrary Polygons Can be more than one span in any row Keep sorted list of edges across row, fill between pairs of edges

12 10/26/04© University of Wisconsin, CS559 Fall 2004 Anti-Aliasing Recall: We can’t sample and then accurately reconstruct an image that is not band-limited –Infinite Nyquist frequency –Attempting to sample sharp edges gives “jaggies”, or stair-step lines Solution: Band-limit by filtering (pre-filtering) –What sort of filter will give a band-limited result? But when doing computer rendering, we don’t have the original continuous function

13 10/26/04© University of Wisconsin, CS559 Fall 2004 Alpha-based Anti-Aliasing Set the  of a pixel to simulate a thick line –The pixel gets the line color, but with  <=1 This supports the correct drawing of primitives one on top of the other –Draw back to front, and composite each primitive over the existing image –Only some hidden surface removal algorithms support it 1/8.914 1/8 1/4 00 00 00 0 0 0 0 0 000

14 10/26/04© University of Wisconsin, CS559 Fall 2004 Calculating  Consider a line as having thickness (all good drawing programs do this) Consider pixels as little squares Set  according to the proportion of the square covered by the line The sub-pixel coverage interpretation of  1/8.914 1/8 1/4 00 00 000 0 0 0 0 000

15 10/26/04© University of Wisconsin, CS559 Fall 2004 Weighted Sampling Instead of using the proportion of the area covered by the line, use convolution to do the sampling –Equivalent to filtering the line then point sampling the result Place the “filter” at each pixel, and integrate product of pixel and line Common filters are cones (like Bartlett) or Gaussians

16 10/26/04© University of Wisconsin, CS559 Fall 2004 Post-Filtering (Supersampling) Sample at a higher resolution than required for display, and filter image down –Easy to implement in hardware –Typical is 2x2 sampling per pixel, with simple averaging to get final What kind of filter? More advanced methods generate different samples (eg. not on regular grid) and filter properly –Issues of which samples to take, and how to filter them

17 10/26/04© University of Wisconsin, CS559 Fall 2004 Where We Stand At this point we know how to: –Convert points from local to window coordinates –Clip polygons and lines to the view volume –Determine which pixels are covered by any given line or polygon –Anti-alias Next thing: –Determine which polygon is in front

18 10/26/04© University of Wisconsin, CS559 Fall 2004 Visibility Given a set of polygons, which is visible at each pixel? (in front, etc.). Also called hidden surface removal Very large number of different algorithms known. Two main classes: –Object precision: computations that operate on primitives –Image precision: computations at the pixel level All the spaces in the viewing pipeline maintain depth, so we can work in any space –World, View and Canonical Screen spaces might be used –Depth can be updated on a per-pixel basis as we scan convert polygons or lines –Actually, run Bresenham-like algorithm on z and w before perspective divide

19 10/26/04© University of Wisconsin, CS559 Fall 2004 Visibility Issues Efficiency – it is slow to overwrite pixels, or rasterize things that cannot be seen Accuracy - answer should be right, and behave well when the viewpoint moves Must have technology that handles large, complex rendering databases In many complex environments, few things are visible –How much of the real world can you see at any moment? Complexity - object precision visibility may generate many small pieces of polygon

20 10/26/04© University of Wisconsin, CS559 Fall 2004 Painters Algorithm (Image Precision) Algorithm: –Choose an order for the polygons based on some choice (e.g. depth to a point on the polygon) –Render the polygons in that order, deepest one first This renders nearer polygons over further Difficulty: –works for some important geometries (2.5D - e.g. VLSI) –doesn’t work in this form for most geometries - need at least better ways of determining ordering zszs xsxs Fails Which point for choosing ordering?

21 10/26/04© University of Wisconsin, CS559 Fall 2004 The Z-buffer (1) (Image Precision) For each pixel on screen, have at least two buffers –Color buffer stores the current color of each pixel The thing to ultimately display –Z-buffer stores at each pixel the depth of the nearest thing seen so far Also called the depth buffer Initialize this buffer to a value corresponding to the furthest point (z=1.0 for canonical and window space) As a polygon is filled in, compute the depth value of each pixel that is to be filled –if depth < z-buffer depth, fill in pixel color and new depth –else disregard

22 10/26/04© University of Wisconsin, CS559 Fall 2004 The Z-buffer (2) Advantages: –Simple and now ubiquitous in hardware A z-buffer is part of what makes a graphics card “3D” –Computing the required depth values is simple Disadvantages: –Over-renders – rasterizes polygons even if they are not visible –Depth quantization errors can be annoying –Can’t easily do transparency or filter-based anti-aliasing (Requires keeping information about partially covered polygons)


Download ppt "10/26/04© University of Wisconsin, CS559 Fall 2004 Last Time Drawing lines Polygon fill rules Midterm Oct 28."

Similar presentations


Ads by Google