cs475m - computer graphicsparagc/teaching/2016/... · cs475m: lecture 8 parag chaudhuri visibility...

43
CS475m - Computer Graphics Lecture 8 : Visibility

Upload: others

Post on 24-Jun-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m - Computer Graphics

Lecture 8 : Visibility

Page 2: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility● What is visible? 

— Which objects are visible?

— Which pixels(fragments) to render?

● Why check for visibilty?

— Efficiency

— Correctness? 

— DisambiguationThe Double Eagle Tanker:4GB of data, 82 M TrianglesFrom: http://www.cs.unc.edu/~geom/hardware/#Vis

Page 3: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Simple question

● The art gallery problem:

Given a planar art gallery, what is the minimum number of guards that need to be placed at the corners (but inside the gallery) so that every part of the gallery is visible to at least one guard.

Page 4: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Simple question

● NP – Complete!

● Upper bound: floor(N/3) for a simple polygon with N vertices.

● Determining visibility is not always easy.

Page 5: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

● The Image Space problem formulation

for (each pixel in the rendered image)

{

— determine the object closest to the viewer that is

intercepted by the projector (ray) through the pixel;

— draw the pixel in the appropriate color;

}

● Worst case complexity: np

n : number of objects, p : number of pixels

Page 6: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

● The Object Space problem formulation

for (every object in the world)

{

— determine those parts of the object whose view is

unobstructed by other parts of itself or any other object;

— draw those parts in the appropriate color;

}

● Worst case complexity: n2

n : number of objects

Page 7: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility● Types of visibilty computation we have seen:

— Clipping – 2D and 3D

— View­frustum clipping/culling

— Backface culling

http://geometricalgebra.org

Page 8: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

e p

n

p−e .n0

p−e .n≤0

● Backface Culling

Cull

Do Not Cull (may be visible)

Simple Idea:

Discard surface patches that face away from the camera.

Page 9: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

If                       are the patch vertices in CCW order seen from outside then the outward facing normal is given by:

Visibility

e p

n

p1, p2, p3, p4

n= p2− p1× p3− p1

● Backface Culling

Compute the outward normals and do Backface culling in the WCS.

p1

p2p3

p4

Page 10: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

● Backface Culling is not enough

Backface Culling does not remove all occluded patches (it is a conservative algorithm as are many visibility algorithms) – the example shown here is a case of self occlusion.

Page 11: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

● Floating Horizon Algorithm

z1

z2

z3

Given a surface defined byWe can sample it at many 2D cutting planes, yielding a set of curves of the form  y= f x , z i

Slicing Planes

z 4

z1

z2

z3z 4

f x , y , z=0

Page 12: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

● For each slicing plane i, with z=zi

— Compute yi for any xi on the curve.

— The point (xi,yi) is visible if yi > yj  for all j < i and xi = xj

Visibility

● Floating Horizon Algorithm

z1

z2

z3z4

Projection on z=0 plane.

Page 13: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

● Z­Buffer and Scan Conversion

● Initialize the z­buffer

to the max Z value.

● glClear, glDepthRange

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

Page 14: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

● Z­Buffer and Scan Conversion

1 1 1 1 1 1 1 1

1 0.5 0.5 1 1 1 1 1

1 0.5 0.5 0.5 0.5 0.5 1 1

1 0.5 0.5 0.5 0.5 1 1 1

1 0.5 0.5 0.5 1 1 1 1

1 0.5 0.5 1 1 1 1 1

1 0.5 0.5 1 1 1 1 1

1 0.5 1 1 1 1 1 1(0,0.1,0.5)

(0.6,0.7,0.5)(0.0,0.7,0.5)

Page 15: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

● Z­Buffer and Scan Conversion

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 0.5 0.5 1 1 1 1 1

1 0.5 0.5 1 1 1 1 1

1 0.5 0.5 0.5 1 1 1 1

1 0.4 0.5 0.6 0.7 1 1 1

1 0.3 0.4 0.5 0.6 0.7 1 1

1 0.2 0.3 0.4 0.5 0.6 0.7 1(0.1,0.1,0.2) (0.5,0.1,0.7)

(0.0,0.6,0.5)

Page 16: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

● Z­Buffer and Scan Conversion

1 1 1 1 1 1 1 1

1 0.5 0.5 1 1 1 1 1

1 0.5 0.5 0.5 0.5 0.5 1 1

1 0.5 0.5 0.5 0.5 1 1 1

1 0.5 0.5 0.5 1 1 1 1

1 0.4 0.5 0.6 0.7 1 1 1

1 0.3 0.4 0.5 0.6 0.7 1 1

