Today CS-184: Computer Graphics Lecture #10: Clipping and Hidden Surfaces!! Prof. James O Brien University of California, Berkeley! V2015-S-10-1.0 Clipping Clipping to view volume Clipping arbitrary polygons Hidden Surface Removal Z-Buffer BSP Trees Others 2 1 2
Clipping Clipping Stuff outside view volume should not be drawn Too close: obscures view Stuff outside view volume should not be drawn Too close: obscures view Too far: Complexity Z-buffer problems Too high/low/right/left: Memory errors Broken algorithms Complexity 3 4 3 4
Clipping Line to Line/Plane Clipping Line to Line/Plane Line segment to be clipped x(t)=a +t(b a) a Line segment to be clipped x(t)=a +t(b a) a ˆn b ˆn b Line/plane that clips it ˆn x ˆn r = 0 r } Line/plane that clips it ˆn x f = 0 ˆn (a +t(b a)) f = 0 t = f ˆn a ˆn d ˆn a +t(ˆn (b a)) f = 0 5 6 5 6
Clipping Line to Line/Plane Triangle Clip/Split Segment may be on one side a c + c + c + t 62 [0...1] ˆn b Lines may be parallel ˆn d = 0 t = f ˆn a ˆn d - a - - a b - - a b - b ˆn d appleε (Recall comments about numerical issues) Double vertices if you want separation... 7 8 7 8
Polygon Clip to Convex Domain Polygon Clipping Find the part of a polygon inside the clip window? Convex domain defined by collection of planes (or lines or hyper-planes) Planes have outward pointing normals Clip against each plane in turn Check for early/trivial rejection Before Clipping 9 9 10
Polygon Clipping Find the part of a polygon inside the clip window? Sutherland-Hodgman Clipping Clip to each window boundary one at a time After Clipping 11 12
Sutherland-Hodgman Clipping Clip to each window boundary one at a time Sutherland-Hodgman Clipping Clip to each window boundary one at a time 13 14
Sutherland-Hodgman Clipping Clip to each window boundary one at a time Sutherland-Hodgman Clipping Clip to each window boundary one at a time 15 16
Polygon Clip to Convex Domain Polygon Clip to Convex Domain Inside Outside Inside Outside Inside Outside Inside Outside s p p i s Note double edges. p Output p s i p Output i s No output Output i and p 18 17 17 18
Polygon Clip to Convex Domain General Polygon Clipping A B A B Sutherland-Hodgman algorithm Basically edge walking Clipping done often... should be efficient B A Liang-Barsky parametric space algorithm See text for clipping in 4D homogenized coordinates A [ B 19 A \ B 20 19 20
General Polygon Clipping Weiler Algorithm Double edges Hidden Surface Removal True 3D to 2D projection would put every thing overlapping into the view plane. We need to determine what s in front and display only that. 21 22 21 22
Z-Buffers Add extra depth channel to image Write Test Z-Buffers Z values when writing pixels Benefits Z values before writing Easy to implement Works for most any geometric primitive Parallel operation in hardware Images from Okan Arikan Limitations Quantization and aliasing artifacts Overfill Transparency does not work well 23 23 24 24
Z-Buffers Z-Buffers Transparency requires partial sorting: Partially transparent Opaque 3rd 2nd Front Partially transparent Opaque 1st 3rd Recall depth-value distortions.! It s a feature... More resolution near viewer Best use of limited precision Opaque 1st Opaque 2nd Good Not Good 25 26 25 26
A-Buffers Scan-line Algorithm Store sorted list of fragments at each pixel Draw all opaque stuff first then transparent Stuff behind full opacity gets ignored Assume polygons don t intersect Each time an edge is crossed determine who s on top! Nice for antialiasing... 27 28 27 28
Painter s Algorithm BSP-Trees Sort Polygons Front-to-Back Draw in order Back-to-Front works also, but wasteful How to sort quickly? Intersecting polygons? Cycles? Binary Space Partition Trees Split space along planes Allows fast queries of some spatial relations Draw Front-to-Back Draw same-side polygons first Draw root node polygon (if any) Draw other-side polygons last 29 30 29 30