Hidden surfaces
Download
1 / 68

Hidden Surfaces - PowerPoint PPT Presentation


  • 68 Views
  • Uploaded on

Hidden Surfaces. Dr. Scott Schaefer. Hidden Surfaces. Hidden Surfaces. Hidden Surfaces. Backface Culling. Backface Culling. view direction. Backface Culling. view direction. Backface Culling. , draw polygon. view direction. Backface Culling. , cull polygon. view direction.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Hidden Surfaces' - stormy


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Hidden surfaces

Hidden Surfaces

Dr. Scott Schaefer






Backface culling1
Backface Culling

view direction


Backface culling2
Backface Culling

view direction


Backface culling3
Backface Culling

, draw polygon

view direction


Backface culling4
Backface Culling

, cull polygon

view direction



Backface culling6
Backface Culling

counter clock-wise orientation, draw polygon


Backface culling7
Backface Culling

clock-wise orientation, cull polygon


Backface culling8
Backface Culling

  • Advantages

    • Improves rendering speed by removing roughly half of polygons from scan conversion

  • Disadvantages

    • Assumes closed surface with consistently oriented polygons

    • NOT a true hidden surface algorithm!!!


Backface culling9
Backface Culling

  • Is this all we have to do?


Backface culling10
Backface Culling

  • Is this all we have to do? No!

    • Can still have 2 (or more) front faces that map to the same screen pixel


Backface culling11
Backface Culling

  • Is this all we have to do? No!

    • Can still have 2 (or more) front faces that map to the same screen pixel

    • Which actually gets drawn?


Painter s algorithm
Painter’s Algorithm

  • Sort polygons according to distance from viewer

  • Draw from back to front

  • How do we sort polygons?


Painter s example

z = 0.7

z = 0.3

z = 0.1

z = 0

Painter’s Example

Sort by depth:

Green rect

Red circle

Blue tri



Painter s algorithm2
Painter’s Algorithm

  • Sometimes there is NO ordering that produces correct results!!!


Painter s algorithm3
Painter’s Algorithm

  • Sort all objects’ zmin and zmax


Painter s algorithm4
Painter’s Algorithm

  • Sort all objects’ zmin and zmax

  • If an object is uninterrupted (its zmin and zmax are adjacent in the sorted list), it is fine


Painter s algorithm5
Painter’s Algorithm

  • Sort all objects’ zmin and zmax

  • If an object is uninterrupted (its zmin and zmax are adjacent in the sorted list), it is fine

  • If 2 objects DO overlap

    3.1 Check if they overlap in x

    - If not, they are fine

    3.2 Check if they overlap in y

    - If not, they are fine

    - If yes, need to split one


Painter s algorithm6
Painter’s Algorithm

  • The splitting step is the tough one

    - Need to find a plane to split one polygon by so that each new polygon is entirely in front of or entirely behind the other

    - Polygons may actually intersect, so then need to split each polygon by the other


Painter s algorithm7
Painter’s Algorithm

  • The splitting step is the tough one

    - Need to find a plane to split one polygon by so that each new polygon is entirely in front of or entirely behind the other

    - Polygons may actually intersect, so then need to split each polygon by the other

  • After splitting, you can resort the list and should be fine


Painter s algorithm summary
Painter’s Algorithm-Summary

  • Advantages

    • Simple algorithm for ordering polygons

  • Disadvantages

    • Sorting criteria difficult to produce

    • Redraws same pixel many times

    • Sorting can also be expensive


Depth z buffer
Depth (“Z”) Buffer

  • Simple modification to scan-conversion

  • Maintain a separate buffer storing the closest “z” value for each pixel

  • Only draw pixel if depth value is closer than stored “z” value

    • Update buffer with closest depth value


Depth z buffer1
Depth (“Z”) Buffer

  • Advantages

    • Simple to implement

    • Allows for a streaming approach to polygon drawing

  • Disadvantages

    • Requires extra storage space

    • Still lots of overdraw


