1 / 51

CS430 Computer Graphics

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.

oren
Download Presentation

CS430 Computer Graphics

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS430 Computer Graphics Rasterization Revisit Chi-Cheng Lin, Winona State University

  2. Topics • Rasterization in the Graphics Pipeline • Rasterization of Line Primitives • Rasterization of Circle Primitives • Rasterization of Filled Area • Filling Polygons • Antialiasing Techniques

  3. 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

  4. 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

  5. Rasterization in the Graphics Pipeline • Rasterization of primitives • Line • Circle • Polyline • Polygon • Filled area • Text

  6. 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

  7. 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)

  8. 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)

  9. 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

  10. 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

  11. DDA Algorithm

  12. 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

  13. 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

  14. Bresenham's Midpoint Algorithm • Example • E or NE?

  15. Bresenham's Midpoint Algorithm • Example • From (5, 8) to (9, 11)

  16. 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

  17. 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

  18. 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 =

  19. 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()

  20. 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

  21. 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()?

  22. 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

  23. Symmetry of Circle Circle centered at origin Circle centered at (xc, yc)

  24. 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) }

  25. 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))

  26. 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!!

  27. Bresenham's Midpoint Algorithm The second octant

  28. 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)

  29. Bresenham's Midpoint Algorithm Before and after …

  30. 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

  31. 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)

  32. 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

  33. 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

  34. Run-Fill

  35. 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

  36. 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

  37. 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

  38. 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

  39. 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

  40. 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

  41. 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?

  42. 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

  43. 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

  44. 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

  45. 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:

  46. 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

  47. 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 

  48. 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

  49. 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

  50. 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

More Related