Hidden surfaces
This presentation is the property of its rightful owner.
Sponsored Links
1 / 72

Hidden Surfaces PowerPoint PPT Presentation


  • 172 Views
  • Uploaded on
  • Presentation posted in: General

Hidden Surfaces. Chapter 10. Hidden Lines. Hidden Lines Removed. Hidden Surfaces Removed. Why?. We must determine what is visible within a scene from a chosen viewing position For 3D worlds this is known as visible surface detection or hidden surface elimination. Hidden Surface Removal.

Download Presentation

Hidden Surfaces

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

Chapter 10


Hidden lines

Hidden Lines


Hidden lines removed

Hidden Lines Removed


Hidden surfaces removed

Hidden Surfaces Removed


Hidden surfaces

Why?

We must determine what is visible within a scene from a chosen viewing position

For 3D worlds this is known as visible surface detection or hidden surface elimination


Hidden surface removal

Hidden Surface Removal

  • Goal: Determine which surfaces are visible and which are not.

    • Z-Buffer is just one of many hidden surface removal algorithms.

  • Other names:

    • Visible-surface detection

    • Hidden-surface elimination

  • Display all visible surfaces, do not display any occluded surfaces.

  • We can categorize into

    • Object-space methods

    • Image-space methods


Topics need to be read

Topics need to be read

  • Back face Culling

  • Hidden Object Removal: Painters Algorithm

  • Z-buffer

  • Scanline

  • subdivision

  • Warnock

  • Atherton-Weiler

  • BSP Tree


Two main approaches

Two Main Approaches

Visible surface detection algorithms are broadly classified as:

  • Object Space Methods: Compares objects and parts of objects to each other within the scene definition to determine which surfaces are visible

  • Image Space Methods: Visibility is decided point-by-point at each pixel position on the projection plane

    Image space methods are by far the more common


Two main approaches1

Two Main Approaches

  • Object Space Method:

    For each object in the scene do

    Begin

    1. Determine those part of the object whose view is unobstructed by other parts of it or

    any other object with respect to the viewing specification.

    2. Draw those parts in the object color.

    End


Two main approaches2

Two Main Approaches

  • Image Space Method:

    For each pixel in the image do

    Begin

    1. Determine the object closest to the viewer that is pierced by the projector through the pixel

    2. Draw the pixel in the object colour.

    End


Visible surface detection

Visible Surface Detection

Object space methods ex: back-face, painters algorithm

Image space methods ex: z-buffer, scan-line, subdivision


Back face detection

Back-Face Detection

  • In a solid object, there are surfaces which are facing the viewer (front faces) and there are surfaces which are opposite to the viewer (back faces).

Each surface has a normal vector. If this vector is pointing in the direction of the center of projection, it is a front face and can be seen by the viewer. If it is pointing away from the center of projection, it is a back face and cannot be seen by the viewer.

The test is very simple, if the z component of the normal vector is positive, then, it is a back face. If the z component of the vector is negative, it is a front face.


Back face detection1

Back-Face Detection

(x,y,z) is behind the polygon if Ax+By+Cz<0

or

A polygon is a backface if

Vview . N >0

if Vview is parallel to zv axis:

if C<0 then backface

if C=0 then polygon cannot be seen

yv

xv

N=(A,B,C)

zv

Vview


Back face culling example

Back-Face Culling Example

n1·v = (2, 1, 2) · (-1, 0, -1)

= -2 – 2 = -4,

so n1·v < 0

so n1front facing polygon

n2 = (-3, 1, -2)

n1 = (2, 1, 2)

n2 ·v = (-3, 1, -2) · (-1, 0, -1)

= 3 + 2 = 5

so n2 · v > 0

so n2 back facing polygon

v = (-1, 0, -1)


Back face culling

Back-Face Culling

If the viewpoint is on the +z axis looking at the origin, we only need check the sign of the z component of the object’s normal vector

if nz < 0, it is back facing

if nz > 0 it is front facing

What if nz = 0?

the polygon is parallel to the view direction, so we don’t see it


Z buffering

Z-Buffering