Binary space partitioning trees
Binary Space Partitioning Trees

  • BSP tree: organize all of space (hence partition)into a binary tree

    - Preprocess: overlay a binary tree on objects in the scene

    - Runtime: correctly traversing this tree enumerates objects from back to front

    - Idea: divide space recursively into half-spaces by choosing splitting planes

    • Splitting planes can be arbitrarily oriented


Bsp trees objects
BSP Trees: Objects

9

8

7

6

5

4

1

2

3


Bsp trees objects1
BSP Trees: Objects

9

-

8

+

7

6

5

4

1

2

3


Bsp trees objects2
BSP Trees: Objects

Put front objects in the left branch

+

-

9

-

8

+

7

6

1

4

6

7

8

9

2

3

5

5

4

1

2

3


Bsp trees objects3
BSP Trees: Objects

Put front objects in the left branch

+

-

9

8

7

6

-

+

+

-

5

4

1

4

6

7

8

9

2

3

5

1

2

3


Bsp trees objects4
BSP Trees: Objects

Put front objects in the left branch

+

-

9

8

7

6

-

+

+

-

5

4

1

-

-

-

+

+

+

1

2

3

3

2

4

5

6

7

9

8


Bsp trees objects5
BSP Trees: Objects

Put front objects in the left branch

+

-

9

8

7

6

-

+

+

-

5

4

1

-

-

-

+

+

+

1

2

3

3

5

6

8

6

-

-

2

+

+

2

4

7

9


Bsp trees objects6
BSP Trees: Objects

Put front objects in the left branch

+

-

9

8

7

6

-

+

+

-

5

4

1

-

-

-

+

+

+

1

2

3

3

5

6

8

6

-

-

2

+

+

2

4

7

9

When to stop the recursion?


Object splitting

Ouch

Object Splitting

  • No bunnies were harmed in my example

  • But what if a splitting plane passes through an object?

    - Split the object; give half to each node:

    - Worst case: can create up to O(n3) objects!


Building a bsp tree
Building a BSP Tree

  • Choose a splitting polygon

  • Sort all other polygons as

    • Front

    • Behind

    • Crossing

    • On

  • Add “front” polygons to front child, “behind” to back child

  • Split “crossing” polygons with infinite plane

  • Add “on” polygons to root

  • Recur


Building a bsp tree1
Building a BSP Tree

6

7

3

5

1

2

4


Building a bsp tree2
Building a BSP Tree

6

7

3

5

1

2

4

1

b

2,3,4,5,6,7


Building a bsp tree3
Building a BSP Tree

6

7-2

5-2

3

7-1

5-1

1

2

4

1

b

3

f

b

7-2,6, 5-2

2,4,5-1,7-1


Building a bsp tree4
Building a BSP Tree

6

7-2

5-2

3

7-1

5-1

1

2

4

1

b

3

f

b

7-1

7-2,6, 5-2

b

f

4, 5-1

2


Building a bsp tree5
Building a BSP Tree

6

7-2

5-2

3

7-1

5-1

1

2

4

1

b

3

f

b

7-1

7-2,6, 5-2

b

f

4

2

b

5-1


Building a bsp tree6
Building a BSP Tree

6

7-2

5-2

3

7-1

5-1

1

2

4

1

b

3

f

b

7-1

7-2,6, 5-2

b

f

4

2

b

5-1


Building a bsp tree7
Building a BSP Tree

6

7-2

5-2

3

7-1

5-1

1

2

4

1

b

3

f

b

7-1

7-2,6, 5-2

b

f

4

2

b

5-1


Building a bsp tree8
Building a BSP Tree

6

7-2

5-2

3

7-1

5-1

1

2

4

1

b

3

f

b

7-2

7-1

b

b

f

4

6, 5-2

2

b

5-1


Building a bsp tree9
Building a BSP Tree

6

7-2

5-2

3

7-1

5-1

1

2

4

1

b

3

f

b

7-2

7-1

b

b

f

4

6

2

b

b

5-2

5-1


Building a bsp tree10
Building a BSP Tree

6

7-2

5-2

3

7-1

5-1

1

2

4

1

b

3

f

b

7-2

7-1

b

b

f

4

6

2

b

b

5-1

