cs430 computer graphics n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
CS430 Computer Graphics PowerPoint Presentation
Download Presentation
CS430 Computer Graphics

Loading in 2 Seconds...

play fullscreen
1 / 51

CS430 Computer Graphics - PowerPoint PPT Presentation


  • 145 Views
  • Uploaded on

CS430 Computer Graphics. Rasterization Revisit. Topics. Rasterization in the Graphics Pipeline Rasterization of Line Primitives Rasterization of Circle Primitives Rasterization of Filled Area Filling Polygons Antialiasing Techniques. Rasterization in the Graphics Pipeline.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'CS430 Computer Graphics' - oren


Download Now An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
cs430 computer graphics

CS430 Computer Graphics

Rasterization Revisit

Chi-Cheng Lin, Winona State University

topics
Topics
  • Rasterization in the Graphics Pipeline
  • Rasterization of Line Primitives
  • Rasterization of Circle Primitives
  • Rasterization of Filled Area
  • Filling Polygons
  • Antialiasing Techniques
rasterization in the graphics pipeline
Rasterization in the Graphics Pipeline
  • Life after Window to Viewport Transformation?
    • Backend of graphics pipeline
  • Scan conversion (rasterization)
    • Convert specification of a primitive into pixels in the frame buffer
    • Process of taking high-level information such as the positions and colors of vertices and determining the colors of many pixels in a region of the frame buffer
rasterization in the graphics pipeline1
Rasterization in the Graphics Pipeline
  • Per fragment operation
    • Rasterization produces fragments, not just pixels
    • Fragment: color, depth, and texture coordinate
    • Steps and tests are performed on a fragment before it is written into the frame buffer as a simple pixel value
  • Backend of graphics pipeline

Per Fragment Operations

Pixels on display

Viewport Transformation

Scan Conversion

rasterization in the graphics pipeline2
Rasterization in the Graphics Pipeline
  • Rasterization of primitives
    • Line
    • Circle
    • Polyline
    • Polygon
    • Filled area
    • Text
line primitive
Line Primitive
  • Pixel provides a basis for all the raster graphics techniques
  • Q: How is a line segment defined?
    • A: By the two endpoints
  • Q: How is a line displayed
    • A: By scan converting two endpoints into pixels on the line from one endpoint to the other
  • We are going to study three algorithms to perform scan conversion for a line
line primitive1
Line Primitive
  • Basic line equation
    • y = mx + b,

where m = slope, b = intercept on y axis

    • Given two points (ax, ay) and (bx, by)

m = (by - ay)/(bx - ax)

b = ay – max

    • Example: a = (1, 1), b = (5, 3)
basic increment algorithm
Basic Increment Algorithm
  • Algorithm (Brute Force)
    • Given two points (ax, ay) and (bx, by), ax < bx

m = (by - ay)/(bx - ax)

b = ay – max

for (x = ax; x<= bx; x++)

y = mx + b

setPixel(x, round(y))

// round(y) = floor(y + 0.5)

basic increment algorithm1
Basic Increment Algorithm
  • Problems
    • One multiplication for each y
    • Calculation of round()
    • When abs(m) > 1, there are many missing pixels, since incrementing x by 1 increments y by > 1
    • When ax = bx, m = infinity

Expensive

Operations

Can be solved easily by programming

dda algorithm
DDA Algorithm
  • Relies on the fact that for any 2 pts on line, xi+1 - xi = 1 (pixels)
    • yi+1 = mxi+1 + b

= m (xi + x) + b

= (mxi + b) + mx

= yi + mx

yi+1= yi + m, if x = 1

dda algorithm2
DDA Algorithm
  • Algorithm
    • Given two points (ax, ay) and (bx, by), ax < bx

m = (by - ay)/(bx - ax)

for (x = ax; x<= bx; x++; y += m)

setPixel(x, round(y))

  • Problems
    • No multiplication, but round() is still there
    • ax = bx
    • Missing pixels when abs(m) > 1
bresenham s midpoint algorithm
Bresenham's Midpoint Algorithm
  • Use the midpoint between two y values of a line to make a decision about which direction the next pixel should go
  • Using a decision variable d to decide whether the line passes over or under M (the Midpoint)
    • If d > 0 then go NE (North East) pixel
    • If d <=0 then go E (East)
  • Details will be given in the lecture
bresenham s midpoint algorithm2
Bresenham's Midpoint Algorithm
  • Example
    • From (5, 8) to (9, 11)
bresenham s midpoint algorithm3
Bresenham's Midpoint Algorithm
  • Algorithm
    • Given two points (ax, ay) and (bx, by), ax < bx

y = ay H = by - ay W = bx - ax

E = 2H NE = 2(H - W) F = 2H - W

