Computer Graphics - Hidden Surface Elimination

Post on 28-Mar-2015

441 views 0 download

transcript

Hidden Surface EliminationIntroduction

Need is to eliminate ambiguity

OR

Hidden Surface EliminationIntroduction

Wire frame

Hidden Line Elimination Hidden Surface Elimination

Hidden Surface EliminationIntroduction

Approaches

• Image SpaceThrough pixel

• Object SpaceThrough primitive

Hidden Surface EliminationImage Space Approach

for (each pixel in the image){

determine the object closest to the viewer that isintercepted by the projector through the pixel;

draw the pixel in the appropriate color;}

Computational effort: npn : number of objectsp : number of pixels

Hidden Surface EliminationObject Space Approach

for (each object in the world){

determine those parts of the object whose view isunobstructed by other parts of it or any other object;

draw those parts in the appropriate color;}

Computational effort: n2

n: number of objects

Hidden Surface EliminationFloating Horizon Algorithm

Surface FunctionF(x,y,z)=0

x

z

z1= constantz2

z3x

y

zz1= constantz2

z3z4

z5

Hidden Surface EliminationFloating Horizon Algorithm

With z=constant plane closest to the viewpoint, the curve ineach plane is generated (for each x coordinate in image spacethe appropriate y value is found).

x

y

z1z2

z3z4

z5

Projection on z=0 planeAlgorithm:If at any given value of x the y valueof the curve in the current plane islarger than the y value for anyprevious curve at that x value,then the curve is visible,otherwise it is hidden.

Hidden Surface EliminationFloating Horizon Algorithm

x

y

z1z2

z3z4

z5

Projection on z=0 plane

Algorithm:If at any given value of x the y valueof the curve in the current plane islarger than the y value or smallerthan the minimum y value for anyprevious curve at that x value,then the curve is visible,otherwise it is hidden.

Hidden Surface EliminationBack Face Culling

Preprocessing to eliminate faces which are not visible

P

np

If a surface’s normal is pointing away from theeye (viewer), then this is a back face

backface then Vn If p 0<⋅

V

Hidden Surface EliminationBack Face Culling

z

x

Conservative algorithm

Hidden Surface EliminationBack Face Culling

z

x

Conservative algorithm

Hidden Surface EliminationZ-Buffer Algorithm

Proposed by Catmull 1974Simple to implementZ-buffer is like a frame buffer, contains depth

Zb(x, y)C(x, y)

(x, y)

(x, y)

Hidden Surface EliminationZ-Buffer Algorithm

Initialize all d[i,j]=1.0 (max depth), c[i,j]=background color.for (each polygon) for (each pixel in polygon’s projection) { Find depth-z of polygon at (x,y) corresponding to pixel (i,j); If z < d[i,j] d[i,j] = z; p[i,j] = color; end }

Hidden Surface EliminationZ-Buffer Algorithm

1)x( CA

zxCA

zz

xCA

zz

CDByx)xA

z

xx At

CC

DByAxz

x AtDCzByAx

=−=−=

−=−

+++−=

+

≠++−=

=+++

ÄÄ