5-2


Building a bsp tree11
Building a BSP Tree

6

7-2

5-2

3

7-1

5-1

1

2

4

1

b

3

f

b

7-2

7-1

b

b

f

4

6

2

b

b

5-1

5-2


Rendering with a bsp tree
Rendering with a BSP Tree

  • If eye is in front of plane

    • Draw “back” polygons

    • Draw “on” polygons

    • Draw “front” polygons

  • If eye is behind plane

    • Draw “front” polygons

    • Draw “on” polygons

    • Draw “back” polygons

  • Else eye is on plane

    • Draw “front” polygons

    • Draw “back” polygons


Bsp trees objects7
BSP Trees: Objects

Correctly traversing this tree enumerates objects from back to front

+

-

9

8

7

6

-

+

+

-

5

4

1

-

-

-

+

+

+

1

2

3

3

5

6

8

6

-

-

2

+

+

2

4

7

9

Traversal order?


Bsp trees objects8
BSP Trees: Objects

Correctly traversing this tree enumerates objects from back to front

+

-

9

8

7

6

-

+

+

-

5

4

1

-

-

-

+

+

+

1

2

3

3

5

6

8

6

-

-

2

+

+

2

4

7

9

Traversal order:

8->9->7->6->5->3->4->2->1


Building a bsp tree12
Building a BSP Tree

6

7-2

5-2

3

7-1

5-1

1

2

4

1

b

3

f

b

7-2

7-1

b

b

f

4

6

Traversal order:

2

b

b

5-1

5-2


Building a bsp tree13
Building a BSP Tree

6

7-2

5-2

3

7-1

5-1

1

2

4

1

b

3

f

b

7-2

7-1

b

b

f

4

6

Traversal order:

6->(5-2)->(7-2)->3->(5-1)->4->(7-1)->2->1

2

b

b

5-1

5-2


Building a bsp tree14
Building a BSP Tree

6

7-2

5-2

3

7-1

5-1

1

2

4

1

b

3

f

b

7-2

7-1

b

b

f

4

6

Traversal order:

2

b

b

5-1

5-2


Building a bsp tree15
Building a BSP Tree

6

7-2

5-2

3

7-1

5-1

1

2

4

1

b

3

f

b

7-2

7-1

b

b

f

4

6

Traversal order:

1->2->(7-1)->4->(5-1)->3->(7-2)->(5-2)->6

2

b

b

5-1

5-2


Building a bsp tree16
Building a BSP Tree

6

7-2

5-2

3

7-1

5-1

1

2

4

1

b

3

f

b

7-2

7-1

b

b

f

4

6

Traversal order?

2

b

b

5-1

5-2


Rendering with a bsp tree1
Rendering with a BSP Tree

  • Advantages

    • No depth comparisons needed

    • Polygons split and ordered automatically

  • Disadvantages

    • Computationally intense preprocess stage restricts algorithm to static scenes

    • Splitting increases polygon count

    • Redraws same pixel many times

    • Choosing splitting plane not an exact science


Improved bsp rendering
Improved BSP Rendering

Take advantage of view direction to cull away polygons behind viewer


Improved bsp rendering1
Improved BSP Rendering

View frustum

Take advantage of view direction to cull away polygons behind viewer


Improved bsp rendering2
Improved BSP Rendering

Take advantage of view direction to cull away polygons behind viewer


Opengl and hidden surfaces
OpenGL and Hidden Surfaces

glEnable(GL_DEPTH_TEST);

glEnable(GL_CULL_FACE);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glCullFace ( GL_BACK );


Scan line algorithm
Scan Line Algorithm

  • Assume for each line of screen, we have scan-lines for all polygons intersecting that line

  • For each polygon, keep track of extents of scan line

  • Whenever the x-extents of two scan lines overlap, determine ordering of two polygons





Scan line algorithm4
Scan Line Algorithm

  • Advantages

    • Takes advantage of coherence resulting in fast algorithm

    • Does not require as much storage as depth buffer

  • Disadvantages

    • More complex algorithm

    • Requires all polygons sent to GPU before drawing


ad