1 0.2 0.3 0.4 0.5 0.6 0.7 1

Note that almost everywhere the result is independent of the order of drawing these polygons.Except at the pixels where the depth may be the same (this is very unlikely).

Page 17: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

● Z­Buffer Algorithm

Initialize 

zbuf[i, j]=MAX_DEPTH 

cbuf[i, j]=BACKGROUND_COLOR

for (each scan converted polygon)

{

Find pseudodepth, z, of polygon at pixel (x, y) with color c

If (z < zbuf[i, j]) { zbuf[i, j] = z; cbuf[i, j] = c;}

}

Page 18: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

● Z­Buffer Algorithm

● Advantages

— Simple, Accurate (modulo non­linear z­mapping).

— Independent of order of drawing polygons.

● Disadvantages

— Memory (not an issue these days).

— Wasted computation when over­writing distant points

● Complexity

— Time: O(nm . k) – nxm pixels, k polygons

— Space: O(nm . b) – nxm pixels, b bytes precision per pixel

Page 19: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

● Z­Buffer Algorithm and Scan Conversion

y1

y2

y3

y4

y5

y6

x2x7

x2

x2

x2

x2

x2

x3

x 4

x5

x6

x2 x3 x 4 x5 x6x7 x8

y1

y2

y3

y4

y5

y6

y7

y8

x1

for each edge [( xi , y i , d i ) and ( x j , y j , d j )] with  yi y j

{

   x=x i , d=d i , x=x j−x i

y j− y i and  d=

d j−d i

y j−y i

  for ( y= y i , y y j ; y)  {    insert ( x ,d ) into the AEL of scanline  y    such that it is sorted on the  x  values     x=x x ,d=d d  }}

● Construct the active edge list AEL for every scanline.

● Interpolate the pseudodepth for each active edge.

d 6

d 5

d 4

d 3

d 2

d 1d 1 '

d 5 '

d 4 '

d 3 '

d 2 '

Page 20: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

● Z­Buffer Algorithm and Scan Conversion

x2 x3 x 4 x5 x6x7 x8

y1

y2

y3

y4

y5

y6

y7

y8

y1

y2

y3

y4

y5

y6

x1

x2x7

x2

x2

x2

x2

x2

x3

x 4

x5

x6

● Compute the active edge list.

● Interpolate the pseudodepth for each active edge.

● Now, for rendering a ∆ABC:

d 6

d 5

d 4

d 3

d 2

d 1

d 5 '

d 4 '

d 3 '

d 2 '

d 1 'ymin=min y A , y B , yC ymax=max y A , y B , yC

for ( y=ymin ; y≤ymax ; y++ ){  get ( x p , d p) and  (xq , d q) from the AEL with x p< xq

  Δ d=(d q−d p)

(x q−x p );

  for ( x=x p ,d=d p ; x≤xq ; x ++ , d=d+Δd )  {    if ( d<zbuf [ x , y ] ) { zbuf [ x , y ]=d , cbuf [ x , y ]=c }  }}

zbuf [ i , j ]=MAX_DEPTH ,∀0≤iN ,0≤ jM

cbuf [ i , j ]=BACKGROUND_COLOR

● Note: The color c at a pixel is also interpolated along the scanline like the pseudodepth is

Page 21: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

● Z­Buffer Algorithm and Scan Conversion

y1

y2

y3

y4

y5

y6

x2x7

x2

x2

x2

x2

x2

x3

x 4

x5

x6

● Compute the active edge list.

● Interpolate the pseudodepth for each active edge.

d 6

d 5

d 4

d 3

d 2

d 1

d 5

d 4

d 3

d 2

d 1

x2 x3 x 4 x5 x6x7 x8

y1

y2

y3

y4

y5

y6

y7

y8

x1

Page 22: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

● Painter's Algorithm

● Sort polygon's in increasing order of depth.

● Draw the sorted list of polygons from back to front, i.e., from greatest depth to lesser depths.

● What happens when a polygon has vertices at different depths?

Page 23: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

● Painter's Algorithm

Visibility

● Sort polygon's in increasing order of depth.

● Draw the sorted list of polygons from back to front, i.e., from greatest depth to lesser depths.

● What happens when a polygon has vertices at different depths?

● Sort according to depth of farthest vertex.

Page 24: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

● Painter's Algorithm

Visibility

● Sort polygon's in increasing order of depth.

● Draw the sorted list of polygons from back to front, i.e., from greatest depth to lesser depths.

● What happens when a polygon has vertices at different depths?

● Sort according to depth of farthest vertex.

● Does it always work?

● How often do we sort?

?

Page 25: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

● Painter's Algorithm

Visibility

?

Page 26: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

