240 likes | 268 Views
Learn about visible surface detection techniques such as back-face culling, depth-buffer method, scan-line method, and depth-sorting method used in computer graphics. Understand how to determine visible surfaces within a scene, reduce intersection calculations, and implement depth-buffer algorithms. This comprehensive guide covers object-space and image-space approaches for hidden-surface elimination, efficient sorting algorithms, and considerations for rendering accurate 3D views. Watch the tutorial to enhance your computer vision and pattern recognition skills.
E N D
Computer Graphics Chapter 16 Visible-Surface Detection Methods
3D Viewing https://www.youtube.com/watch?v=TEAtmCYYKZA Computer Vision & Pattern Recognition Lab.
1. Classification • Visible-Surface Detection (Hidden-Surface Elimination) • What is visible within a scene from a chosen viewing position? • Two approaches: (1) Object-space approach -. To compare objects to each other to determine which surfaces are visible. -. O(n2) : n is the number of objects -. Good for images with small number of objects (2) Image-space approach -. Visibility is decided point by point at each pixel position -. O(np) : p is the number of pixels -. constant performance over a class of problems Computer Vision & Pattern Recognition Lab.
2. Back-Face Detection • Back-face test (Back-face culling) • Useful if an object is closed and opaque. • Considering the direction of surface normal and viewing direction • A polygon is a back face if • If the viewing direction is along negative zv axis, A polygon is a back face if Computer Vision & Pattern Recognition Lab.
3. Depth-Buffer (z-Buffer) Method • Image-space approach (No object comparison) • Algorithm: * Depth values range from 0(nearest) to 1.0(farthest) 1. Initialization: depthBuff(x,y) =1.0, frameBuff(x,y)=backgndColor 2. For each polygon For each projected (x,y) pixel position of a polygon pz = z value at pixel (x,y) if pz < depthBuff(x,y) { /* if it is closer */ depthBuff(x,y) = pz frameBuff(x,y) = surfaceColor(x,y) } Computer Vision & Pattern Recognition Lab.
3. Depth-Buffer (z-Buffer) Method Computer Vision & Pattern Recognition Lab.
3. Depth-Buffer (z-Buffer) Method • Easy to implement (Hardware/Software) • z-Buffer is required (same size as frame buffer) • Execution time is independent of the number of polygons for approximating a surface • No intersection calculation is needed • z sort : one comparison per pixel of a polygon • How many bits for storing depth? 16, 32 bits • Cutaway view can be easily obtained. • Before calculating z, perspective transformation in order to handle perspective projection same as parallel projection • Simplified calculation of z : z = (-Ax-By-D)/C Ax+By+Cz+D = 0 Given z(x,y), z(x+1,y) = z(x,y) - A/C Computer Vision & Pattern Recognition Lab.
Z-buffer 알고리즘 Z-buffer 의 초기화 갈색 삼각형 처리결과
Z-buffer 알고리즘 갈색 삼각형 처리결과 녹색 삼각형 처리결과
5. Scan-Line Method • Similar to scan-line polygon filling • One scan line at a time with a set of polygons • Algorithm: For each scan line Find all intersections, and sort them. For each intersection from left to right Update in-out flag, #IN (in-out flag for each polygon: toggle, #IN: increment/decrement) If #IN = 0, move to next intersection else if #IN =1, draw a line to next intersection else if #IN > 1, find the closest polygon and draw Computer Vision & Pattern Recognition Lab.
6. Depth-Sorting Method • Painter’s algorithm, List-priority algorithm • Draw surfaces from back (farthest away) to front (closest): • Sort surfaces/polygons by their depth (z value) • Draw objects in order (farthest to closest) • Closer objects paint over the top of farther away objects Computer Vision & Pattern Recognition Lab.
6. Depth-Sorting Method • Draw objects in order (farthest to closest)Object-space approach • Problem: How to determine the sorted order • Algorithm: 1. Sort all polygons according to farthest z coordinate. 2. Resolve ambiguity when z extents overlap. Split polygon if necessary. 3. Paint polygons back to front. • Efficient for small number of polygons/objects: O(n2) Computer Vision & Pattern Recognition Lab.
6. Depth-Sorting Method • Refinement of Step 2: S: farthest polygon (currently considered) Before painting S, test against each poly S’ whose z extent overlaps If all S’ pass one of following 4 tests, paint S 1. Bounding rectangle not overlap? (Fig 16-13) 2. Is S completely behind S’? (Fig 16-14) 3. Is S’ completely in front of S? (Fig 16-15) 4. Projections of polygon not overlap? (Fig 16-16) else { test if S’ can be painted before S (test 2,3) True --> Move S’ to the end of list : (Fig 16-17) False --> Split either S or S’ } • Special case (infinite loop) --> Split Computer Vision & Pattern Recognition Lab.
8. Area-Subdivision Method • Idea: As areas become smaller, fewer polygons overlap and decision becomes possible. • Subdivide area into 4 equal squares Case 1: Surrounding surface Case 2: Overlapping surface Case 3: Inside surface Case 4: Outside surface Computer Vision & Pattern Recognition Lab.
8. Area-Subdivision Method • Decision rule: 1. If all surfaces are outside the area, display background. 2. If there exists only one inside or overlapping surface, paint with background and then display part of the surface. 3. If there is only one surrounding surface, fill the area with that surface. 4. If one surrounding surface that obscure all other surfaces, fill the area with that surface. (Compute z coor. of all planes at 4 corners of area by using poly. eq.) 5. If none of above, subdivide further. Computer Vision & Pattern Recognition Lab.
Initial scene 8. Area-Subdivision Method
First subdivision 8. Area-Subdivision Method
Second subdivision 8. Area-Subdivision Method
Third subdivision 8. Area-Subdivision Method
Fourth subdivision 8. Area-Subdivision Method
10. Ray-Casting Method A D E Image plane Viewer C Eye View Plane B
10. Ray-Casting Method • To cast imaginary rays of light from a pixel position on the view plane through a scene Image-space approach: O(np) • Algorithm: Select COP and window on view plane; for (each scan line in image) { for (each pixel in scan line) { determine ray from COP thru pixel; for (each object in scene) { if (object is intersected and is closest considered thus far) record intersection(depth) and object information; } set pixel's color to that at closest object intersection; } } Computer Vision & Pattern Recognition Lab.
10. Ray-Casting Method • Computing intersection : Use parametric representation x = x0 + t*(x1-x0), y = y0 + t*(y1-y0), z = z0 + t*(z1-z0), t > 0 (1) Sphere (x-a)2 + (y-b)2 + (z-c)2 = r2 Substitute x,y,z quadratic in t Solve for t. if no real root, no intersection else if one root, one intersection else find the one with smallest positive t (2) Polygon Determine whether the ray intersects polygon's surface: Mostly trivial Determine whether the intersection lies within the polygon (Use orthographic projection and polygon containment test) Computer Vision & Pattern Recognition Lab.
11. Comparison • Comparing visible-surface algorithms is difficult because of - data/application dependence - different assumptions - relevance to shading - ease of implementation/modification • "Depth sort" is efficient for small(<10000) number of polygons. • "z-buffer" is efficient for scenes with more than a few thousand surfaces. • When there are few overlaps of surfaces, scan-line or area-subdivision approach is a fast method. • If a scene contains curved-surfaces, ray-casting method is useful. • Ray casting is a good candidate for parallel implementation. Computer Vision & Pattern Recognition Lab.