for (x = ax; x<= bx; x++)

setPixel(x, y)

if (F < 0)

F += E

else

y++

F += NE

bresenham s midpoint algorithm4
Bresenham's Midpoint Algorithm
  • No multiplication, no rounding
  • BUT, the algorithm given in the notes only works when
    • ax < bx and
    • 0 m 1
  • Polyline and polygon can then be constructed using lines
circle primitive
Circle Primitive
  • Circle equation (radius = R)
    • Centered at the origin: x2 + y2 = R2
    • Centered at (a, b): (x - a)2 + (y - b)2 = R2
  • Basic increment algorithm won’t work
    • y =
using polar coordinates
Using Polar Coordinates
  • Better than basic increment

, where

(xc, yc) is the centre

r is the radius

 is the angle in radians

  • Problems
    • floating point operations
    • cos() and sin()
using regular polygon
Using Regular Polygon
  • Regular polygon
    • A polygon is regularif it is simple, if all its sides have equal lengths, and if adjacent sides meet at equal interior angles
  • n-gon
    • Regular polygon having n sides
    • Large n approximates a circle
using regular polygon1
Using Regular Polygon
  • Code shown in the textbook
    • Fig 3.43
    • Fig 3.55
  • Your lab and project
  • Problems
    • Do we get rid of floating point operations, cos(), and sin()?
symmetry of circle
Symmetry of Circle
  • Circle is symmetric

 for each point calculated, we can plot 7 others

 only calculations for 1/8 of the circle is required

symmetry of circle1
Symmetry of Circle

Circle centered at origin

Circle centered at

(xc, yc)

symmetry of circle2
Symmetry of Circle
  • Algorithm
    • CirclePoints(x, y) // for circle centered at (0, 0)

{ setPixel(x, y)

setPixel(x, -y)

setPixel(-x, y)

setPixel(-x, -y)

setPixel(y, x)

setPixel(y, -x)

setPixel(-y, x)

setPixel(-y, -x)

}

bresenham s midpoint algorithm5
Bresenham's Midpoint Algorithm
  • Is there an algorithm to draw circles without floating point operations?
  • The same person did it …
    • Similar to his line drawing algorithm
  • Eightfold symmetry of circles

 computation performed only on the second octant of the circle

 (x,y) from (0,R) to (R/sqrt(2), R/sqrt(2))

bresenham s midpoint algorithm6
Bresenham's Midpoint Algorithm
  • A decision variable d is used to decide to go two directions E or SE based upon how close the line is to the midpoint M
    • If d < 0 then chooses E
    • If d  0 then chooses SE
  • Details will be given in the lecture
  • No floating point operations!!
bresenham s midpoint algorithm8
Bresenham's Midpoint Algorithm
  • Algorithm
    • Given radius R and center (0, 0)

x = 0 y = Rd = 1 - R

CirclePoints(x, y)

while (y > x)

if (d < 0)

d += 2x + 3

else

d += 2(x - y) + 5

y--

x++

CirclePoint(x, y)

bresenham s midpoint algorithm9
Bresenham's Midpoint Algorithm

Before and after …

filled area
Filled Area
  • Filling pixel-defined region
    • Fill the region R of the set of all pixels having color C that are “connected” to a given pixel S.
    • Example: pour ink in a region in MS-Paint
  • Filling polygons
    • Given a list of vertices of a polygon, fill the region of the polygon
flood fill
Flood-Fill
  • Change every interior 4-connected pixel of color intColor to a new color newColor
  • Algorithm
    • floodFill(x, y, intColor, newColor)

if (getPixel(x, y) == intColor)

setPixel(x, y, newColor)

floodFill(x-1, y, intColor)

floodFill(x+1, y, intColor)

floodFill(x, y+1, intColor)

floodFill(x, y-1, intColor)

flood fill1
Flood-Fill
  • Flood-fill is a recursive algorithm
  • Problem
    • Neighbors are test blindly
    • Might cause a stack overflow even for a small region
    • Example:

seed=(4,2)

the calls are on

(3,2), (2,2), (1,2), (3,2),

(2,3), (2,1), (4,2), (3,3),…

totally 21 calls!!

5

4

3

2

1

0

0

1

2

3

4

5

run fill
Run-Fill
  • Solution to flood-fill
    • Exploit region coherence :likelihood that a pixel adjacent to an interior pixel is also an interior pixel
  • Run
    • Group of pixels lying on the same scan line
  • Run-fill
    • Identified and filled a whole run at once
run fill2
Run-Fill
  • Algorithm
    • while (stack not empty)

push address of seed pixel on the stack

seed = pop(stack)

fill in the run defined by seed

find interior runs reachable from this run in the row above

push addresses of right most pixels of each run