Visible Surface Determination Algorithm:

Determine which object is visible at each pixel.

Order of polygons is not critical.

Works for dynamic scenes.

Basic idea:

Rasterize (scan-convert) each polygon, one at a time

Keep track of a z value at each pixel

Interpolate z value of vertices during rasterization.

Replace pixel with new color if z value is greater. (i.e., if object is closer to eye)


Example

Example

Goal is to figure out which polygon to draw based on which is in front of what. The algorithm relies on the fact that if a nearer object occupying (x,y) is found, then the depth buffer is overwritten with the rendering information from this nearer surface.


Z buffering1

Z-buffering

Need to maintain:

Frame buffer

contains colour values for each pixel

Z-buffer

contains the current value of z for each pixel

The two buffers have the same width and height.

No object/object intersections.

No sorting of objects required.

Additional memory is required for the z-buffer.

In the early days, this was a problem.


Hidden surfaces

Z-Buffering: Algorithm

  • Algorithm:

  • 1. Initially each pixel of the z-buffer is set to the maximum depth value (the depth of the back clipping plane).

  • 2. The image buffer is set to the background color.

  • 3. Surfaces are rendered one at a time.

  • 4. For the first surface, the depth value of each pixel is calculated.

  • 5. If this depth value is smaller than the corresponding depth value in the z-buffer (ie. it is closer to the view point), both the depth value in the z-buffer and the color value in the image buffer are replaced by the depth value and the color value of this surface calculated at the pixel position.

  • 6. Repeat step 4 and 5 for the remaining surfaces.

  • 7. After all the surfaces have been processed, each pixel of the image buffer represents the color of a visible surface at that pixel.


Z buffering algorithm

Z-Buffering: Algorithm

allocate z-buffer;

 The z-buffer algorithm:

compare pixel depth(x,y) against buffer record d[x][y]

for (every pixel){ initialize the colour to the background};

for (each facet F){

for (each pixel (x,y) on the facet)

if (depth(x,y) < buffer[x][y]){ / / F is closest so far

set pixel(x,y) to colour of F;

d[x][y] = depth(x,y)

}

}


Z buffering example

Z-Buffering: Example

-1

-2

-3

-1

-3

-4

-5

-3

-2

-4

-5

-6

-7

-5

-4

-3

-7

-6

-5

-4

Scan convert the following two polygons.

The number inside the pixel represents its z-value.

(3,3)

(0,3)

(0,0)

(3,0)

(0,0)

(3,0)

Does order matter?


Z buffering example1

Z-Buffering: Example

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-

-1

-1

-1

-1

-1

-1

-1

-2

-2

-2

-3

-3

-3

-1

-1

-1

-3

-3

-2

-2

-2

-2

-3

-3

-3

-3

-3

-4

-4

-4

-5

-5

-5

-3

-3

-3

-2

-2

-2

-5

-5

-4

-4

-3

-3

-3

-3

-4

-4

-4

-4

-4

-5

-5

-5

-6

-6

-6

-7

-7

-7

-5

-5

-5

-4

-4

-4

-3

-3

-3

-7

-7

-6

-6

-5

-5

-4

-4

-4

-4

-5

-5

-7

-7

-7

-6

-6

-6

-5

-5

-5

-4

-4

-4

=

+

+

=

+

=

+

=


Hidden surfaces

Z-Buffering: Example


Z buffering computing z

Z-Buffering: Computing Z

How do you compute the z value at a given pixel?

Interpolate between vertices

z1

y1

za

zb

ys

zs

y2

z2

y3

z3


Z buffer advantages

Z-Buffer Advantages

  • Simple to implement in hardware.

    • Memory for z-buffer is now not expensive

  • Diversity of primitives – not just polygons.

  • Unlimited scene complexity

  • Don’t need to calculate object-object intersections.

  • – Buffer may be saved with image for re-processing

  • Amenable to scan-line algorithms

  • Can easily resolve visibility cycles


Z buffer disadvantages

