visibility - dynamic graphics project · visibility • intro visibility • object vs image space...

28
2/20/16 1 Topic 8 Visibility Intro visibility Object vs Image space algorithms Bounding volumes Culling Clipping Z-buffering Scan conversion Visibility What is not visible?

Upload: others

Post on 31-May-2020

22 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

1

Topic8Visibility

• Introvisibility• ObjectvsImagespacealgorithms• Boundingvolumes• Culling• Clipping• Z-buffering• Scanconversion

Visibility

Whatisnotvisible?

Page 2: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

2

Visibility

Whatisnotvisible?• Primitivesoutside ofthefieldofview• Back-facingprimitives• Primitivesoccludedbyotherobjects closertothecamera

Whycomputevisibility?

• Generalprinciple:don’t spendcyclesdrawingwhatyoudon’thaveto!• Somethingsarenotvisible. Canwegetridofthese?• Efficiency:Ifitwon’tcontributetothefinalimage,avoidunnecessarycomputations.• Realism:Objectsocclusions naturallyhappen inscenes

Page 3: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

3

Whycomputevisibility

• Examplecubeinperspective:• Atmostthreefaceswillbevisible• Threesides don’tevenneedtobedrawn

(Googleimages)

Whycomputevisibility

Imagesource:http://www.cs.sfu.ca/~torsten/

Page 4: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

4

Whycomputevisibility

Imagesource:http://www.cs.sfu.ca/~torsten/

Typesofalgorithms

• Objectspace• Occursatthepolygon levelinobjectspace• Dotheworkon theobjectsthemselvesbeforetheyareconverted topixels• Doneatthemathematical/analyticallevelindependentofresolution

• Imagesspace• Occursatthepixellevelinimagespace• Workdonewhenobjectsarebeingconverted topixels• Resolutionofthedisplaymattershere• Determinethecolour ofpixelbasedonwhatisvisible

Page 5: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

5

ObjectSpace

for each object in scene {

determine which parts of objects are visible (parts unobstructed by itself or other objects)

rasterize only those parts

}

ImageSpace

for each pixel in image {

determine polygon closest to the viewer at that pixel location

colour the pixel with the appropriate colour

}

Page 6: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

6

Efficiency

• Boundingvolumes (boxes, spheres)• Back-faceculling• Coherence(exploitlocalsimilarity)

BoundingVolumes

Source:Google images

Page 7: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

7

Culling

• Frustumculling• Cullingoftrianglesoutsideoftheviewfrustum

• Occlusion culling• Cullingoftriangleswithinthefrustumthatareoccludedbyothers

• Backface culling• Cullingoftrianglesfacingawayfromthecamera

Backface Culling

• Goal:Removesurfacesthatpointaway fromthecamera(i.e.the“backfacing”polygons).Don’tdrawthese!• For(most)solid objects, backfacesshould notbevisibleà hidden• Canbedoneinwindow coordinates(windingorder)orinworldcoordinatesusingfacenormals.

Page 8: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

8

Back-faceCulling

Backfacing facesonthewireframemodel:ADHE,EHGF,AEFBwillnotbedrawn.

Back-faceCulling

Page 9: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

9

Back-faceCulling• Some limitations:

VisibilityAlgorithms

• Object-spacealgorithms:• Painter’sAlgorithm• BinarySpacePartitioningalgorithm(BSP)(nextweek)

• Image-spacealgorithms:• Z-buffer• Scanline

Page 10: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

10

Painter’salgorithm

Painter’salgorithm

• Limitations:Cycles• Thereisno sortorderheretoallowcorrectvisibility handling• Workaround: breakpolygons intosmallerparts

Page 11: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

11

Clipping

Clipping

Page 12: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

12

Clipping

Clipping

Page 13: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

13

Clipping

Clipping

Page 14: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

14

Clipping

Clipping

Page 15: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

15

Clipping

WhentodoClipping

Page 16: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

16

WhentodoClipping

• Easiesttoclipbefore thehomogenizationstepandclipinhomogeneous coordinates• Thismeansweactuallyclipinfourdimensions againstthreedimensional clippinghyperplanes.• Afterhomogenization,theresultgivesusthecoordinatesin3Dspace.

Z-buffering

Page 17: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

17

Z-buffering

• Animage-spacealgorithm.• Maintainsdepthforeachpixel(reallythepseudo-depth)• Initiallysetto“veryfaraway”• Checks thedepthofacolour beforecolouring thepixel.• Ifcolour is“closer”then,colour pixelwithitandupdatethez-buffer.• Else,keepeverythingasis.

Z-buffering

for each polygonfor each pixel p in the polygon's projection{pz = pseudo-depth at (x, y);if (pz > zBuffer[x, y]) // closer to the camera

{zBuffer[x, y] = pz;framebuffer[x, y] = colour of pixel p}

}

Page 18: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

18

Z-buffering

Z-buffering

Page 19: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

19

Z-buffering

Z-buffering

Q:Whatwouldtheresultbeifwedrewtheclosesttriangle first?

Page 20: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

20

Z-buffering

Q:Whatwouldtheresultbeifwedrewtheclosesttriangle first?

A:Theresultwouldbethesame

Z-buffering

Advantages:• Simple andaccurate• Independentoftheorderpolygons aredrawnDisadvantages:• Biggestissuewithz-bufferingisfiniteprecision(z-fighting)• Wastedcomputationwhenoverwritingdistantpoints

Page 21: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

21

Rasterizationorscanconversion

Fillingpolygons

Page 22: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

22

Fillingpolygons

Coherence

Page 23: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

23

Polygonscanconversion

Polygonscanconversion

Processeachscanline1. Findtheintersections ofthescanlinewith allpolygonedges.2. Sorttheintersections byxcoordinate.3. Fill inpixelsbetweenpairsofintersections usinganodd-

parityrule.- Setparityeveninitially.- Eachintersectionflipstheparity.- Drawwhenparityisodd.

Page 24: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

24

Specialcases:vertices

• Q:Howdowecounttheintersectingvertexintheparitycomputation?

Specialcases:vertices

• Q:Howdowecounttheintersectingvertexintheparitycomputation?

A:Countitzeroortwotimes.

Page 25: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

25

Computing intersections

• Foreachscanline,weneedtoknowifitintersectsthepolygon edges.• Itisexpensive tocomputeacompleteline-line intersectioncomputationforeachscanline.• Aftercomputingtheintersectionbetweenascanlineandanedge,wecanusethatinformationinthenextscanline.• Wecanexploitscanlinecoherence.

Rasterizinggeneralpolygons

• Let’slook atamoregeneralmethodforpolygons.• Fortriangles,itbecomes evenmoreefficient(only onespanperscanlinesinceitisalwaysconvex)

Page 26: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

26

Rasterizinggeneralpolygons

Rasterizinggeneralpolygons

Page 27: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

27

Rasterizinggeneralpolygons

Rasterizinggeneralpolygons

Page 28: Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space algorithms • Bounding volumes • Culling • Clipping • Z-buffering • Scan

2/20/16

28

Rasterizinggeneralpolygons

Rasterizinggeneralpolygons