Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space...
Transcript of Visibility - Dynamic Graphics Project · Visibility • Intro visibility • Object vs Image space...
2/20/16
1
Topic8Visibility
• Introvisibility• ObjectvsImagespacealgorithms• Boundingvolumes• Culling• Clipping• Z-buffering• Scanconversion
Visibility
Whatisnotvisible?
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
2/20/16
3
Whycomputevisibility
• Examplecubeinperspective:• Atmostthreefaceswillbevisible• Threesides don’tevenneedtobedrawn
(Googleimages)
Whycomputevisibility
Imagesource:http://www.cs.sfu.ca/~torsten/
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
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
}
2/20/16
6
Efficiency
• Boundingvolumes (boxes, spheres)• Back-faceculling• Coherence(exploitlocalsimilarity)
BoundingVolumes
Source:Google images
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.
2/20/16
8
Back-faceCulling
Backfacing facesonthewireframemodel:ADHE,EHGF,AEFBwillnotbedrawn.
Back-faceCulling
2/20/16
9
Back-faceCulling• Some limitations:
VisibilityAlgorithms
• Object-spacealgorithms:• Painter’sAlgorithm• BinarySpacePartitioningalgorithm(BSP)(nextweek)
• Image-spacealgorithms:• Z-buffer• Scanline
2/20/16
10
Painter’salgorithm
Painter’salgorithm
• Limitations:Cycles• Thereisno sortorderheretoallowcorrectvisibility handling• Workaround: breakpolygons intosmallerparts
2/20/16
11
Clipping
Clipping
2/20/16
12
Clipping
Clipping
2/20/16
13
Clipping
Clipping
2/20/16
14
Clipping
Clipping
2/20/16
15
Clipping
WhentodoClipping
2/20/16
16
WhentodoClipping
• Easiesttoclipbefore thehomogenizationstepandclipinhomogeneous coordinates• Thismeansweactuallyclipinfourdimensions againstthreedimensional clippinghyperplanes.• Afterhomogenization,theresultgivesusthecoordinatesin3Dspace.
Z-buffering
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}
}
2/20/16
18
Z-buffering
Z-buffering
2/20/16
19
Z-buffering
Z-buffering
Q:Whatwouldtheresultbeifwedrewtheclosesttriangle first?
2/20/16
20
Z-buffering
Q:Whatwouldtheresultbeifwedrewtheclosesttriangle first?
A:Theresultwouldbethesame
Z-buffering
Advantages:• Simple andaccurate• Independentoftheorderpolygons aredrawnDisadvantages:• Biggestissuewithz-bufferingisfiniteprecision(z-fighting)• Wastedcomputationwhenoverwritingdistantpoints
2/20/16
21
Rasterizationorscanconversion
Fillingpolygons
2/20/16
22
Fillingpolygons
Coherence
2/20/16
23
Polygonscanconversion
Polygonscanconversion
Processeachscanline1. Findtheintersections ofthescanlinewith allpolygonedges.2. Sorttheintersections byxcoordinate.3. Fill inpixelsbetweenpairsofintersections usinganodd-
parityrule.- Setparityeveninitially.- Eachintersectionflipstheparity.- Drawwhenparityisodd.
2/20/16
24
Specialcases:vertices
• Q:Howdowecounttheintersectingvertexintheparitycomputation?
Specialcases:vertices
• Q:Howdowecounttheintersectingvertexintheparitycomputation?
A:Countitzeroortwotimes.
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)
2/20/16
26
Rasterizinggeneralpolygons
Rasterizinggeneralpolygons
2/20/16
27
Rasterizinggeneralpolygons
Rasterizinggeneralpolygons
2/20/16
28
Rasterizinggeneralpolygons
Rasterizinggeneralpolygons