Presentation is loading. Please wait.

Presentation is loading. Please wait.

Hidden Surface Removal Why make the effort?  Realistic models.  Wasted time drawing. OpenGL and HSR  OpenGL does handle HSR using the depth buffer.

Similar presentations


Presentation on theme: "Hidden Surface Removal Why make the effort?  Realistic models.  Wasted time drawing. OpenGL and HSR  OpenGL does handle HSR using the depth buffer."— Presentation transcript:

1 Hidden Surface Removal Why make the effort?  Realistic models.  Wasted time drawing. OpenGL and HSR  OpenGL does handle HSR using the depth buffer. Why find other methods?  Time and space.  Efficiency in specific cases. So what is hidden line removal?

2 Object versus Image Object Precision  Uses machine precision to compute the coordinates of the visible faces.  Allows for enlargement with accurate results. Image Precision  Per Pixel approach.  Precision is only to the screen coordinate system.

3 Suggested Code class Face { int Verts; Point* pt; float* depth; Plane plane; Cuboid extent; }

4 Hidden Line Removal HLR as HSR  Device must allow “Painting over”. Essential considerations  Only need to clip lines against “front” faces.  If the edge belongs to two back faces it is not visible. The rest of HLR is the same as HSR  Except one clips an edge instead of a face.

5 Finally! Techniques!

6 Depth-Buffer Pros:  No Sorting  Makes use of depth coherence  Works with many classes of objects  File saving for another session Cons:  Re-draw pixels having to re-do expensive shading calculations  Large memory usage (Precision dependant)

7 Area Subdivision Method makes use of Area coherence. How does it work?  Divide and conquer.  Terminates on “simple” or too small regions.  Geometry of division is important. Some definitions of “Simple”  Only one face is involved  Empty  Dominating face Vertex Division Geometry  Select a vertex in the region and divide along it.

8 More HSR Algorithms Algorithms Already Covered  Depth-Buffer  Area Sub-Division Algorithms To Follow  A Scan Line Algorithm = good for static scenes (per pixel tests)  3 List-Priority Algorithms: 1. Heedless Painter = simple but wrong 1. Heedless Painter = simple but wrong 2. Depth-Sort = improvement on painter 2. Depth-Sort = improvement on painter 3. BSP Trees = elegant (dynamic) 3. BSP Trees = elegant (dynamic)

9 Scan-Line Algorithm 1 Brute Force Algorithm Overview: 1. depth on a per pixel basis. 2. convention – a horizontal scan lines, scanned top to bottom. Brute Force Algorithm Pseudocode: For( each scan line, y){ For( each pixel, x, on scan line y){ For( each pixel, x, on scan line y){ Find the closest face for the pixel at (x,y) Find the closest face for the pixel at (x,y) Set the pixel at (x,y) to the colour of the closest face at (x,y) Set the pixel at (x,y) to the colour of the closest face at (x,y) }}

10 Scan-Line Algorithm 2 A Faster Algorithm Overview 1. Same as brute force (scan left to right & per pixel basis) 2. But it exploits edge-coherence along the scan-line. 3. An Active-Edge List (AEL) Is constructed AEL stores all the x values at which a given scan-line intersects an edge.

11 For( each scan line, y){ For( each new AEL x-range){ For( each new AEL x-range){ Find the closest face for the pixel at (x,y) at AEL( i ) Find the closest face for the pixel at (x,y) at AEL( i ) For( x > AEL( i ) and x AEL( i ) and x < AEL( i+1 ) ){ Set the pixel at (x,y) to the colour of the closest face at (x,y) Set the pixel at (x,y) to the colour of the closest face at (x,y) If( at AEL (i+1) closest face != closest face at AEL(i)){ If( at AEL (i+1) closest face != closest face at AEL(i)){ find the x value at which the intersection occurred find the x value at which the intersection occurred Correct the pixels between this intersection@x and AEL (i+1) Correct the pixels between this intersection@x and AEL (i+1) } } }} Faster Scan-Line Algorithm Pseudocode:

12 Heedless Painter Heedless Painter Algorithm Overview 1. Simple but Incorrect. 2. Sorts the array of faces by the depth of its bounding box. 3. Draws from the greatest depth to the closest depth Heedless Painter Algorithm Pseudocode: Sort_By_Descending_Depth( FACES[] ) While( i < number of faces) Draw FACES[ i ]

13 Problems with the Heedless Painter Algorithm 1. Cant deal with polygon intersections. 2. In general it cant deal with case where the z extent of the bounding boxes intersect. The algorithm draws Polygon 1 first then Polygon 2.

14 Depth-Sort Algorithm Depth-Sort Algorithm Overview: 1. Similar to Heedless painter but it works. 2. Sorts the array of faces by the depth of its bounding box. 3. Deals with problematic faces, and re-sorts the faces. 4. Draws from the greatest depth to the closest depth It splits the faces until for any pair of faces, one lies either behind or in front of the other (removes intersections).

15 Sort_By_Descending_Depth( FACES[] ) /* split faces if required and resort FACES[] */ While( i < number of faces){ For( every other FACES[j]){ For( every other FACES[j]){ if(FACES[j] trivially does not obscure FACES[i]) continue //try next face if(FACES[j] trivially does not obscure FACES[i]) continue //try next face /*face either intersects or face is incorrectly hidden by another face*/ /*face either intersects or face is incorrectly hidden by another face*/ if(face j is hidden by face i) { if(face j is hidden by face i) { move face j to the start of the list move face j to the start of the list }else{ }else{ split face j by the plane of face i split face j by the plane of face i insert pieces of j in list } insert pieces of j in list } }} While( i < number of faces) Draw FACES[ i ] Depth-Sort Algorithm Pseudocode:

16 BSP Tree Algorithm BSP Tree Algorithm Overview: 1. BSP Tree (Binary-Space Partition Tree) 2. Elegant and efficient, especially in dynamic situations. 3. The faces are preprocessed into a binary-tree (each node has 2 children) (each node has 2 children) 4. Some faces are split, and placed in the tree 5. Each node contains a single face 6. The tree is traversed in a particular order, such that HSR is accomplished.


Download ppt "Hidden Surface Removal Why make the effort?  Realistic models.  Wasted time drawing. OpenGL and HSR  OpenGL does handle HSR using the depth buffer."

Similar presentations


Ads by Google