Z-Buffer Disadvantages

  • Extra memory and bandwidth

  • Waste time drawing hidden objects

  • Z-precision errors

  • May have to use point sampling

  • Requires a lot of memory

  • – Finite depth precision can cause problems

  • – Spends time while rendering polygons that are not visible

  • – Requires re-calculations when changing the scale

  • Does not do transparency easily

  • Aliasing occurs! Since not all depth questions can be resolved

  • Anti-aliasing solutions non-trivial

  • Shadows are not easy

  • Higher order illumination is hard in general


Scan line method

Scan-Line Method

An image space method for identifying visible surfaces Computes and compares depth values along the various scan-lines for a scene.


Scan line method cont

Scan-Line Method (cont…)

Two important tables are maintained:

  • The edge table

  • The surface facet table

    The edge table contains:

  • Coordinate end points of reach line in the scene

  • The inverse slope of each line

  • Pointers into the surface facet table to connect edges to surfaces

    The surface facet tables contains:

  • The plane coefficients

  • Surface material properties

  • Other surface data

  • Maybe pointers into the edge table


Scan line method cont1

Scan-Line Method (cont…)

  • To facilitate the search for surfaces crossing a given scan-line an active list of edges is formed for each scan-line as it is processed.

  • The active list stores only those edges that cross the scan-line in order of increasing x.

  • Also a flag is set for each surface to indicate whether a position along a scan-line is either inside or outside the surface.


Scan line method cont2

Scan-Line Method (cont…)

  • Pixel positions across each scan-line are processed from left to right

  • At the left intersection with a surface the surface flag is turned on

  • At the right intersection point the flag is turned off

  • We only need to perform depth calculations when more than one surface has its flag turned on at a certain scan-line position


Scan line method example

Scan Line Method Example


Scan line method limitations

Scan-Line Method Limitations

The scan-line method runs into trouble when surfaces cut through each other or otherwise cyclically overlap

Such surfaces need to be divided


Scan line method1

Scan-Line Method

For each scan-line, examine all polygon surface projections intersecting that scan line to determine which are visible. Then enter the surface color of that position in the frame buffer.

Edge table:

  • coordinate endpoints of each line

  • inverse slope of each line

  • pointers to surface table

    Surface table:

  • plane coefficients (A,B,C)

  • surface material properties

  • pointers to edge table

yv

xv

Image space method


Scan line method2

Scan-Line Method

Algorithm:

1. Form an active edge list that contains only the edges that cross the current scan line, sorted in order of increasing x.

2. Define a flag for each surface to indicate whether a position along a scan line is inside or outside the surface.

3. Process pixel positions across each scan line from left to right. Locate visible positions of surfaces along the scan line.

yv

1

2

3

xv


Warnock s algorithm

An area-subdivision technique

Idea:

Divide an area into four equal sub-areas

At each stage, the projection of each polygon will do one of four things:

Completely surround a particular area

Intersect the area

Be completely contained in the area

Be disjoint to the area

Warnock’s Algorithm


Warnock s algorithm1

Warnock’s Algorithm

Disjoint polygons do not influence an area.

Parts of an intersecting polygon that lie outside the area do not influence that area

At each step, we determine the areas we can color and color them, then subdivide the areas that are ambiguous.


Warnock s algorithm2

Warnock’s Algorithm

At each stage of the algorithm, examine the areas:

If no polygons lie within an area, the area is filled with the background color

If only one polygon is in part of the area, the area is first filled with the background color and then the polygon is scan converted within the area.

If one polygon surrounds the area and it is in front of any other polygons, the entire area is filled with the color of the surrounding polygon.

Otherwise, subdivide the area and repeat the above 4 tests.


Warnock s algorithm3

Warnock’s Algorithm

Initial scene


Warnock s algorithm4

Warnock’s Algorithm

First subdivision


Warnock s algorithm5

Warnock’s Algorithm

Second subdivision


Warnock s algorithm6

Warnock’s Algorithm

Third subdivision


Warnock s algorithm7

Warnock’s Algorithm

Fourth subdivision


Warnock s algorithm8

Warnock’s Algorithm

Subdivision continues until:

All areas meet one of the four criteria

An area is pixel size