● Painter's Algorithm

Visibility

Page 27: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

● Binary Space Partitioning (BSP) Trees

11 1 2

222 1

e

e

e

e

● Observe the correct order of drawing polygons as the eye moves

Page 28: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

● Binary Space Partitioning (BSP) Trees

T1 T1T1

T1

T2

T2T2 T2e

e

e

e

● If e and T2 are on the same side of T1

— Draw T1 and then draw T2

● If e and T2 are on different sides of T1

— Draw T2 and then draw T1

Inside(Back)

Outside(Front)

Page 29: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

● Binary Space Partitioning (BSP) Trees

T1 T1T1

T1

T2

T2T2 T2e

e

e

e

● If the implicit equation of the plane containing T1 

is given by:

● If                             then draw T1 and then draw T2

● If                             then draw T2 and then draw T1

pe

q

f r =r− p . n

f q . f e0

f q . f e0

Page 30: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

● BSP Tree is an efficient data structure for quickly determining the inside/outside relation between  polygons and the camera position.

12

34

56

7

89

10

11

● Two Phases

— Preprocessing: BSP Tree construction

(done once for a given scene)

— Rendering: BSP Tree traversal

(done whenever the eye position changes) 

Page 31: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

● BSP Tree construction

12

34

56

7

89

10

11

1

5, 6, 7, 8, 9, 10, 11

2, 3, 4

IN OUT

Page 32: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

● BSP Tree construction

12

34

56

7

89

10

11

1

6, 7,  10, 113, 4

IN OUT

2 5

8

IN OUTIN

Page 33: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

● BSP Tree construction

12

34

56

7

89b

10

11

1

6, 7, 9a 10, 113, 4

2 5

8, 9b

9a

IN OUT

IN OUTIN

Page 34: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

● BSP Tree construction

12

34

56

7

89b

10

11

1

7, 9a 10, 11

2 5

9a

3

4

6 8

9b

Page 35: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

● BSP Tree construction

12

34

56

7

89b

10

11

1

2 5

9a

3

4

8

7

9a

10

11

6

9b

Page 36: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

11

Visibility

● BSP Tree traversal

12

34

56

7

89b

10

1

2 5

9a

3 86

9b

2, 3, 4, 1, 8, 9b, 5, 6, 7, 9a, 10, 11

● If e is outside (or in front of) a face i

— Draw everything behind i,Draw i, Draw everything in front of i

● If e is inside a (or behind) face i

— Draw everything in front of i,Draw i, Draw everything behind i

4

7

9a

10

11

e

Page 37: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

● BSP Tree traversal

1

2 5

3 86

9b

● If e is outside (or in front of) a face i

— Draw everything behind i,Draw i, Draw everything in front of i

● If e is inside a (or behind) face i

— Draw everything in front of i,Draw i, Draw everything behind i

What is the traversal order now? 

11

12

34

56

7

89b

10

9a

3

4

7

9a

10

11e

Page 38: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

Surrounding Intersecting Contained Disjoint

Area ofInterest

Polygon● Warnock's Algorithm

Algorithm:

Consider the projected image area If it is easy to decide which polygons are visible in the area then displayelse subdivide the area and recurse with each subdivided area

Page 39: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

Surrounding Intersecting Contained Disjoint

Area ofInterest

Polygon● Warnock's Algorithm

No subdivision for an area is required if

● All the polygons are disjoint with it : fill background color in the area.

● Only one intersecting or only one contained polygon: The area is filled first by background color, then the polygon part contained in the area.

● Only one surrounding polygon (no contained and intersecting polygons): The area is filled with the color of the surrounding polygon.

● More than one polygon is intersecting, contained in, or surrounding the area, with surrounding polygon in front: Fill the area with the color of the surrounding polygon.

Page 40: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

Surrounding Intersecting Contained Disjoint

Area ofInterest

Polygon● Warnock's Algorithm

The starting area is the whole image.

Page 41: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

Surrounding Intersecting Contained Disjoint

Area ofInterest

Polygon● Warnock's Algorithm

Test in the area and subdivide.

Page 42: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

Surrounding Intersecting Contained Disjoint

Area ofInterest

Polygon● Warnock's Algorithm

Test in the area and subdivide.

Page 43: CS475m - Computer Graphicsparagc/teaching/2016/... · CS475m: Lecture 8 Parag Chaudhuri Visibility The Image Space problem formulation for (each pixel in the rendered image) — determine

CS475m: Lecture 8 Parag Chaudhuri

Visibility

Surrounding Intersecting Contained Disjoint

Area ofInterest

Polygon● Warnock's Algorithm

In the worst case you can end up subdividingupto pixel level.