find interior runs reachable from this run in the row below

push addresses of right most pixels of each run

filling polygons
Filling Polygons
  • Progress through the frame buffer scan line by scan line, and use inside-outside test to fill portions of each line
  • Algorithm (brute force)

for each scan line L

find intersections of L with all edges of polygon

sort intersections by increasing x-value

fill pixel runs between all pairs of intersections

out

in

out

in

out

filling polygons1
Filling Polygons
  • What is the time complexity of the brute force algorithm?
  • Use edge coherence to improve performance
    • Tendency for many of the edges intersected by scan line y to be intersected as well by scan line (y + 1)
    • Property that the x-value of the intersection migrates in uniform increments from scan line to scan line
  • Maintain an active-edge list (AEL) to locate intersections quickly
filling polygons2
Filling Polygons
  • Each edge in AEL contains
    • xint: x-value of intersection of current scan line and the edge
    • 1/m: reciprocal of the edge’s slope m
    • yhigh: y-value of upper endpoint of the edge
  • Why storing 1/m?
    • xint + 1/m is the x-value of intersection of the edge and the next scan line above
    • Edge coherence
filling polygons3
Filling Polygons

120

  • Example
  • AEL for y = 50

80

60

50

40

20

40

80

120

70 0 70

100 .33 80

45 -.5 80

56.66 .666 70

filling polygons4
Filling Polygons
  • When move up to next scan line y
    • If yhigh of an edge < y then delete the edge
    • New edge(s) might be added to AEL
    • For nonsimple polygons, the intersections might have to be sorted
  • How do we find edges that should be added quickly?
    • Edge table
filling polygons5
Filling Polygons
  • Edge table
    • Array of lists, one list for each scan line
  • The list edgetable[y]
    • Contains information about any edge with lower endpoint at scan line y
    • xint: x-value of lower endpoint
    • 1/m: reciprocal of the edge’s slope m
    • yhigh: y-value of upper endpoint of the edge
  • Horizontal edges are not in the edge table
    • It’s ok, though … why?
filling polygons6

80

30 1 90

110 -1 90

:

:

40 -.5 80

40 .666 70

40

:

:

20

70 0 70

90 .33 80

Filling Polygons
  • Example

80

40

20

10

30

50

70

90

110

filling polygons7
Filling Polygons
  • Algorithm
    • AEL = NULL

for (y = 0; y <= maxRow; y++)

add all edges in edgetable[y] to AEL

if (AEL != NULL)

sort AEL by xint

fill pixels values along y

delete any edge with yhigh ==y

xint = xint + 1/m for each edge in AEL

antialiasing techniques
Antialiasing Techniques
  • Aliasing
    • Distortion of information due to undersampling
    • Appearance of “jaggies” because of discrete nature of pixels
  • Antialiasing techniques: reduce aliasing
    • Prefiltering
    • Supersampling
    • Postfiltering
prefiltering
Prefiltering
  • Pixel color computed based on the fraction of pixel area covered by object
    • But it’s time consuming to calculate the coverage of pixels
    • Example:
prefiltering1
Prefiltering
  • Pitteway and Watkinson’s algorithm
    • Efficient algorithm calculating the coverage
    • Based on Bresenham’s algorithm
    • For a line with a slope m, where 0 m 1
      • Coverage increased by m if go east
      • Coverage decreased by 1 – m if go northeast
prefiltering2
Prefiltering
  • Example

Shaded area .5 .9 .3 .7 .1 .5 .9 .3 .7 .1 .5

1 2 3 4 5 6 7 8 9 10 11

x 

supersampling
Supersampling
  • Taking more intensity samples of the scene than are displayed
  • Each pixel value is then formed as the average of neighbor samples
  • Ns : value of oversampling
    • Example: Ns = 2  double sampling
      • Object sampled two time more densely in both x and y than displayed
      • Final pixel value

= average of nine neighbor samples

supersampling1
Supersampling
  • Example: Ns = 2  double sampling
    • Pixel A = 2/3 of object’s color + 1/3 of background color
    • Pixel B = object’s color

A

B

supersampling2
Supersampling
  • Works even with no supersampling, i.e., Ns = 1
    • Scene sampled at the corner of each display pixel
    • Intensity of pixel = average of pixel corners

pixel corner

postfiltering
Postfiltering
  • Improved visual effect by giving center sample more weight than neighbors
  • Display pixel = weighted average of an appropriate set of neighbors
  • Example
    • Pixels Mask (Window function)

28 16 4 1/16 1/16 1/16

42 30 17 1/16 1/2 1/16

53 60 62 1/16 1/16 1/16

Intensity of display pixel =

30/2 + (28 + 16 + 4 + 42 + 17 + 53 + 60 + 62)/16 = 32.625  33