Top Banner
10/26/04 © University of Wisconsin, CS559 F all 2004 Last Time Drawing lines Polygon fill rules Midterm Oct 28
22

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

Jan 01, 2016

Download

Documents

Arleen Bennett
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 10/26/04© University of Wisconsin, CS559 Fall 2004 Last Time Drawing lines Polygon fill rules Midterm Oct 28.

10/26/04 © University of Wisconsin, CS559 Fall 2004

Last Time

• Drawing lines

• Polygon fill rules

• Midterm Oct 28

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

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

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

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?

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

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

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

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 ymin to ymax are relevant for what y values?

• What about horizontal edges?

ymin

ymax

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

10/26/04 © University of Wisconsin, CS559 Fall 2004

When are Edges Relevant (2)

1

2

3

43,4

1,3

1,2

Convex polygon:Always only two edges active

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

10/26/04 © University of Wisconsin, CS559 Fall 2004

Spans

• Fill rows from bottom to top, one at a time

• Have pixels xmin, xmax for each span

• Fill [xmin, xmax)

– Include xmin, exclude xmax

xmin,xmax

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

10/26/04 © University of Wisconsin, CS559 Fall 2004

Tracking xmin and xmax

• 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 xmin

and xmax?

– What is the decision variable?

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

10/26/04 © University of Wisconsin, CS559 Fall 2004

yi

yi+1

xi+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 (xi+1,yi+1). Is it above or below the line?

xi

Choose (xi+1,yi+1)

yi

yi+1

xi+1xi

Choose (xi+1,yi)

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

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

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

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

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

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

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

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

1/8

.914

.914

.914

1/8

1/8

1/4

1/4

1/41/40 0

00

0000

0

0

0

0 0 0

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

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

1/8

.914

.914

.914

1/8

1/8

1/4

1/4

1/41/40 0

00

0000

0

0

0

0 0 0

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

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

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

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

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

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

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

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

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

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

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

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

zs

xs

Fails

Which point for choosing ordering?

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

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

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

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)