visibility culling ii: beyond cells & portals david luebke computer science department...

32
Visibility Culling Visibility Culling II: II: Beyond Cells & Beyond Cells & Portals Portals David Luebke David Luebke Computer Science Computer Science Department Department University of Virginia University of Virginia <[email protected]> <[email protected]>

Upload: robert-morrison

Post on 02-Jan-2016

219 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

Visibility Culling II:Visibility Culling II:Beyond Cells & PortalsBeyond Cells & Portals

David LuebkeDavid Luebke

Computer Science Computer Science DepartmentDepartment

University of VirginiaUniversity of Virginia

<[email protected]><[email protected]>

Page 2: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D2

Review: Cells & Review: Cells & PortalsPortals

• Idea: Idea: – Cells form the basic unit of Cells form the basic unit of PVSPVS– Create an Create an adjacency graphadjacency graph of cells– Starting with cell containing Starting with cell containing

eyepoint, traverse graph, rendering eyepoint, traverse graph, rendering visible cells visible cells

– A cell is only visible if it can be seen A cell is only visible if it can be seen through a sequence of portalsthrough a sequence of portals

• So cell visibility reduces to testing So cell visibility reduces to testing portal sequences for a portal sequences for a line of sight…line of sight…

Page 3: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D3

Cells & Portals:Cells & Portals:View-Dependent SolutionView-Dependent Solution

A

D

H

FCB

E

G

H

B C D F G

EA

Page 4: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D4

Cells & Portals:Cells & Portals:View-Dependent SolutionView-Dependent Solution

A

D

H

FCB

E

G

H

B C D F G

EA

Page 5: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D5

Cells & Portals:Cells & Portals:View-Dependent SolutionView-Dependent Solution

A

D

H

FCB

E

G

H

B C D F G

EA

Page 6: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D6

Cells & Portals:Cells & Portals:View-Dependent SolutionView-Dependent Solution

A

D

H

FCB

E

G

H

B C D F G

EA

Page 7: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D7

Cells & Portals:Cells & Portals:View-Dependent SolutionView-Dependent Solution

A

D

H

FCB

E

G

H

B C D F G

EA

Page 8: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D8

Cells & Portals:Cells & Portals:View-Dependent SolutionView-Dependent Solution

A

D

H

FCB

E

G

H

B C D F G

EA

?

??

Page 9: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D9

Cells & Portals:Cells & Portals:View-Dependent SolutionView-Dependent Solution

A

D

H

FCB

E

G

H

B C D F G

EA

X

XX

Page 10: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D10

Cells & Portals:Cells & Portals:View-Independent View-Independent

SolutionSolution• View-independentView-independent solution: find all solution: find all

cells a particular cell could cells a particular cell could possiblypossibly see:see:

C can C can onlyonly see A, D, E, and H see A, D, E, and H

A

D

H

FCB

E

G

A

D

H

E

Page 11: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D11

Cells & Portals:Cells & Portals:View-Independent View-Independent

SolutionSolution• View-independentView-independent solution: find all solution: find all

cells a particular cell could cells a particular cell could possiblypossibly see:see:

H will H will nevernever see F see F

A

D

H

FCB

E

G

A

D

CB

E

G

Page 12: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D12

Review: Cells and Review: Cells and PortalsPortals

• Questions:Questions:– How can we detect whether a given How can we detect whether a given

cell is visible from a given viewpoint?cell is visible from a given viewpoint?– How can we detect view-independent How can we detect view-independent

visibility between cells?visibility between cells?

• The The key insightkey insight: : – These problems reduce to eye-portal These problems reduce to eye-portal

and portal-portal visibilityand portal-portal visibility

Page 13: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D13

Cells and PortalsCells and Portals

• Luebke (1995): view-dependent Luebke (1995): view-dependent onlyonly– Eye-portal visibility determined by Eye-portal visibility determined by