in this case, the polygon with the closest point at that pixel determines the pixel color


Warnock s algorithm9

Warnock’s Algorithm

2

3

2

2

  • Regions labeled with case used to classify them:

    • One polygon in front

    • Empty

    • One polygon inside, surrounding or intersecting

  • Small regions not labeled

  • Note it’s a rendering algorithm and a HSR algorithm at the same time

    • Assuming you can draw squares

3

3

3

2

3

3

3

1

3

1

3

1

1

1

3

3

3

3

2

3

3

3

2

2

2

2


Hidden surfaces

Weiler -Atherton Algorithm

  • Object space

  • Like Warnock

  • Output – polygons of arbitrary accuracy


Weiler atherton algorithm

Weiler -Atherton Algorithm

  • Subdivide along polygon boundaries (unlike Warnock’s rectangular boundaries in image space);

  • Algorithm:

    • Sort the polygons based on their minimum z distance

    • Choose the first polygon P in the sorted list

    • Clip all polygons left against P, create two lists:

      • Inside list: polygon fragments inside P (including P)

      • Outside list: polygon fragments outside P

    • All polygon fragments on the inside list that are behind P are discarded. If there are polygons on the inside list that are in front of P, go back to step 3), use the ’offending’ polygons as P

    • Display P and go back to step (2)


Hidden surfaces

Weiler -Atherton Algorithm

WA_display(polys : ListOfPolygons)

sort_by_minZ(polys);while (polys <> NULL) doWA_subdiv(polys->first, polys)end;

WA_subdiv(first: Polygon; polys: ListOfPolygons)

inP, outP : ListOfPolygons := NULL;

for each P in polys do Clip(P, first->ancestor, inP, outP);

for each P in inP do if P is behind (min z)first then discard P;

for each P in inP doif P is not part of first then WA_subdiv(P, inP);

for each P in inP do display_a_poly(P);

polys := outP;

end;


Painter s algorithm

Painter’s Algorithm

Object-space 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


Bsp trees object precision

BSP-Trees (Object Precision)

  • Construct a binary space partition tree

    • Tree gives a rendering order

    • A list-priority algorithm

  • Tree splits 3D world with planes

    • The world is broken into convex cells

    • Each cell is the intersection of all the half-spaces of splitting planes on tree path to the cell

  • Also used to model the shape of objects, and in other visibility algorithms

    • BSP visibility in games does not necessarily refer to this algorithm


Bsp tree example

BSP-Tree Example

A

A

C

4

-

3

+

C

B

-

B

+

-

+

1

3

2

4

1

2


Building bsp trees

Building BSP-Trees

  • Choose polygon (arbitrary)

  • Split its cell using plane on which polygon lies

    • May have to chop polygons in two (Clipping!)

  • Continue until each cell contains only one polygon fragment

  • Splitting planes could be chosen in other ways, but there is no efficient optimal algorithm for building BSP trees

    • Optimal means minimum number of polygon fragments in a balanced tree


Building example

Building Example

We will build a BSP tree, in 2D, for a 3 room building

Ignoring doors

Splitting edge order is shown

“Back” side of edge is side with the number

5

2

3

4

1

6


Building example 1

Building Example (1)

5

1

+

-

3a, 4a, 6

2, 3b, 4b, 5

3b

2

4b

1

4a

3a

6


Building example 2

Building Example (2)

5b

5a

1

+

-

3a, 4a, 6

2

-

+

3b

2

4b

4b, 5a

3b, 5b

1

4a

3a

6


Building example 3

Building Example (3)

5b

5a

1

+

-

2

3a

-

+

+

3b

2

4b

4a, 6

4b, 5a

3b

+

5b

1

4a

3a

6


Building example done

Building Example (Done)

5b

5a

1

+

-

2

3a

-

+

+

3b

2

4b

4a

4b

3b

+

+

+

6

5a

5b

1

4a

3a

6


Bsp tree rendering

