visibility - indian institute of technology...

11
  CS 475 / CS 675 Computer Graphics Lecture 8 : Visibility CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015 Visibility What is visible? Which objects are visible? Which pixels(fragments) to render? Why check for visibilty? Efficiency Correctness? Disambiguation The Double Eagle Tanker: 4GB of data, 82 M Triangles From: http://www.cs.unc.edu/~geom/hardware/#Vis CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015 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. CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015 Simple question NP – Complete! Upper bound: floor(N/3) for a simple polygon with N vertices. Determining visibility is not always easy.

Upload: others

Post on 24-Jun-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Visibility - Indian Institute of Technology Bombayparagc/teaching/2015/cs475/lectures/08_visibility_h.pdfVisibility Backface Culling is not enough Backface Culling does not remove

   

 

CS 475 / CS 675Computer Graphics

Lecture 8 : Visibility

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

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

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

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.

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

Simple question

● NP – Complete!

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

● Determining visibility is not always easy.

Page 2: Visibility - Indian Institute of Technology Bombayparagc/teaching/2015/cs475/lectures/08_visibility_h.pdfVisibility Backface Culling is not enough Backface Culling does not remove

   

 

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

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

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

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

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

Visibility

● Types of visibilty computation we have seen:– Clipping – 2D and 3D

– View-frustum clipping/culling

– Backface culling

http://geometricalgebra.org

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

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 3: Visibility - Indian Institute of Technology Bombayparagc/teaching/2015/cs475/lectures/08_visibility_h.pdfVisibility Backface Culling is not enough Backface Culling does not remove

   

 

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

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

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

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.

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

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

z3z4

f x , y , z =0

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

● For each slicing plane i, with z=zi

– Compute yi for any xi on the curve.

– The point (xi,y

i) is visible if y

i > y

j

for all j < i and xi = x

j

Visibility

● Floating Horizon Algorithm

z1

z 2

z3z4

Projection on z=0 plane.

Page 4: Visibility - Indian Institute of Technology Bombayparagc/teaching/2015/cs475/lectures/08_visibility_h.pdfVisibility Backface Culling is not enough Backface Culling does not remove

   

 

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

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

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

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)

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

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)

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

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 5: Visibility - Indian Institute of Technology Bombayparagc/teaching/2015/cs475/lectures/08_visibility_h.pdfVisibility Backface Culling is not enough Backface Culling does not remove

   

 

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

Visibility

● Z-Buffer AlgorithmInitialize

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;}

}

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

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

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

Visibility

● Z-Buffer Algorithm and Scan Conversion

y1

y 2

y 3

y4

y 5

y 6

x 2x7

x 2

x 2

x 2

x 2

x 2

x3

x 4

x5

x6

x 2 x3 x4 x5 x 6 x7 x8

y1

y2

y3

y4

y 5

y 6

y 7

y 8

x1

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

{

   x=xi , d=di , x=x j−xi

y j− yi and  d=

d j−di

y j−yi

  for ( y= yi , 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 '

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

Visibility

● Z-Buffer Algorithm and Scan Conversion

x2 x3 x 4 x5 x6 x 7 x8

y1

y2

y3

y4

y5

y 6

y 7

y 8

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 yA ,y B ,yC ymax=max yA , yB , yC

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

  Δ d=(d q−d p)

(x q−x p );

  for ( x=x p ,d =d p ; x≤x q ; 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 6: Visibility - Indian Institute of Technology Bombayparagc/teaching/2015/cs475/lectures/08_visibility_h.pdfVisibility Backface Culling is not enough Backface Culling does not remove

   

 

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

Visibility

● Z-Buffer Algorithm and Scan Conversion

y1

y 2

y 3

y4

y 5

y 6

x 2x7

x 2

x 2

x 2

x 2

x 2

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

x 2 x3 x4 x5 x 6 x7 x8

y1

y2

y3

y4

y 5

y 6

y 7

y 8

x1

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

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?

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

● 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.

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

● 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 7: Visibility - Indian Institute of Technology Bombayparagc/teaching/2015/cs475/lectures/08_visibility_h.pdfVisibility Backface Culling is not enough Backface Culling does not remove

   

 

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

● Painter's Algorithm

Visibility

?

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

● Painter's Algorithm

Visibility

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

Visibility

● Binary Space Partitioning (BSP) Trees

1 1 1 2

222 1

e

e

e

e

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

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

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 T

1

– Draw T1 and then draw T

2

● If e and T2 are on different sides of T

1

– Draw T2 and then draw T

1

Inside(Back)

Outside(Front)

Page 8: Visibility - Indian Institute of Technology Bombayparagc/teaching/2015/cs475/lectures/08_visibility_h.pdfVisibility Backface Culling is not enough Backface Culling does not remove

   

 

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

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 T

2

● If then draw T2 and then draw T

1

pe

q

f r =r−p . n

f q . f e0

f q . f e0

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

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)

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

Visibility

● BSP Tree construction

12

34

56

7

89

10

11

1

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

2, 3, 4

IN OUT

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

Visibility

● BSP Tree construction

12

34

56

7

89

10

11

1

6, 7,  10, 11

3, 4

IN OUT

2 5

8

IN OUTIN

Page 9: Visibility - Indian Institute of Technology Bombayparagc/teaching/2015/cs475/lectures/08_visibility_h.pdfVisibility Backface Culling is not enough Backface Culling does not remove

   

 

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

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

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

Visibility

● BSP Tree construction

12

34

56

7

89b

10

11

1

7, 9a 10, 11

2 5

9a

3

4

6 8

9b

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

Visibility

● BSP Tree construction

12

34

56

7

89b

10

11

1

2 5

9a

3

4

8

7

9a

10

11

6

9b

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

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 10: Visibility - Indian Institute of Technology Bombayparagc/teaching/2015/cs475/lectures/08_visibility_h.pdfVisibility Backface Culling is not enough Backface Culling does not remove

   

 

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

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

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

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

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

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.

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

Visibility

Surrounding Intersecting Contained Disjoint

Area ofInterest

Polygon● Warnock's Algorithm

The starting area is the whole image.

Page 11: Visibility - Indian Institute of Technology Bombayparagc/teaching/2015/cs475/lectures/08_visibility_h.pdfVisibility Backface Culling is not enough Backface Culling does not remove

   

 

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

Visibility

Surrounding Intersecting Contained Disjoint

Area ofInterest

Polygon● Warnock's Algorithm

Test in the area and subdivide.

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

Visibility

Surrounding Intersecting Contained Disjoint

Area ofInterest

Polygon● Warnock's Algorithm

Test in the area and subdivide.

CS 475/ CS 675: Lecture 8 Parag Chaudhuri, 2015

Visibility

Surrounding Intersecting Contained Disjoint

Area ofInterest

Polygon● Warnock's Algorithm

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