intersecting portal intersecting portal cull boxescull boxes– No preprocess (integrate w/ No preprocess (integrate w/

modeling)modeling)– Quick, simple hackQuick, simple hack– Public-domain library: Public-domain library:

pfportals.cs.virginia.edupfportals.cs.virginia.edu

Page 14: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D14

pfPortals AlgorithmpfPortals Algorithm

• Depth-first adjacency graph traversalDepth-first adjacency graph traversal– Render cell containing viewerRender cell containing viewer– Treat portals as special polygonsTreat portals as special polygons

• If portal is visible, render adjacent cellIf portal is visible, render adjacent cell• But clip to boundaries of portal!But clip to boundaries of portal!• Recursively check portals in that cell against Recursively check portals in that cell against

new clip boundaries (and render) new clip boundaries (and render)

– Each visible Each visible portal sequenceportal sequence amounts to amounts to a series of nested portal boundaries a series of nested portal boundaries

• Kept implicitly on recursion stackKept implicitly on recursion stack

Page 15: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D15

pfPortals AlgorithmpfPortals Algorithm

• Recursively rendering cells while Recursively rendering cells while clipping to portal boundaries not newclipping to portal boundaries not new– Visible-surface algorithm (Jones 1971): Visible-surface algorithm (Jones 1971):

general polygon-polygon clippinggeneral polygon-polygon clipping• Elegant, expensive, complicatedElegant, expensive, complicated

– Conservative overestimate (pfPortals): Conservative overestimate (pfPortals): use portal’s use portal’s cull boxcull box

• Cull box = x-y screenspace bounding boxCull box = x-y screenspace bounding box• Cheap to compute, very cheap (constant time) Cheap to compute, very cheap (constant time)

to intersectto intersect

Page 16: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D16

pfPortals AlgorithmpfPortals Algorithm

• How badly does the cull box How badly does the cull box approximation overestimate PVS?approximation overestimate PVS?– Not much for most architectural Not much for most architectural

scenesscenes

• Note: Can implement mirrors as Note: Can implement mirrors as portals with an extra portals with an extra transformation!transformation!– Some clipping & Z-buffering issues Some clipping & Z-buffering issues – Must limit recursionMust limit recursion

Page 17: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D17

Cells and Portals: Cells and Portals: DetailsDetails

• Usually separate model into Usually separate model into occludersoccluders and and detail objectsdetail objects– Occluders: walls, floorsOccluders: walls, floors– Detail objects: desks, chairs, pencilsDetail objects: desks, chairs, pencils– Cell creation process only accounts for Cell creation process only accounts for

occluders (occluders (Why?Why?))

• pfPortals: find detail object visibility pfPortals: find detail object visibility through portal sequences at run timethrough portal sequences at run time

• Teller: also precompute into PVSTeller: also precompute into PVS

Page 18: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D18

Why View-Why View-Independent?Independent?

• If view-dependent techniques can If view-dependent techniques can often calculate a reasonable PVS often calculate a reasonable PVS fast enough, why bother with fast enough, why bother with view-independent solutions?view-independent solutions?

• One good answer: smart One good answer: smart prefetchingprefetching– Soda Hall walkthrough (Funkhouser)Soda Hall walkthrough (Funkhouser)

• Whole model doesn’t fit in memoryWhole model doesn’t fit in memory• Use Teller stab trees to load in only Use Teller stab trees to load in only

cells that cells that mightmight be visible be visible

Page 19: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D19

Creating Cells and Creating Cells and PortalsPortals

• Given a model, how might you extract Given a model, how might you extract the cells and portals?the cells and portals?– Airey: k-D tree (axis-aligned boxes)Airey: k-D tree (axis-aligned boxes)– Teller: BSP tree (general convex cells)Teller: BSP tree (general convex cells)– Luebke: modeler (any cells at all)Luebke: modeler (any cells at all)

