Hidden Surface Removal Why make the effort? Realistic models. Wasted time drawing. OpenGL and HSR ...

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

Transcript of Hidden Surface Removal Why make the effort? Realistic models. Wasted time drawing. OpenGL and HSR ...

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

Hidden Surface RemovalHidden Surface RemovalWhy make the effort?Why make the effort? Realistic models.Realistic models. Wasted time drawing.Wasted time drawing.

OpenGL and HSROpenGL and HSR OpenGL does handle HSR using the depth buffer.OpenGL does handle HSR using the depth buffer.

Why find other methods?Why find other methods? Time and space.Time and space. Efficiency in specific cases.Efficiency in specific cases.

So what is hidden line removal?So what is hidden line removal?

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

Object versus ImageObject versus ImageObject PrecisionObject Precision Uses machine precision to compute the coordinates of the Uses machine precision to compute the coordinates of the

visible faces.visible faces. Allows for enlargement with accurate results.Allows for enlargement with accurate results.

Image PrecisionImage Precision Per Pixel approach.Per Pixel approach. Precision is only to the screen coordinate system.Precision is only to the screen coordinate system.

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

Suggested CodeSuggested Codeclass Faceclass Face

{{

int Verts;int Verts;

Point* pt;Point* pt;

float* depth;float* depth;

Plane plane;Plane plane;

Cuboid extent;Cuboid extent;

}}

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

Hidden Line RemovalHidden Line RemovalHLR as HSRHLR as HSR Device must allow “Painting over”.Device must allow “Painting over”.

Essential considerationsEssential considerations Only need to clip lines against “front” faces.Only need to clip lines against “front” faces. If the edge belongs to two back faces it is not visible.If the edge belongs to two back faces it is not visible.

The rest of HLR is the same as HSRThe rest of HLR is the same as HSR Except one clips an edge instead of a face.Except one clips an edge instead of a face.

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

Finally! Finally! Techniques!Techniques!

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

Depth-BufferDepth-BufferPros:Pros: No SortingNo Sorting Makes use of depth coherenceMakes use of depth coherence Works with many classes of objectsWorks with many classes of objects File saving for another sessionFile saving for another session

Cons:Cons: Re-draw pixels having to re-do expensive shading Re-draw pixels having to re-do expensive shading

calculationscalculations Large memory usage (Precision dependant)Large memory usage (Precision dependant)

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

Area SubdivisionArea SubdivisionMethod makes use of Area coherence.Method makes use of Area coherence.

How does it work?How does it work? Divide and conquer.Divide and conquer. Terminates on “Terminates on “simplesimple” or too small regions.” or too small regions. Geometry of division is important.Geometry of division is important.

Some definitions of “Simple”Some definitions of “Simple” Only one face is involvedOnly one face is involved EmptyEmpty Dominating faceDominating face

Vertex Division GeometryVertex Division Geometry Select a vertex in the region and divide along it.Select a vertex in the region and divide along it.

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

More HSR AlgorithmsMore HSR AlgorithmsAlgorithms Already CoveredAlgorithms Already Covered Depth-Buffer Depth-Buffer Area Sub-Division Area Sub-Division

Algorithms To FollowAlgorithms To Follow A Scan Line Algorithm = good for static scenes (per pixel A Scan Line Algorithm = good for static scenes (per pixel

tests)tests) 3 List-Priority Algorithms:3 List-Priority Algorithms:

1. Heedless Painter = simple but wrong1. Heedless Painter = simple but wrong 2. Depth-Sort = improvement on painter2. Depth-Sort = improvement on painter 3. BSP Trees = elegant (dynamic)3. BSP Trees = elegant (dynamic)

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

Scan-Line Algorithm 1Scan-Line Algorithm 1Brute Force Algorithm Overview:Brute Force Algorithm Overview: 1. depth on a per pixel basis.1. depth on a per pixel basis.

2. convention – a horizontal scan lines, scanned top to bottom.2. convention – a horizontal scan lines, scanned top to bottom.

