Docsity

Rasterization - Introduction to Computer Graphics - Lecture Slides, Slides of Computer Graphics

Partial preview of the text

Download Rasterization - Introduction to Computer Graphics - Lecture Slides and more Slides Computer Graphics in PDF only on Docsity!

Rasterization:

Polygon Drawing

and

Hidden Surface Removal

Today

  • Finish up line anti-aliasing
    • Ratio method
  • Present several methods for polygon drawing
  • Discuss hidden surface removal algorithms

Rasterization

  • All geometry that makes it to rasterization is within the normalized viewing region
  • All the rasterizer cares about is (x, y)
    • z is only used for z-buffering later on
  • Need to convert continuous (floating point) geometry to discrete (integer) pixels

Line Drawing

  • A classic part of the computer graphics curriculum
  • Input:
    • Line segment definition
      • (x 1 , y 1 ), (x 2 , y 2 )
  • Output:
    • List of pixels (x 1 , y 1 ) (x 2 , y 2 )

Antialiasing

Antialiasing

  • Essentially 2 techniques: 1.Supersample then filter - We discussed a simple averaging filter 2.Compute the fraction of a line that should be applied to a pixel - Ratio method

Antialiasing #1:

Supersampling

No antialiasing 2x Supersampled Downsampled to original size 1/42/41/ 1/42/

Antialiasing #2:

Ratios

100% 0% 0% 75% 25% 0% 50% 50% 0%

Polygon Drawing

  • After clipping, we know that the entire polygon is inside the viewing region - Makes the problem easier
  • Need to determine which pixels are inside the polygon, and color those - Find edges, and fill in between them - Edges - Connected line segments - How to fill?

Scan-Line Polygons

  • Algorithm: 1.Mark local minima and maxima 2.Mark all distinct y values on edges 3.For each scan line: 1.Create pairs of edge pixels (going from left to right) 2.Fill in between pairs

Scan-Line Polygon Example

Polygon Vertices Maxima / Minima Edge Pixels Scan Line Fill

Flood Fill

  • 4 - fill
    • Neighbor pixels are only up, down, left, or right from the current pixel
  • 8 - fill
    • Neighbor pixels are up, down, left, right, or diagonal

Flood Fill Algorithm

void boundaryFill4(int x, int y, int fill, int boundary) { int curr; curr = getPixel(x, y); if ((current != boundary) && (current != fill)) { setColor(fill); setPixel(x, y); boundaryFill4(x+1, y, fill, boundary); boundaryFill4(x-1, y, fill, boundary); boundaryFill4(x, y+1, fill, boundary); boundaryFill4(x, y-1, fill, boundary); } } Seed Position Fill “Color” Edge “Color”

Flood Fill Example

  • 4 - fill: (^) Edge Pixels Seed Filled Pixels