• Problems and issuesProblems and issues– Running timeRunning time– Free cellsFree cells– Intra-wall cellsIntra-wall cells

Page 20: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D20

Cells and Portals: Cells and Portals: DiscussionDiscussion

• Good solution for most Good solution for most architectural or urban modelsarchitectural or urban models– Use the simplest algorithm that Use the simplest algorithm that

suffices for your needs:suffices for your needs:• pfPortals-style algorithm: view-dependent pfPortals-style algorithm: view-dependent

solution, reasonably tight PVS, no solution, reasonably tight PVS, no preprocess necessary (except partition)preprocess necessary (except partition)

• Teller-style algorithm: tighter PVS, Teller-style algorithm: tighter PVS, somewhat more complex, can provide somewhat more complex, can provide view-independent solution for prefetchingview-independent solution for prefetching

Page 21: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D21

Cells and Portals: Cells and Portals: DiscussionDiscussion

• Public-domain code I’m aware of:Public-domain code I’m aware of:– pfPortals: pfPortals: http://pfportals.cs.virginia.eduhttp://pfportals.cs.virginia.edu

• A very simple set of Performer callbacks that A very simple set of Performer callbacks that implements cull-box portal cullingimplements cull-box portal culling

– pfWalkthru: pfWalkthru: http://home.earthlink.net/~mmchow/http://home.earthlink.net/~mmchow/

• Includes code to extract cells and portalsIncludes code to extract cells and portals

– Game engine sitesGame engine sites• Lots of “level builders” and “level compilers”Lots of “level builders” and “level compilers”• Treat these with a grain of saltTreat these with a grain of salt

Page 22: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D22

General Occlusion General Occlusion CullingCulling

• When cells and portals don’t When cells and portals don’t work…work…– Trees in a forestTrees in a forest– A crowded train stationA crowded train station

• Need general Need general occlusion cullingocclusion culling algorithms:algorithms:– Aggregate occlusion Aggregate occlusion – Dynamic scenesDynamic scenes– Non-polygonal scenesNon-polygonal scenes

Page 23: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D23

General Occlusion General Occlusion CullingCulling

• I’ll discuss three algorithms:I’ll discuss three algorithms:– Loose front-to-back sortingLoose front-to-back sorting– Hierarchical Z-Buffer Hierarchical Z-Buffer

• Ned Greene, SIGGRAPH 93Ned Greene, SIGGRAPH 93

– Hierarchical Occlusion Maps Hierarchical Occlusion Maps • Hansong Zhang, SIGGRAPH 97Hansong Zhang, SIGGRAPH 97

• I’ll also describe current I’ll also describe current hardware supporthardware support

Page 24: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D24

Loose Loose Front-To-Back Front-To-Back

SortingSorting• Can sort your geometry in roughly front-Can sort your geometry in roughly front-

to-back order, e.g. by:to-back order, e.g. by:– Using an octree/BSP treeUsing an octree/BSP tree– Sorting centroids or near points of bounding Sorting centroids or near points of bounding

volumesvolumes

• Why would this help?Why would this help?– A: Early rejection helps whole fragment A: Early rejection helps whole fragment

pipelinepipeline

• Why might this be hard?Why might this be hard?– A: could conflict with sorting by render stateA: could conflict with sorting by render state

Page 25: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D25

Image-SpaceImage-SpaceOcclusion CullingOcclusion Culling

• Most general occlusion culling Most general occlusion culling algorithms use an algorithms use an image-spaceimage-space approachapproach

• Idea: solve visibility in 2D, on Idea: solve visibility in 2D, on the image planethe image plane

Page 26: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D26

Hierarchical Z-BufferHierarchical Z-Buffer

• Replace Z-buffer with a Replace Z-buffer with a Z-pyramidZ-pyramid– Lowest level: full-resolution Z-bufferLowest level: full-resolution Z-buffer– Higher levels: each pixel represents Higher levels: each pixel represents

