68
Hidden Surface Elimination Introduction Need is to eliminate ambiguity OR

Computer Graphics - Hidden Surface Elimination

Embed Size (px)

Citation preview

Page 1: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationIntroduction

Need is to eliminate ambiguity

OR

Page 2: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationIntroduction

Wire frame

Hidden Line Elimination Hidden Surface Elimination

Page 3: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationIntroduction

Approaches

• Image SpaceThrough pixel

• Object SpaceThrough primitive

Page 4: Computer Graphics - Hidden Surface Elimination

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

Page 5: Computer Graphics - Hidden Surface Elimination

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

Page 6: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationFloating Horizon Algorithm

Surface FunctionF(x,y,z)=0

x

z

z1= constantz2

z3x

y

zz1= constantz2

z3z4

z5

Page 7: Computer Graphics - Hidden Surface Elimination

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.

Page 8: Computer Graphics - Hidden Surface Elimination

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.

Page 9: Computer Graphics - Hidden Surface Elimination

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

Page 10: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationBack Face Culling

z

x

Conservative algorithm

Page 11: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationBack Face Culling

z

x

Conservative algorithm

Page 12: Computer Graphics - Hidden Surface Elimination

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)

Page 13: Computer Graphics - Hidden Surface Elimination

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 }

Page 14: Computer Graphics - Hidden Surface Elimination

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

Page 15: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationZ-Buffer Algorithm

Example

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

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

Z-buffer Screen

Page 16: Computer Graphics - Hidden Surface Elimination

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

Page 17: Computer Graphics - Hidden Surface Elimination

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

Page 18: Computer Graphics - Hidden Surface Elimination

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

Page 19: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationZ-Buffer Algorithm

• Simple method• Complexity

Time : nxm buffer k poygonsO(nmk)

Space : b depth precisionO(nmb)

Page 20: Computer Graphics - Hidden Surface Elimination
Page 21: Computer Graphics - Hidden Surface Elimination

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

Page 22: Computer Graphics - Hidden Surface Elimination

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

Page 23: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationPainter’s Algorithm

Z=20 Z=15 Z=10

Page 24: Computer Graphics - Hidden Surface Elimination

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

Page 25: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationPainter’s Algorithm

P

Q

Cyclic overlappingMay require splitting

Page 26: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationBinary Space Partitioning (BSP)

BSP Tree

Space partitioning using planes

Page 27: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationBinary Space Partitioning (BSP)

BSP Tree

For hidden surface elimination: sets a display order

PB

F

P

BF

Page 28: Computer Graphics - Hidden Surface Elimination

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

Page 29: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationBinary Space Partitioning

3

5

5b

5a

2

14

3

45b

front back

125a

Example

Page 30: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationBinary Space Partitioning

3

5

5b

5a

2

14

3

45b

front back

2

5a 1

Example

Page 31: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationBinary Space Partitioning

3

3

5

5b

5a

2

14

front back

2

5a 1

4

5b

Example

Page 32: Computer Graphics - Hidden Surface Elimination

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

Page 33: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationBinary Space Partitioning

3

5

2

14

5

front

back

1

2

3

4

Example

Page 34: Computer Graphics - Hidden Surface Elimination

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

Page 35: Computer Graphics - Hidden Surface Elimination

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

Page 36: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationArea Subdivision

Quad tree

Page 37: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationArea Subdivision AlgorithmWarnock’s Algorithm

Polygon

Area of interest

Surrounding Intersecting Contained Disjoint

Page 38: Computer Graphics - Hidden Surface Elimination

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

Page 39: Computer Graphics - Hidden Surface Elimination

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.

Page 40: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationWarnock’s Algorithm

Area

Page 41: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationWarnock’s Algorithm

Page 42: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationWarnock’s Algorithm

Page 43: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationWarnock’s Algorithm

Page 44: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationWarnock’s Algorithm

Maximum subdivision: pixel!

Page 45: Computer Graphics - Hidden Surface Elimination
Page 46: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationWeiler Atherton Algorithm

Subdivision along polygon boundaries

Clipping!

Page 47: Computer Graphics - Hidden Surface Elimination

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)

Page 48: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationWeiler Atherton Algorithm

A

BinA

BoutA

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

Display A

Process BoutA

Page 49: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationWeiler Atherton Algorithm

A

B

x

y

z

x

y

z

AB

Page 50: Computer Graphics - Hidden Surface Elimination

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

Page 51: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationWeiler Atherton AlgorithmMore polygons with more fragments

Page 52: Computer Graphics - Hidden Surface Elimination

Based on

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

– scan-conversion algorithm and a little more datastructure

Hidden Surface EliminationScan Line Algorithm

Page 53: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationScan Line Algorithm

Spans

Page 54: Computer Graphics - Hidden Surface Elimination

• 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

Page 55: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationScan Line Algorithm

Page 56: Computer Graphics - Hidden Surface Elimination

• 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

Page 57: Computer Graphics - Hidden Surface Elimination

• 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

Page 58: Computer Graphics - Hidden Surface Elimination

• 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

Page 59: Computer Graphics - Hidden Surface Elimination

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)

Page 60: Computer Graphics - Hidden Surface Elimination

In addition,

Use active In-Polygon List (IPL)

Active Edge Table (AET)

Hidden Surface EliminationScan Line Algorithm

Page 61: Computer Graphics - Hidden Surface Elimination

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

Page 62: Computer Graphics - Hidden Surface Elimination

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

Page 63: Computer Graphics - Hidden Surface Elimination

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

Page 64: Computer Graphics - Hidden Surface Elimination

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

Page 65: Computer Graphics - Hidden Surface Elimination

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

Page 66: Computer Graphics - Hidden Surface Elimination

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

Page 67: Computer Graphics - Hidden Surface Elimination

Hidden Surface EliminationScan Line Algorithm Nonpenetrating

Page 68: Computer Graphics - Hidden Surface Elimination

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