1 / 65

Computer Graphics (fall 2009)

Computer Graphics (fall 2009). School of Computer Science University of Seoul. Topics. Graphics pipeline Algorithms for the tasks in the pipeline. Chap 7: From Vertices to Fragments. Basic Implementation Strategies Four Major Tasks Clipping Line-Segment Clipping Polygon Clipping

yair
Download Presentation

Computer Graphics (fall 2009)

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. Computer Graphics(fall 2009) School of Computer Science University of Seoul

  2. Topics • Graphics pipeline • Algorithms for the tasks in the pipeline

  3. Chap 7: From Vertices to Fragments • Basic Implementation Strategies • Four Major Tasks • Clipping • Line-Segment Clipping • Polygon Clipping • Clipping of Other Primitives • Clipping in Three Dimensions • Rasterization • Bresenham’s Algorithm • Polygon Rasterization • Hidden-Surface Removal • Antialiasing • Display Considerations

  4. 7.1 Basic Implementation Strategies

  5. Big Picture • Input • Geometric objects • Attributes: color, material, normal, etc. • Lights • Camera specifications • Etc. • Output • Arrays of colored pixels in the framebuffer

  6. Big Picture (cont’d) • Tasks by graphics system • Transformations • Clipping • Shading • Hidden-surface removal • Rasterization

  7. Object-Oriented Approach • for(each_object) render(object); • Pipeline renderer • Same operation on every primitive (independently, in arbitrary order) SIMD (Single Instruction, Multiple Data) • Cannot handle global calculations (exception: hidden-surface removal)

  8. Image-Oriented Approach • for(each_pixel) assign_a_color(pixel); • To determine which geometric primitives can contribute to its color • Coherency  incremental implementation • Complex data structure • Can handle global effects • Example: raytracing

  9. 7.2 Four Major Tasks

  10. Four Major Tasks • Modeling • Geometry processing • Rasterization • Fragment processing

  11. 1. Modeling • Output: set of vertices

  12. 2. Geometry Processing • Model-view transformation • To camera (eye) coordinate • Projection transformation • To a normalized view volume • Vertices represented in clip coordinate • Primitive assembly • Clipping • Shading • Modified Phong model • Perspective division

  13. 3. Rasterization • A.k.a. scan conversion • “How to approximate a line segment with pixels?” • “Which pixels lie inside a 2D polygon?” • Viewport transformation • Fragments in window coordinates • Vs. screen coordinates?

  14. 4. Rasterization • Color assigned by linear interpolation • Hidden-surface removal on a fragment-by-fragment basis • Blending • Antialiasing

  15. 7.3 Clipping

  16. Clipping • Before perspective division • Normalized device coordinates

  17. 7.4 Line-Segment Clipping

  18. Clipper • Clipper accepts, rejects (or culls), or clips primitives against the view volume • Before rasterization • Four cases in 2D • Two algorithms • Cohen-Sutherland clipping • Liang-Barsky clipping

  19. Cohen-Sutherland Clipping • Intersection calculation replaced by membership test • Intersection calculation: FP mul & div • Membership test: FP sub & bit operations • Intersection calculation only when needed • The whole 2D space decomposed into 9 regions • Membership test against each plane • outcodes computed • “0000” for inside of the volume

  20. Cohen-Sutherland Clipping (cont’d) • Four cases associated with the outcodes of endpoints • o1==o2==0: both inside (AB) • o1<>0, o2==0 (or vide versa): one inside and the other outsideintersection calculation required (CD) • o1&o2<>0: outside of the common plane(edge)can be discarded (EF) • o1&o2==0: outside of the different planemore computation required (GH & IJ)

  21. Cohen-Sutherland Clipping (cont’d) • Works best when many line segments are discarded • Can be extended to three dimension • Must be recursive

  22. Liang-Barsky Clipping • Parametric form of line segment • Four parameter values computed associated with the intersections with four planes • Example • 1:bottom, 2: left, 3: top, 4: right • (a) 0<1< 2< 3< 4<1 • (b) 0<1< 3< 2< 4<1

  23. Liang-BarskyClipping (cont’d) • Intersection calculation (against top plane) • Simpler form used for clipping decision • FP div only when required • Multiple shortening not required • Not extend to three dimension

  24. More on Line Clipping • Line clipping by Wikipedia

  25. 7.5 Polygon Clipping

  26. Applications • Non-rectangular window • Shadow generation • Hidden-surface removal • Antialiasing

  27. Concave & Convex Polygons • Clipping concave polygon is complex • Clipping convex polygon is easysingle clipped polygon • Concave polygon is tessellated into convex polygons

  28. Algorithm • Sutherland-Hodgeman • Any line segment clipper can be applied blackboxed • Convex polygon (including rectangle) as the intersection of half-spaces • Intersection test against each plane

  29. Algorithm (cont’d) • Pipelined

  30. 7.6 Clipping of Other Primitives

  31. Bounding Volume • Early clipping can improve performancebounding boxes & volumes • AABB (Axis-Aligned Bounding Box) • Bounding sphere • OBB(Oriented Bounding Box) • DOP (Discrete Oriented Polytop) • Convex hull • …and many more

  32. Bounding Volume (cont’d) (image courtesy of http://www.ray-tracing.ru)

  33. Curves, Surfaces and Texts • Approximated with line segments (or triangles/quads) • “Convex hull property” for parametric curves & surfaces • Texts • Texts as bit patterns  clipping in framebuffer • Texts as geometric objects  polygon clipping • OpenGL allows both • Scissoring: clipping in the framebuffer

  34. 7.7 Clipping in Three Dimensions

  35. 3D Clipping • Clipping against 3D view volume • Extension of Cohen-Sutherland

  36. 3D Clipping (cont’d) • Extension of Liang-Barsky • Intersection calculation is simple due to normalization • Additional clipping planes with arbitrary orientations supported

  37. 7.8 Rasterization

  38. Pixels • Square-shaped • Integer coordinates • In OpenGL center is located at the halfway between integers

  39. DDA Algorithm • Rasterization of line segment • Only for small slopes • FP addition for each pixel

  40. 7.9 Bresenham’s Algorithm

  41. Bresenham’s Algorithm • No FP calculation! • Standard algorithm • For integer endpoints (x1,y1)-(x2,y2)

  42. Bresenham’sAlgorithm (cont’d) • How it works: • With slope 0<=m<=1 • Assume we just colored the pixel (i+1/2,j+1/2) • We need to color either (i+3/2,j+1/2) or (i+3/2,j+3/2)depending on d=a-b • (x2-x1)(a-b) is integer  simpler calculation • d can be computed incrementally(next page)

  43. Bresenham’s Algorithm (cont’d) • d can be computed incrementally • If a_k > b_k (left) • a_{k+1}+m=a_k a_{k+1}=a_k-m • b_k= b_{k+1}-m  b_{k+1}=b_k+m • If a_k<b_k (right) • 1+a_k=a_{k+1}+m  a_{k+1}=a_k-(m-1) • 1-b_k=m-b_{k+1}  b_{k+1}=b_k+(m-1)

  44. 7.10 Polygon Rasterization

  45. Polygon Rasterization • Inside-outside testing • Crossing (or odd-even test) • Winding test – how to compute?

  46. Tessellation • Supported by GLU functions • Triangles generated based on given contour • Different tessellation depending on the winding number (gluTessProperty)

  47. Polygon Fill • “How to fill the interior of a polygon?” • Three algorithms • Flood fill – starts with “seed point” • Scanline fill • Odd-Even fill • Singularity • Handle separately • Perturb the position • Different values for pixels and vertices

  48. 7.11 Hidden-Surface Removal

  49. Hidden-Surface Removal • Object-space approach • For each object, determine & render the visible parts • Pairwise comparison  O(k^2) • Image-space approach • For each pixel, determine the closest polygon • O(k)

  50. Scanline Algorithm • “Spans” processed independently for lighting and depth calculations • Overhead to generate spans y-x algorithm

More Related