the maximum depth of the four the maximum depth of the four pixels “underneath” itpixels “underneath” it

• Basic idea: hierarchical Basic idea: hierarchical rasterization of the polygon, with rasterization of the polygon, with early termination where polygon early termination where polygon is occludedis occluded

Page 27: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D27

Hierarchical Z-BufferHierarchical Z-Buffer

• Idea: test polygon against highest Idea: test polygon against highest level firstlevel first– If polygon is further than distance If polygon is further than distance

recorded in pixel, stop—it’s occludedrecorded in pixel, stop—it’s occluded– If polygon is closer, recursively If polygon is closer, recursively

check against next lower levelcheck against next lower level– If polygon is visible at lowest level, If polygon is visible at lowest level,

set new distance value and set new distance value and propagate uppropagate up

Page 28: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D28

Hierarchical Z-BufferHierarchical Z-Buffer

• Z-pyramid exploits Z-pyramid exploits image-space image-space coherencecoherence: : – Polygon occluded in a pixel is Polygon occluded in a pixel is

probably occluded in nearby pixelsprobably occluded in nearby pixels

• HZB also exploits HZB also exploits object-space object-space coherencecoherence– Polygons near an occluded Polygons near an occluded

polygon are probably occludedpolygon are probably occluded

Page 29: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D29

Hierarchical Z-BufferHierarchical Z-Buffer

• Exploiting object-space Exploiting object-space coherence:coherence:– Subdivide scene with an octreeSubdivide scene with an octree– All geometry in an octree node is All geometry in an octree node is

contained by a cubecontained by a cube– Before rendering the contents of a Before rendering the contents of a

node, “render” the faces of its cube node, “render” the faces of its cube (i.e., query the Z-pyramid)(i.e., query the Z-pyramid)

– If cube faces are occluded, ignore If cube faces are occluded, ignore the entire nodethe entire node

Page 30: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D30

Hierarchical Z-BufferHierarchical Z-Buffer

• HZB can exploit HZB can exploit temporal coherencetemporal coherence– Most polygons affecting the Z-buffer last Most polygons affecting the Z-buffer last

frame will affect Z-buffer this frameframe will affect Z-buffer this frame– HZB also operates at max efficiency HZB also operates at max efficiency

when Z-pyramid already builtwhen Z-pyramid already built

• So start each frame by rendering So start each frame by rendering octree nodes visible last frameoctree nodes visible last frame

Page 31: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D31

Hierarchical Z-Hierarchical Z-Buffer:Buffer:

DiscussionDiscussion• HZB needs hardware support to be HZB needs hardware support to be

really competitivereally competitive• Hardware vendors haven’t entirely Hardware vendors haven’t entirely

bought in:bought in:– Z-pyramid (and hierarchies in general) Z-pyramid (and hierarchies in general)

unfriendly to hardwareunfriendly to hardware– Unpredictable Z-query times generate Unpredictable Z-query times generate

bubbles in rendering pipebubbles in rendering pipe

• But there is a promising trend…But there is a promising trend…

Page 32: Visibility Culling II: Beyond Cells & Portals David Luebke Computer Science Department University of Virginia

D32

Hierarchical Z-BufferHierarchical Z-Buffer

• Recent hardware supports Recent hardware supports Z-query operationZ-query operation– Allows systems to exploit:Allows systems to exploit:

• Object-space coherence (bounding boxes) Object-space coherence (bounding boxes) • Temporal coherence (last-rendered list)Temporal coherence (last-rendered list)

– Examples in OpenGL:Examples in OpenGL:• HP_OCCLUSION_QUERYHP_OCCLUSION_QUERY• NV_OCCLUSION_QUERYNV_OCCLUSION_QUERY• Go to NVIDIA occlusion presentation…Go to NVIDIA occlusion presentation…

– An aside: applies to cell-portal culling!An aside: applies to cell-portal culling!