BSP-Tree Rendering

  • Observation: Things on the opposite side of a splitting plane from the viewpoint cannot obscure things on the same side as the viewpoint

  • Rendering algorithm is recursive descent of the BSP Tree

  • At each node (for back to front rendering):

    • Recurse down the side of the sub-tree that does not contain the viewpoint

      • Test viewpoint against the split plane to decide which tree

    • Draw the polygon in the splitting plane

      • Paint over whatever has already been drawn

    • Recurse down the side of the tree containing the viewpoint


Bsp tree rendering example

BSP-Tree Rendering Example

A

A

C

4

-

+

3

C

B

-

+

-

+

B

1

3

2

4

1

2

3rd

4th

1st

2nd

View


Bsp tree rendering 2

BSP-Tree Rendering (2)

  • Advantages:

    • One tree works for any viewing point

    • Filter anti-aliasing and transparency work

      • Have back to front ordering for compositing

    • Can also render front to back, and avoid drawing back polygons that cannot contribute to the view

      • User two trees – an extra one that subdivides the window

  • Disadvantages:

    • Can be many small pieces of polygon

    • Over-rendering


Bsp binary space partitioning tree

BSP (Binary Space Partitioning) Tree.

  • One of class of “list-priority” algorithms – returns ordered list of polygon fragments for specified view point (static pre-processing stage).

  • Choose polygon arbitrarily

  • Divide scene into front (relative to normal) and back half-spaces.

  • Split any polygon lying on both sides.

  • Choose a polygon from each side – split scene again.

  • Recursively divide each side until each node contains only 1 polygon.

5

2

3

1

4

View of scene from above


Bsp tree

BSP Tree.

5

5a

5b

2

3

1

4

3

back

front

1

2

5a

4

5b

  • Choose polygon arbitrarily

  • Divide scene into front (relative to normal) and back half-spaces.

  • Split any polygon lying on both sides.

  • Choose a polygon from each side – split scene again.

  • Recursively divide each side until each node contains only 1 polygon.


Bsp tree1

BSP Tree.

5

  • Choose polygon arbitrarily

  • Divide scene into front (relative to normal) and back half-spaces.

  • Split any polygon lying on both sides.

  • Choose a polygon from each side – split scene again.

  • Recursively divide each side until each node contains only 1 polygon.

5a

5b

2

3

1

4

3

back

front

2

4

5b

front

5a

1


Bsp tree2

BSP Tree.

5

5a

5b

2

3

1

4

3

back

front

2

4

front

5a

1

5b

  • Choose polygon arbitrarily

  • Divide scene into front (relative to normal) and back half-spaces.

  • Split any polygon lying on both sides.

  • Choose a polygon from each side – split scene again.

  • Recursively divide each side until each node contains only 1 polygon.


Displaying a bsp tree

Displaying a BSP tree.

  • Once we have the regions – need priority list

  • BSP tree can be traversed to yield a correct priority list for an arbitrary viewpoint.

  • Start at root polygon.

    • If viewer is in front half-space, draw polygons behind root first, then the root polygon, then polygons in front.

    • If polygon is on edge – either can be used.

    • Recursively descend the tree.

  • If eye is in rear half-space for a polygon – then can back face cull.


Bsp tree3

BSP Tree.

  • A lot of computation required at start.

    • Try to split polygons along good dividing plane

    • Intersecting polygon splitting may be costly

  • Cheap to check visibility once tree is set up.

  • Can be used to generate correct visibility for arbitrary views.

  • Efficient when objects don’t change very often in the scene.


Bsp performance measure

BSP performance measure

  • Tree construction and traversal (object-space ordering algorithm – good for relatively few static primitives, precise)

  • Overdraw: maximum

  • Front-to-back traversal is more efficient

    • Record which region has been filled in already

    • Terminate when all regions of the screen is filled in

  • S. Chen and D. Gordon. “Front-to-Back Display of BSP Trees.” IEEE Computer Graphics & Algorithms, pp 79–85. September 1991.


Coherence

Coherence

• Most methods for visible surface determination take advantage of coherence

  • features in the surface:

  • – Object coherence

  • – Face coherence

  • – Edge coherence

  • – Scan-line coherence

  • – Depth coherence

  • – Frame coherence


  • Login