Brute Force Algorithm Pseudocode:Brute Force Algorithm Pseudocode:

For( each scan line, y){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 Set the pixel at (x,y) to the colour of the closest face at (x,y) (x,y)

}}

}}

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

Scan-Line Algorithm 2Scan-Line Algorithm 2A Faster Algorithm OverviewA Faster Algorithm Overview1. Same as brute force (scan left to right & per pixel basis)1. Same as brute force (scan left to right & per pixel basis)

2. But it exploits edge-coherence along the scan-line.2. But it exploits edge-coherence along the scan-line.

3. An Active-Edge List (AEL) Is constructed3. An Active-Edge List (AEL) Is constructed

AEL stores all the x values at which a given scan-line intersects an AEL stores all the x values at which a given scan-line intersects an edge.edge.

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

For( each scan line, y){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+1 ) ){For( 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 occurredfind 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:Faster Scan-Line Algorithm Pseudocode:

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

Heedless Painter Heedless Painter Heedless Painter Algorithm OverviewHeedless Painter Algorithm Overview1. Simple but Incorrect.1. Simple but Incorrect.

2. Sorts the array of faces by the depth of its bounding box.2. Sorts the array of faces by the depth of its bounding box.

3. Draws from the greatest depth to the closest depth3. Draws from the greatest depth to the closest depth

Heedless Painter Algorithm Pseudocode:Heedless Painter Algorithm Pseudocode:

Sort_By_Descending_Depth( FACES[] )Sort_By_Descending_Depth( FACES[] )

While( i < number of faces) Draw FACES[ i ] While( i < number of faces) Draw FACES[ i ]

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

Problems with the Heedless Painter AlgorithmProblems with the Heedless Painter Algorithm1. Cant deal with polygon intersections.1. Cant deal with polygon intersections.

2. In general it cant deal with case where the z extent of the 2. In general it cant deal with case where the z extent of the bounding boxes intersect.bounding boxes intersect.

The algorithm draws Polygon 1 first then Polygon 2.The algorithm draws Polygon 1 first then Polygon 2.

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

Depth-Sort AlgorithmDepth-Sort AlgorithmDepth-Sort Algorithm Overview:Depth-Sort Algorithm Overview:1. Similar to Heedless painter but it works.1. Similar to Heedless painter but it works.

2. Sorts the array of faces by the depth of its bounding box.2. Sorts the array of faces by the depth of its bounding box.

3. Deals with problematic faces, and re-sorts the faces.3. Deals with problematic faces, and re-sorts the faces.

4. Draws from the greatest depth to the closest depth4. Draws from the greatest depth to the closest depth

It splits the faces until for any pair of faces, one lies either behindIt splits the faces until for any pair of faces, one lies either behind

or in front of the other (removes intersections).or in front of the other (removes intersections).

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

Sort_By_Descending_Depth( FACES[] )Sort_By_Descending_Depth( FACES[] )

/* split faces if required and resort FACES[] *//* split faces if required and resort FACES[] */

While( i < number of 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 faceif(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 listmove face j to the start of the list

}else{}else{

split face j by the plane of face isplit 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 ] While( i < number of faces) Draw FACES[ i ]

Depth-Sort Algorithm Pseudocode:Depth-Sort Algorithm Pseudocode:

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

BSP Tree AlgorithmBSP Tree AlgorithmBSP Tree Algorithm Overview:BSP Tree Algorithm Overview:1. BSP Tree (Binary-Space Partition Tree) 1. BSP Tree (Binary-Space Partition Tree)

2. Elegant and efficient, especially in dynamic situations.2. Elegant and efficient, especially in dynamic situations.

3. The faces are preprocessed into a binary-tree 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 tree4. Some faces are split, and placed in the tree

5. Each node contains a single face5. Each node contains a single face

6. The tree is traversed in a particular order, such that HSR is 6. The tree is traversed in a particular order, such that HSR is accomplished.accomplished.