1 / 88

Implementation

Implementation. Dr. Amy Zhang. Reading. Hill, Chapters 9.4-9.7 Hill, Chapter 10. Outline. The Rasterization Problem Scan converting lines Filling polygons Clipping Hidden surface removal (z-buffer). 3D Graphics Pipeline. The rasterization step scan converts the object into pixels.

admon
Download Presentation

Implementation

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. Implementation Dr. Amy Zhang

  2. Reading • Hill, Chapters 9.4-9.7 • Hill, Chapter 10

  3. Outline • The Rasterization Problem • Scan converting lines • Filling polygons • Clipping • Hidden surface removal (z-buffer)

  4. 3D Graphics Pipeline • The rasterization step scan converts the object into pixels

  5. Implicit Lines • Implicit equation in two dimensions: • Points with f(x,y) = 0 are on the line • Points with f(x,y) != 0 are not on the line

  6. Implicit Lines • The implicit form of the slope‐intercept equation:

  7. The slope‐intercept form can not represent some lines, such as x = 0. • A more general implicit form is more useful: y = mx + b or • The implicit line through two points (x0,y0) and (x1,y1):

  8. Example • What is the implicit equation of this line?

  9. Example • Solution 1: ‐2X+4Y=0 • Solution 2: 2X‐4Y=0 • What’s the lesson here? • k f(x,y) = 0 is the same line, for any value of k

  10. Example • The value of f(x,y) = ‐2x +4y tells us which side of the line a point (x,y) is on

  11. The Rasterization Problem • Primitives map to discrete display space

  12. Solution • Selection of discrete representation values

  13. Scan converting lines • Characterizing the problem: 2 cases • Move vertical scanline from x0 to xn • Move horizontal scanline from bottom to top • dot: center of pixel

  14. Exactly one pixel per column: • Fewer: disconnected • More: too thick • Only discuss m≤1 case • The strategy • Pick pixels closest to endpoints • Select in between pixels “closest”to ideal line • Objective: To minimize the required calculations.

  15. DDA (Digital Differential Analyzer) Algorithm

  16. DDA Algorithm, Incremental Form

  17. Disadvantage of DDA algorithm: • Floating point addition. Slow!! • Solution: integer operation

  18. Bresenham’s Algorithm • Allowable Pixel Selections • Standard algorithm used in hardware/software rasterizers.

  19. Iterating

  20. Decision function: Q(x,y)=y-mx-b above line L: +; on: 0; below: - F(x,y)=ax+by+c=0 (implicit equation of the line) if F(xi+1, yi+1/2)<0, M lies above the line, chose E if F(xi+1, yi+1/2)>0, M lies below the line, chose NE

  21. Calculating the decision function (x0,y0): the point on the line Initial condition:

  22. Problem: • Complete computation of d along the line • Solution: incremental calculation of di

  23. The code

  24. Bresenham’s Algorithm • An example

  25. Filling Polygons

  26. Scan Line Algorithm • Compute the bounding pixels • Fill the spans

  27. Scan Line Algorithm • Find the intersections of current scan line with all edges of the polygon. • Sort the intersections by increasing x coordinate. • Fill in pixels that lie between pairs of intersections that lie interior to the polygon using the odd/even parity rule. • Parity: even, change parity once encounter an edge • Special parity: no change of the parity (draw 1 pixel)

  28. Filling polygons: scan line algorithm • http://www.cs.rit.edu/~icss571/filling/example.html

  29. Edge table • Initializing the all_edges table: determine how the polygon's vertices are related • Each adjacent set of vertices defines an edge. For each edge, we need to keep: • The minimum y value of the 2 vertices: ymin • The maximum y value of the 2 vertices: ymax • The x value associated with the minimum y value: xval • 1/The slope of the edge:1/m (?)

  30. Global edge table • Initializing the Global Edge Table (GET): • keep track of the edges that are still needed to complete the polygon. • place the edges with m≠0 (?) • be inserted with edges grouped by increasing minimum y values and further by x values

  31. Active Edge Table • Initializing Parity • even since no edges have been crossed yet . • Initializing the Scan-Line • is equal to the lowest y value for all of the global edges.(10) • Initializing the Active Edge Table (AET) • keep track of the ordered edges that are intersected by the current scan-line.

  32. Scanline = 10: at x=10, parity = odd. draw pixels left to x=22, parity = even. at x=28, draw a pixel (the special parity case)

  33. Filling the polygon • Scanline=11: update x = x +1/m  sort by xval • at x=10, parity = odd. • draw pixels left to x=23, parity = even. • at x=27, parity = odd. • draw pixels left to x=28, parity = even.

  34. Scanline+=1, until ymax is equal to the next scan-line • Scanline = 15: • at x=10, parity = odd. • draw pixels left to x=22, parity = even. • at x=27, parity = odd. • draw pixels left to x=28, parity = even.

  35. Scanline++ (16) • remove the edges if ymax=scanline from the active edge table (for the edges at indices 0, 2, and 3) • update the x values for all remaining edges in the active edge table

  36. Now add the edges from the global edge table to the active edge table since ymin =scanline. reorder

  37. Scanline=17: update = x +1/m, sort by xva • at x=12, parity = odd. • draw pixels left to x=20, parity = even.l

  38. Scanline ++, until scanline=19 • at x=15, parity = odd. • draw pixels left to x=18, parity = even.

  39. scanline++ • remove the edges if ymax=scanline from the active edge table (for the edges at indices 0, 1) • add the edges from the global edge table to the active edge table if ymin =scanline. • Iterate until both tables are empty.

  40. Demo • Algorithm • Initiate the GET, scanline, AET • Draw the pixels based on AET and the parity • Scanline++ • Remove the edges from AET is scanline=ymax ,terminate if both AET and GET are empty • Update X values • Add edges to AET if GET is not empty • Reorder AET • Goto step 2.

  41. Problem • Antialiasing by Area Averaging • Color multiple pixels for each x depending on coverage by ideal line

  42. Aliasing problems can be serious for polygons • Jaggedness of edges • Small polygons neglected • Need compositing so color of one polygon does not totally determine color of pixel All three polygons should contribute to color

  43. Outline • The Rasterization Problem • Scan converting lines • Filling polygons • Clipping • Hidden surface removal (z-buffer)

  44. Clipping • Clipping Against a Rectangular Region Multiple Cases

  45. Division of Space

  46. Cohen Sutherland Clipping: Outcodes

  47. Cohen Sutherland Clipping: Region Outcodes

  48. Trivial Acceptance: • O( P0 ) = O( P1) = 0

More Related