Docsity

Antialiasing - Computer Graphics - Lecture Slides, Slides of Computer Graphics

Partial preview of the text

Download Antialiasing - Computer Graphics - Lecture Slides and more Slides Computer Graphics in PDF only on Docsity!

Computer Graphics Raster Graphics: Polygons & Antialiasing

So Far…

n Raster graphics: n Line drawing algorithms (simple, Bresenham’s) n Today: n Defining and filling regions n Polygon drawing and filling n Antialiasing

Defining and Filling Regions of Pixels

n Methods of defining region n Pixel-defined: specifies pixels in color or geometric range n Symbolic: provides property pixels in region must have n Examples of symbolic:

  • Closeness to some pixel
  • Within circle of radius R
  • Within a specified polygon

Pixel-Defined Regions

n Definition: Region R is the set of all pixels having color C that are connected to a given pixel S n 4-adjacent: pixels that lie next to each other horizontally or vertically, NOT diagonally n 8-adjacent: pixels that lie next to each other horizontally, vertically OR diagonally n 4-connected: if there is unbroken path of 4-adjacent pixels connecting them n 8-connected: unbroken path of 8-adjacent pixels connecting them

Recursive Flood-Fill Algorithm

n Note: getPixel(x,y) used to interrogate pixel color at (x, y)

void floodFill(short x, short y, short intColor) { if(getPixel(x, y) == intColor) { setPixel(x, y); floodFill(x – 1, y, intColor); // left pixel floodFill(x + 1, y, intColor); // right pixel floodFill(x, y + 1, intColor); // down pixel floodFill(x, y – 1, intColor); // fill up } }

Recursive Flood-Fill Algorithm

n This version defines region using intColor n Can also have version defining region by boundary n Recursive flood-fill is somewhat blind and some pixels may be retested several times before algorithm terminates n Region coherence is likelihood that an interior pixel mostly likely adjacent to another interior pixel n Coherence can be used to improve algorithm performance n A run is a group of adjacent pixels lying on same n Exploit runs(adjacent, on same scan line) of pixels

Filling Polygon-Defined Regions

n Problem: Region defined by Polygon P with vertices Pi = (Xi, Yi), for i – 1…N, specifying sequence of P’s vertices

P

P

P

P

P

P

P

Filling Polygon-Defined Regions

n Solution: Progress through frame buffer scan line by scan line, filling in appropriate portions of each line n Filled portions defined by intersection of scan line and polygon edges n Runs lying between edges inside P are filled

Filling Polygon-Defined Regions

n Example: scan line y = 3 intersects 4 edges e3, e4, e5, e n Sort x values of intersections and fill runs in pairs n Note: at each intersection, inside-outside (parity), or vice versa P

P

P

P

P

P

P

e

e5 e

e

3

Filling Polygon-Defined Regions

n What if two polygons A, B share an edge? n Algorithm behavior could result in: n setting edge first in one color and the another n Drawing edge twice too bright n Make Rule: when two polygons share edge, each polygon owns its left and bottom edges n E.g. below draw shared edge with color of polygon B

A

B

Read: Hill: 9.7.1, pg 481

Antialiasing

n Raster displays have pixels as rectangles n Aliasing: Discrete nature of pixels introduces “jaggies”

Antialiasing

n Aliasing effects: n Distant objects may disappear entirely n Objects can blink on and off in animations n Antialiasing techniques involve some form of blurring to reduce contrast, smoothen image n Three antialiasing techniques: n Prefiltering n Postfiltering n Supersampling

Supersampling

n Useful if we can compute color of any (x,y) value on the screen n Increase frequency of sampling n Instead of (x,y) samples in increments of 1 n Sample (x,y) in fractional (e.g. ½) increments n Find average of samples n Example: Double sampling = increments of ½ = 9 color values averaged for each pixel

Average 9 (x, y) values to find pixel color

Postfiltering

n Supersampling uses average n Gives all samples equal importance n Post-filtering: use weighting (different levels of importance) n Compute pixel value as weighted average n Samples close to pixel center given more weight

1/ 1/16 1/

1/

1/16 1/16 1/

1/ 1/

Sample weighting