1 / 53

ICS 415 Computer Graphics Clipping

ICS 415 Computer Graphics Clipping. Dr. Muhammed Al-Mulhem March 1, 2009. Transform. Illuminate. Transform. Clip. Project. Rasterize. Model & Camera Parameters. Rendering Pipeline. Framebuffer. Display. The Rendering Pipeline. Model World. World Camera. Why clip?.

vic
Download Presentation

ICS 415 Computer Graphics Clipping

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. ICS 415Computer Graphics Clipping Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem

  2. Transform Illuminate Transform Clip Project Rasterize Model & CameraParameters Rendering Pipeline Framebuffer Display The Rendering Pipeline ModelWorld WorldCamera Dr. Muhammed Al-Mulhem

  3. Why clip? • We don’t want to waste time rendering objects that are outside the viewing window (or clipping window) Dr. Muhammed Al-Mulhem

  4. What is clipping? • Analytically calculating the portions of primitives within the view window Dr. Muhammed Al-Mulhem

  5. View Window Eye position (focal point) Clip to what? Viewing Frustum Dr. Muhammed Al-Mulhem

  6. Transform Illuminate Transform Clip Project Rasterize Model & CameraParameters Rendering Pipeline Framebuffer Display Why illuminate before clipping? ModelWorld WorldCamera Dr. Muhammed Al-Mulhem

  7. Transform Illuminate Transform Clip Project Rasterize Model & CameraParameters Rendering Pipeline Framebuffer Display Why WorldCamera before clipping? ModelWorld WorldCamera Dr. Muhammed Al-Mulhem

  8. Why? • Why illuminate before clipping? • Why WorldCamera before clipping? • Efficiency Dr. Muhammed Al-Mulhem

  9. View Window Eye position (focal point) Clip to what? Dr. Muhammed Al-Mulhem

  10. Transform Illuminate Transform Clip Project Rasterize Model & CameraParameters Rendering Pipeline Framebuffer Display Why clip before project and rasterize? ModelWorld WorldCamera Dr. Muhammed Al-Mulhem

  11. Why Clip? • Bad idea to rasterize outside of framebuffer bounds • Also, don’t waste time scan converting pixels outside window Dr. Muhammed Al-Mulhem

  12. Clipping • The naïve approach to clipping lines: for each line segment for each edge of view_window find intersection point pick “nearest” point if anything is left, draw it • What do we mean by “nearest”? • How can we optimize this? B D C A Dr. Muhammed Al-Mulhem

  13. Trivial Accepts • Big optimization: trivial accept/rejects • How can we quickly determine whether a line segment is entirely inside the view window? • A: test both endpoints. Dr. Muhammed Al-Mulhem

  14. Trivial Rejects • How can we know a line is outside view window? • A: if both endpoints on wrong side of same edge, can trivially reject line Dr. Muhammed Al-Mulhem

  15. Clipping Lines To View Window • Combining trivial accepts/rejects • Trivially accept lines with both endpoints inside all edges of the view window • Trivially reject lines with both endpoints outside the same edge of the view window • Otherwise, reduce to trivial casesby splitting into two segments Dr. Muhammed Al-Mulhem

  16. Cohen-Sutherland Line Clipping • Divide view window into regions defined by window edges • Assign each region a 4-bit outcode: Bit 1 indicates y-value of points are above ymax ymax 1001 1000 1010 xmax 0001 0000 0010 0101 0100 0110 Dr. Muhammed Al-Mulhem

  17. Cohen-Sutherland Line Clipping • For each line segment • Assign an outcode to each vertex • If both outcodes = 0, trivial accept • Same as performing if (bitwise OR = 0) • Else • bitwise AND vertex outcodes together • if result  0, trivial reject Dr. Muhammed Al-Mulhem

  18. Cohen-Sutherland Line Clipping • If line cannot be trivially accepted or rejected, subdivide so that one or both segments can be discarded • Pick an edge of view window that the line crosses (how?) • Intersect line with edge (how?) • Discard portion on wrong side of edge and assign new outcode to new vertex • Apply trivial accept/reject tests; repeat if necessary Dr. Muhammed Al-Mulhem

  19. Cohen-Sutherland Line Clipping • If line cannot be trivially accepted or rejected, subdivide so that one or both segments can be discarded • Pick an edge that the line crosses • Check against edges in same order each time • (For example: top, bottom, right, left) E D C B A Dr. Muhammed Al-Mulhem

  20. E D C B A Cohen-Sutherland Line Clipping • Intersect line with edge (how?) – Chapter 6. Dr. Muhammed Al-Mulhem

  21. Cohen-Sutherland Line Clipping • Discard portion on wrong side of edge and assign outcode to new vertex • Apply trivial accept/reject tests and repeat if necessary D C B A Dr. Muhammed Al-Mulhem

  22. Cohen-Sutherland Line Clipping • Discard portion on wrong side of edge and assign outcode to new vertex • Apply trivial accept/reject tests and repeat if necessary C B A Dr. Muhammed Al-Mulhem

  23. View Window Intersection Code • (x1, y1), (x2, y2) intersect with vertical edge at xright • yintersect = y1 + m(xright – x1) • where m=(y2-y1)/(x2-x1) • (x1, y1), (x2, y2) intersect with horizontal edge at ybottom • xintersect = x1 + (ybottom – y1)/m • where m=(y2-y1)/(x2-x1) Dr. Muhammed Al-Mulhem

  24. Cohen-Sutherland Review • Use Outodes to quickly eliminate/include lines • Best algorithm when trivial accepts/rejects are common • Must compute viewing window clipping of remaining lines • Non-trivial clipping cost • Redundant clipping of some lines • More efficient algorithms exist Dr. Muhammed Al-Mulhem

  25. Solving Simultaneous Equations • Equation of a line • Slope-intercept (explicit equation): y = mx + b • Implicit Equation: Ax + By + C = 0 • Parametric Equation: Line defined by two points, P0 and P1 • P(t) = P0 + (P1 - P0) t, where P is a vector [x, y]T • x(t) = x0 + (x1 - x0) t • y(t) = y0 + (y1 - y0) t Dr. Muhammed Al-Mulhem

  26. Parametric Line Equation • Describes a finite line • Works with vertical lines (like the view window edge) • 0 <=t <= 1 • Defines line between P0 and P1 • t < 0 • Defines line before P0 • t > 1 • Defines line after P1 Dr. Muhammed Al-Mulhem

  27. Parametric Lines and Clipping • Define each line in parametric form: • P0(t)…Pn-1(t) • Define each edge of view window in parametric form: • PL(t), PR(t), PT(t), PB(t) • Perform Cohen-Sutherland intersection tests using appropriate view window edge and line Dr. Muhammed Al-Mulhem

  28. Line / Edge Clipping Equations • Faster line clippers use parametric equations • Line 0: • x0 = x00 + (x01 - x00) t0 • y0 = y00 + (y01 - y00) t0 • x00 + (x01 - x00) t0 = xL0 + (xL1 - xL0) tL • y00 + (y01 - y00) t0 = yL0 + (yL1 - yL0) tL • Solve for t0 and/or tL • View Window Edge L: • xL = xL0 + (xL1 - xL0) tL • yL = yL0 + (yL1 - yL0) tL Dr. Muhammed Al-Mulhem

  29. Cyrus-Beck Algorithm • We wish to optimize line/line intersection • Start with parametric equation of line: • P(t) = P0 + (P1 - P0) t • And a point and normal for each edge • PL, NL Dr. Muhammed Al-Mulhem

  30. PL P(t) Inside NL Cyrus-Beck Algorithm P1 • Find t such that • NL [P(t) - PL] = 0 • Substitute line equation for P(t): • NL [P0 + (P1 - P0) t - PL] = 0 • Solve for t • t = NL [PL – P0] / -NL [P1 - P0] P0 Dr. Muhammed Al-Mulhem

  31. Cyrus-Beck Algorithm • Compute t for line intersection with all four edges • Discard all (t < 0) and (t > 1) • Classify each remaining intersection as • Potentially Entering (PE) • Potentially Leaving (PL) • NL [P1 - P0] > 0 implies PL • NL [P1 - P0] < 0 implies PE Dr. Muhammed Al-Mulhem

  32. P1 PL PL PE PE P0 Cyrus-Beck Algorithm • Compute PE with largest t • Compute PL with smallest t • Clip to these two points Dr. Muhammed Al-Mulhem

  33. Cyrus-Beck Algorithm • Because of horizontal and vertical clip lines: • Many computations reduce • Normals: (-1, 0), (1, 0), (0, -1), (0, 1) • Pick constant points on edges • solution for t: • -(x0 - xleft) / (x1 - x0) • (x0 - xright) / -(x1 - x0) • -(y0 - ybottom) / (y1 - y0) • (y0 - ytop) / -(y1 - y0) Dr. Muhammed Al-Mulhem

  34. Comparison • Cohen-Sutherland • Repeated clipping is expensive • Best used when trivial acceptance and rejection is possible for most lines • Cyrus-Beck • Computation of t-intersections is cheap • Computation of (x,y) clip points is only done once • Algorithm doesn’t consider trivial accepts/rejects • Best when many lines must be clipped • Liang-Barsky: Optimized Cyrus-Beck • Nicholl et al.: Fastest, but doesn’t do 3D Dr. Muhammed Al-Mulhem

  35. Clipping Polygons • Clipping polygons is more complex than clipping the individual lines • Input: polygon • Output: Original polygon, new polygon, or nothing • Optimization • The biggest line optimizer we had was trivial accept or reject. • When can we trivially accept/reject a polygon as opposed to the line segments that make up the polygon? Dr. Muhammed Al-Mulhem

  36. Why Is Clipping Hard? • What happens to a triangle during clipping? • Possible outcomes: triangle  quad triangle  5-gon triangle  triangle • How many sides can a clipped triangle have? Dr. Muhammed Al-Mulhem

  37. How many sides? • Seven… Dr. Muhammed Al-Mulhem

  38. Why Is Clipping Hard? • A really tough case: Dr. Muhammed Al-Mulhem

  39. Why Is Clipping Hard? • A really tough case: concave polygon  multiple polygons Dr. Muhammed Al-Mulhem

  40. Sutherland-Hodgman Clipping • Basic idea: • Consider each edge of the view window individually • Clip the polygon against the view window edge’s equation Dr. Muhammed Al-Mulhem

  41. Sutherland-Hodgman Clipping • Basic idea: • Consider each edge of the viewport individually • Clip the polygon against the edge equation Dr. Muhammed Al-Mulhem

  42. Sutherland-Hodgman Clipping • Basic idea: • Consider each edge of the viewport individually • Clip the polygon against the edge equation Dr. Muhammed Al-Mulhem

  43. Sutherland-Hodgman Clipping • Basic idea: • Consider each edge of the viewport individually • Clip the polygon against the edge equation Dr. Muhammed Al-Mulhem

  44. Sutherland-Hodgman Clipping • Basic idea: • Consider each edge of the viewport individually • Clip the polygon against the edge equation Dr. Muhammed Al-Mulhem

  45. Sutherland-Hodgman Clipping • Basic idea: • Consider each edge of the viewport individually • Clip the polygon against the edge equation Dr. Muhammed Al-Mulhem

  46. Sutherland-Hodgman Clipping • Basic idea: • Consider each edge of the viewport individually • Clip the polygon against the edge equation Dr. Muhammed Al-Mulhem

  47. Sutherland-Hodgman Clipping • Basic idea: • Consider each edge of the viewport individually • Clip the polygon against the edge equation Dr. Muhammed Al-Mulhem

  48. Sutherland-Hodgman Clipping • Basic idea: • Consider each edge of the viewport individually • Clip the polygon against the edge equation Dr. Muhammed Al-Mulhem

  49. Sutherland-Hodgman Clipping • Basic idea: • Consider each edge of the viewport individually • Clip the polygon against the edge equation • After doing all edges, the polygon is fully clipped Dr. Muhammed Al-Mulhem

  50. Sutherland-Hodgman Clipping • Input/output for algorithm: • Input: List of polygon vertices in order. • Output: List of clipped polygon vertices consisting of old vertices (maybe) and new vertices (maybe). • Note: this is exactly what we expect from the clipping operation against each edge Dr. Muhammed Al-Mulhem

More Related