Ä

)Ä((Ä

0,)(

0

1

1

1

Q

Computationally

Hidden Surface EliminationZ-Buffer Algorithm

Example

∞ ∞ ∞ ∞∞ ∞ ∞ ∞∞ ∞ ∞ ∞∞ ∞ ∞ ∞∞ ∞ ∞ ∞∞ ∞ ∞ ∞∞ ∞ ∞ ∞∞ ∞ ∞ ∞

∞ ∞ ∞ ∞∞ ∞ ∞ ∞∞ ∞ ∞ ∞∞ ∞ ∞ ∞∞ ∞ ∞ ∞∞ ∞ ∞ ∞∞ ∞ ∞ ∞∞ ∞ ∞ ∞

Z-buffer Screen

Hidden Surface EliminationZ-Buffer Algorithm

Example

[0,1,5]

[0,7,5] [6,7,5]

5 5 5 55 5 5 55 5 5 55 5 5 55 5 5 ∞5 5 ∞ ∞5 ∞ ∞ ∞∞ ∞ ∞ ∞

5 5 5 ∞5 5 ∞ ∞5 ∞ ∞ ∞∞ ∞ ∞ ∞∞ ∞ ∞ ∞∞ ∞ ∞ ∞∞ ∞ ∞ ∞∞ ∞ ∞ ∞

Z-buffer

Hidden Surface EliminationZ-Buffer Algorithm

Example

[0,1,2]

[0,6,7]

[5,1,7]

76 75 6 74 5 6 73 4 5 62 3 4 5

76 7

Hidden Surface EliminationZ-Buffer Algorithm

Example

5 5 5 55 5 5 55 5 5 55 5 5 54 5 5 73 4 5 62 3 4 5∞ ∞ ∞ ∞

5 5 5 ∞5 5 ∞ ∞5 ∞ ∞ ∞∞ ∞ ∞ ∞∞ ∞ ∞ ∞7 ∞ ∞ ∞6 7 ∞ ∞∞ ∞ ∞ ∞

Z-buffer Screen

Hidden Surface EliminationZ-Buffer Algorithm

• Simple method• Complexity

Time : nxm buffer k poygonsO(nmk)

Space : b depth precisionO(nmb)

Hidden Surface EliminationPainter’s Algorithm

Depth Sort, List PriorityPolygons are painted to the screen in the order of theirdistance from the viewer (More distant objects are paintedfirst)

Screen display

Hidden Surface EliminationPainter’s Algorithm

• Sort polygons in order of increasing depth• Draw polygons in sequence, starting from the polygon(surface) of greatest depth

• Careful processing of depth

• Efficiency depends on sorting algorithm

Hidden Surface EliminationPainter’s Algorithm

Z=20 Z=15 Z=10

Hidden Surface EliminationPainter’s Algorithm

P

QR

z

P > Q > R

P

Qz

P > Q

Draw first P then Q and then R

Draw first P then Q

Hidden Surface EliminationPainter’s Algorithm

P

Q

Cyclic overlappingMay require splitting

Hidden Surface EliminationBinary Space Partitioning (BSP)

BSP Tree

Space partitioning using planes

Hidden Surface EliminationBinary Space Partitioning (BSP)

BSP Tree

For hidden surface elimination: sets a display order

PB

F

P

BF

Hidden Surface EliminationBinary Space Partitioning (BSP)

BSP Tree

For hidden surface elimination: sets a display order

PB

F

P

BF

Eye

Display order (back to front): BPF

Hidden Surface EliminationBinary Space Partitioning

3

5

5b

5a

2

14

3

45b

front back

125a

Example

Hidden Surface EliminationBinary Space Partitioning

3

5

5b

5a

2

14

3

45b

front back

2

5a 1

Example

Hidden Surface EliminationBinary Space Partitioning

3

3

5

5b

5a

2

14

front back

2

5a 1

4

5b

Example

Hidden Surface EliminationBinary Space Partitioning

3

3

5

5b

5a

2

14

front back

2

5a 1

4

5b

Example

Display order: 5a 2 1 3 5b 4V

Hidden Surface EliminationBinary Space Partitioning

3

5

2

14

5

front

back

1

2

3

4

Example

Hidden Surface EliminationBinary Space Partitioning

3

5

2

14

5

front

back

1

2

3

4

Example

V

Display order: 5 2 1 3 4

Hidden Surface EliminationBinary Space Partitioning

Issues

How to select the root polygon?

Criteria: Number of split (fragmentation)

a. Arbitrary

b. Heuristic based with 4-5 polygons and consider which gives the leastnumber of split

Static vs Dynamic scene

Hidden Surface EliminationArea Subdivision

Quad tree

Hidden Surface EliminationArea Subdivision AlgorithmWarnock’s Algorithm

Polygon

Area of interest

Surrounding Intersecting Contained Disjoint

Hidden Surface EliminationArea Subdivision Algorithm

Consider an area of the projected image

If it is easy to decide which polygons are visible inthe area, displayElse the area is subdivided into smallerareas and the decision is made recursively

Divide and Conquer

Hidden Surface EliminationArea Subdivision Algorithm

No Subdivision is required if1. All the polygons are disjoint: background color in the area.

2. Only one intersecting or only one contained polygon: The area isfilled first by background color, then the polygon part contained inthe area.

3. Only one surrounding polygon (no contained and intersectingpolygons): The area is filled with the color of the surroundingpolygon.

4. More than one polygon is intersecting, contained in, orsurrounding the area, with surrounding polygon in front: Fill the areawith the color of the surrounding polygon.

Hidden Surface EliminationWarnock’s Algorithm

Area

Hidden Surface EliminationWarnock’s Algorithm

Hidden Surface EliminationWarnock’s Algorithm

Hidden Surface EliminationWarnock’s Algorithm

Hidden Surface EliminationWarnock’s Algorithm

Maximum subdivision: pixel!

Hidden Surface EliminationWeiler Atherton Algorithm

Subdivision along polygon boundaries

Clipping!

Hidden Surface EliminationWeiler Atherton Algorithm

• Initial z-sort• Consider front most polygon, clip all polygons to generate

Fragments inside polygon and outside polygon• All inside polygons if behind delete from the list• If there is an inside polygon in front (offending), clip the inside list of polygons against this polygon• Process the outside polygon(s)

Hidden Surface EliminationWeiler Atherton Algorithm

A

BinA

BoutA

A as clip polygonInside list: A, BinAOutside list: BoutA

Display A

Process BoutA

Hidden Surface EliminationWeiler Atherton Algorithm

A

B

x

y

z

x

y

z

AB

Hidden Surface EliminationWeiler Atherton Algorithm

A as clip polygon

Inside list: A, BinAOutside list: BoutA

BinA

BoutA

BinA as clip polygon

Inside list: BinA, AinBOutside list: BoutA, AoutB

Display BinA

Hidden Surface EliminationWeiler Atherton AlgorithmMore polygons with more fragments

Based on

Scan-line coherence across multiple scan-lines orspan-coherence !

– scan-conversion algorithm and a little more datastructure

Hidden Surface EliminationScan Line Algorithm

Hidden Surface EliminationScan Line Algorithm

Spans

• Each scan line is subdivided into several "spans"• Determine which polygon the current span belongs to• Shade the span using the current polygon’s color• Exploit "span coherence" :• For each span, a visibility test may need to be done

Hidden Surface EliminationScan Line AlgorithmOverview

Hidden Surface EliminationScan Line Algorithm

• A scan line is subdivided into a sequence of spans• Each span can be "inside" or "outside" polygon areas

– "outside“: no pixels need to be drawn (backgroundcolor)

– "inside“: can be inside one or multiple polygons• If a span is inside one polygon, the pixels in the span will

be drawn with the color of that polygon• If a span is inside more than one polygon, then compare

the z values of those polygons at the scan line edgeintersection point to determine the color of the pixel

Hidden Surface EliminationScan Line Algorithm

Inside/Outside Spans

• When a scan line intersects an edge of a polygon– for the 1st time, the span becomes "inside" of the

polygon from that intersection point on– for a 2nd time, the span becomes "outside“ of the

polygon from that point on• A flag "in/out" for each polygon is used to keep track of the

current state• Initially, the in/out flag is set to be "outside" (value = 0 for

example). Invert the tag for “inside”.

Hidden Surface EliminationScan Line Algorithm

Inside/Outside Spans

• Each polygon will have its own in/out flag• There can be more than one polygon having the in/out

flags to be "in" at a given instance• Keep track of polygons the scan line is currently in• If there are more than one polygon "in", perform z value

comparison to determine the color of the scan line span

Hidden Surface EliminationScan Line Algorithm

x ymax ∆x poly-IDET

PT poly-ID A,B,C,D color in/out flag

Hidden Surface EliminationScan Line AlgorithmData StructureEdge Table (ET)Polygon Table (PT)

In addition,

Use active In-Polygon List (IPL)

Active Edge Table (AET)

Hidden Surface EliminationScan Line Algorithm

S T

a

b

c

1

2

3

X0

I

I I I

I I

I V

XN

BG

Example

Hidden Surface EliminationScan Line Algorithm

Y AET IPL

I x0, ba, bc, xN BG, BG+S, BG

II x0, ba, bc, 32, 13, xN BG, BG+S, BG, BG+T, BG

IIIIII xx00, , baba, 32, ca, 13,, 32, ca, 13, x xNN BG, BG+S, BG+S+T, BG+T, BGBG, BG+S, BG+S+T, BG+T, BG

IV x0, ba, ac, 12, 13, xN BG, BG+S, BG, BG+T, BG

Hidden Surface EliminationScan Line Algorithm Example

Hidden Surface EliminationScan Line Algorithm

S T

a

b

c

1

2

3

X0

I

I I I

I I

I V

XN

BG

Y AET IPL

I x0, ba, bc, xN BG, BG+S, BG

Example

Hidden Surface EliminationScan Line Algorithm

S T

a

b

c

1

2

3

X0

I

I I I

I I

I V

XN

BG

Y AET IPL

II x0, ba, bc, 32, 13, xN BG, BG+S, BG, BG+T, BG

Example

Hidden Surface EliminationScan Line Algorithm

S T

a

b

c

1

2

3

X0

I

I I I

I I

I V

XN

BG

Y AET IPL

IIIIII xx00,, ba ba, 32, ca, 13,, 32, ca, 13, x xNN BG, BG+S, BG+S+T, BG+T, BGBG, BG+S, BG+S+T, BG+T, BG

Example

Hidden Surface EliminationScan Line Algorithm

S T

a

b

c

1

2

3

X0

I

I I I

I I

I V

XN

BG

Y AET IPL

IV x0, ba, ac, 12, 13, xN BG, BG+S, BG, BG+T, BG

Example

Hidden Surface EliminationScan Line Algorithm Nonpenetrating

S

I

T

a

2

BG

b

c

3

d

e

1

Hidden Surface EliminationScan Line Algorithm

I x0, ba , 23, ec, ad, 13, xN BG, BG+S, BG+S+T,BG+S+T+, BG+T, BG

Penetrating