visibility algorithms for computer graphics
DESCRIPTION
Visibility Algorithms for Computer Graphics. CS 551/645 Introduction to Computer Graphics Guest lecture by David Luebke. But First…. CS 551/651: Advanced Computer Graphics I’m teaching next semester Follows and builds on 551/645. Topics: Photorealism: Ray tracing, path tracing, radiosity - PowerPoint PPT PresentationTRANSCRIPT
David Luebke 11-2-98
Visibility Algorithms for Visibility Algorithms for Computer GraphicsComputer Graphics
CS 551/645 CS 551/645 Introduction to Computer GraphicsIntroduction to Computer Graphics
Guest lecture by David LuebkeGuest lecture by David Luebke
David Luebke 11-2-98
But First…But First…
CS 551/651: Advanced Computer GraphicsCS 551/651: Advanced Computer Graphics– I’m teaching next semesterI’m teaching next semester– Follows and builds on 551/645. Topics:Follows and builds on 551/645. Topics:
Photorealism: Ray tracing, path tracing, radiosityPhotorealism: Ray tracing, path tracing, radiosity Speed: Occlusion culling, level-of-detail, texture tricksSpeed: Occlusion culling, level-of-detail, texture tricks Hardware: rendering pipeline, graphics architecturesHardware: rendering pipeline, graphics architectures Non-photorealism: pen-and-ink, painterly renderingNon-photorealism: pen-and-ink, painterly rendering Image-based rendering: image warping, sprites, Image-based rendering: image warping, sprites,
layered-depth imageslayered-depth images
– Will also be taught in grad/undergrad formatsWill also be taught in grad/undergrad formats
David Luebke 11-2-98
OverviewOverview
Recap: visible surfaces; Z-bufferRecap: visible surfaces; Z-buffer Other exact algorithmsOther exact algorithms
– BSP treesBSP trees– Ray tracingRay tracing
Conservative algorithmsConservative algorithms– View-frustum cullingView-frustum culling– Cells & portalsCells & portals– Occlusion cullingOcclusion culling
David Luebke 11-2-98
Recap: The Visible Recap: The Visible Surface ProblemSurface Problem
Problem: Many polygons may map Problem: Many polygons may map to same pixel on screen.to same pixel on screen.
Goal: Correctly color pixels, using Goal: Correctly color pixels, using only only unoccludedunoccluded polygons polygons
Formally, Formally, aa occludes occludes bb if: if:– aa and and bb are on the same projector are on the same projector– aa is closer to the center of projection is closer to the center of projection
David Luebke 11-2-98
Recap: Recap: Painter’s AlgorithmPainter’s Algorithm
Idea: do what painters do Idea: do what painters do – Sort objects by depthSort objects by depth– Draw objects from distant to nearDraw objects from distant to near– Just overwrite already-drawn objects Just overwrite already-drawn objects
as you goas you go
David Luebke 11-2-98
Recap:Recap:Painter’s Algorithm Painter’s Algorithm
Pros:Pros:– Simple, fast rasterizationSimple, fast rasterization
Cons: Cons: – Sorting is O(Sorting is O(nn lg lg nn), and ), and nn can get big can get big– Some objects can’t be sorted by depth:Some objects can’t be sorted by depth:
David Luebke 11-2-98
Recap: Z-BufferRecap: Z-Buffer
Idea: resolve visibility Idea: resolve visibility at each pixelat each pixel– Store depth of nearest polygon at pixelStore depth of nearest polygon at pixel– Reset pixel color & depth only if nearer Reset pixel color & depth only if nearer
polygon is foundpolygon is found– Embed this test in rasterization loopEmbed this test in rasterization loop
Pros: simple, linear-time algorithmPros: simple, linear-time algorithm Cons: Read-Modify-Write in inner loop Cons: Read-Modify-Write in inner loop
demands large, fast, dedicated memory demands large, fast, dedicated memory bank (the bank (the Z-bufferZ-buffer))
David Luebke 11-2-98
OverviewOverview
Recap: visible surfaces; Z-bufferRecap: visible surfaces; Z-buffer Other exact algorithmsOther exact algorithms
– BSP treesBSP trees– Ray tracingRay tracing
Conservative algorithmsConservative algorithms– View-frustum cullingView-frustum culling– Cells & portalsCells & portals– Occlusion cullingOcclusion culling
David Luebke 11-2-98
Binary Space PartitionBinary Space Partition(BSP) Trees(BSP) Trees
Fuchs et al, 1980Fuchs et al, 1980 Assumptions:Assumptions:
– Static sceneStatic scene– Moving cameraMoving camera
Commonly used in 3-D video games Commonly used in 3-D video games (e.g., Quake), but going out of style(e.g., Quake), but going out of style
Still a very powerful, general idea, Still a very powerful, general idea, used in many graphics algorithmsused in many graphics algorithms
David Luebke 11-2-98
BSP TreesBSP Trees
– PreprocessPreprocess: overlay a binary (BSP) : overlay a binary (BSP) tree on objects in the scenetree on objects in the scene
– RuntimeRuntime: correctly traversing this tree : correctly traversing this tree enumerates objects from back to frontenumerates objects from back to front
– Idea: divide space recursively into half-Idea: divide space recursively into half-spaces by choosing spaces by choosing splitting planessplitting planes
Splitting planes can be arbitrarily orientedSplitting planes can be arbitrarily oriented Notice: nodes are always convexNotice: nodes are always convex
David Luebke 11-2-98
BSP TreesBSP Trees
David Luebke 11-2-98
BSP TreesBSP Trees
David Luebke 11-2-98
BSP TreesBSP Trees
David Luebke 11-2-98
BSP TreesBSP Trees
David Luebke 11-2-98
BSP TreesBSP Trees
David Luebke 11-2-98
BSP Trees: RenderingBSP Trees: Rendering
renderBSP(BSPtree *T)renderBSP(BSPtree *T)
BSPtree *near, far;BSPtree *near, far;
if (if (T is a leaf nodeT is a leaf node))
renderObject(T)renderObject(T)
if (if (eye on left side of T->planeeye on left side of T->plane))
near = T->left; far = T->right;near = T->left; far = T->right;
else else
near = T->right; far = T->left;near = T->right; far = T->left;
renderBSP(far);renderBSP(far);
renderBSP(near);renderBSP(near);
David Luebke 11-2-98
BSP Trees: RenderingBSP Trees: Rendering
David Luebke 11-2-98
BSP Trees: RenderingBSP Trees: Rendering
David Luebke 11-2-98
BSP Trees: The CatchBSP Trees: The Catch
No bunnies were harmed in my exampleNo bunnies were harmed in my example But what if a splitting plane passes through But what if a splitting plane passes through
an object?an object?– Split the object; give half to each node:Split the object; give half to each node:
– Worst case: can create up to O(nWorst case: can create up to O(n33) objects!) objects!
Ouch
David Luebke 11-2-98
OverviewOverview
Recap: visible surfaces; Z-bufferRecap: visible surfaces; Z-buffer Other exact algorithmsOther exact algorithms
– BSP treesBSP trees– Ray tracingRay tracing
Conservative algorithmsConservative algorithms– View-frustum cullingView-frustum culling– Cells & portalsCells & portals– Occlusion cullingOcclusion culling
David Luebke 11-2-98
Ray TracingRay Tracing
Idea: Idea: – trace a ray from the eyepoint through trace a ray from the eyepoint through
the center of each pixelthe center of each pixel– Color pixel according to Color pixel according to the first object the first object
the ray hitsthe ray hits– Simple! No need for:Simple! No need for:
Perspective projection matricesPerspective projection matrices ClippingClipping Scan conversion of polygonsScan conversion of polygons
David Luebke 11-2-98
Ray TracingRay Tracing
An example:An example:
ScreenEyepoint Scene
David Luebke 11-2-98
Ray TracingRay Tracing
An example:An example:
ScreenEyepoint Scene
David Luebke 11-2-98
Ray TracingRay Tracing
Two flavors of the algorithm:Two flavors of the algorithm:– Ray castingRay casting just finds visible surfaces just finds visible surfaces– Recursive ray tracingRecursive ray tracing traces additional traces additional
rays from those surfaces for rays from those surfaces for sophisticated shadingsophisticated shading
ShadowsShadows ReflectionReflection RefractionRefraction
David Luebke 11-2-98
Ray Tracing: The CatchRay Tracing: The Catch
Ray tracing is a simple, powerful Ray tracing is a simple, powerful way to determine visibility & shadingway to determine visibility & shading
So why don’t we always use it?So why don’t we always use it?
David Luebke 11-2-98
Ray Tracing: The CatchRay Tracing: The Catch
Ray tracing is a simple, powerful Ray tracing is a simple, powerful way to determine visibility & shadingway to determine visibility & shading
So why don’t we always use it?So why don’t we always use it? Too slow!Too slow!
– Complexity proportional to # of pixelsComplexity proportional to # of pixels– Typical screen: ~1,000,000 pixelsTypical screen: ~1,000,000 pixels– Typical scene:« 1,000,000 polygonsTypical scene:« 1,000,000 polygons
David Luebke 11-2-98
OverviewOverview
Recap: visible surfaces; Z-bufferRecap: visible surfaces; Z-buffer Other exact algorithmsOther exact algorithms
– BSP treesBSP trees– Ray castingRay casting
Conservative algorithmsConservative algorithms– View-frustum cullingView-frustum culling– Cells & portalsCells & portals– Occlusion cullingOcclusion culling
David Luebke 11-2-98
Conservative AlgorithmsConservative Algorithms
Rendering with a Z-buffer finds Rendering with a Z-buffer finds exact exact visibilityvisibility of of nn polygons in O( polygons in O(nn) time) time
Conservative visibilityConservative visibility algorithmsalgorithms quickly compute a quickly compute a potentially visible potentially visible setset of of vv polygons, polygons, v v « « nn– v v = all visible polygons + a few others= all visible polygons + a few others
Z-buffer can then render this set in Z-buffer can then render this set in O(v) timeO(v) time
David Luebke 11-2-98
View-frustum cullingView-frustum culling
Simple way to quickly reject many Simple way to quickly reject many polygons at once: polygons at once: – Associate simple bounding volumes Associate simple bounding volumes
(e.g., spheres) with each object(e.g., spheres) with each object– Before rendering object, test its Before rendering object, test its
bounding volume for visibilitybounding volume for visibilityPotentially
Visible
Not Visible
David Luebke 11-2-98
OverviewOverview
Recap: visible surfaces; Z-bufferRecap: visible surfaces; Z-buffer Other exact algorithmsOther exact algorithms
– BSP treesBSP trees– Ray castingRay casting
Conservative algorithmsConservative algorithms– View-frustum cullingView-frustum culling– Cells & portalsCells & portals– Occlusion cullingOcclusion culling
David Luebke 11-2-98
Cells & PortalsCells & Portals
Goal: walk through architectural Goal: walk through architectural models (buildings, cities, catacombs…)models (buildings, cities, catacombs…)
These divide naturally into These divide naturally into cellscells– Rooms, alcoves, corridors… Rooms, alcoves, corridors…
Transparent Transparent portalsportals connect cellsconnect cells– Doorways, entrances, windows… Doorways, entrances, windows…
Key observation: cells only see each Key observation: cells only see each other through portals!other through portals!
David Luebke 11-2-98
Cells & PortalsCells & Portals
Idea: Idea: – Create an Create an adjacency graphadjacency graph of cells– Starting with cell containing eyepoint, Starting with cell containing eyepoint,
traverse graph, rendering visible cells traverse graph, rendering 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 Need a Need a line of sightline of sight So cell visibility reduces to testing portal So cell visibility reduces to testing portal
sequences… sequences…
David Luebke 11-2-98
Cells & PortalsCells & Portals
A
D
H
FCB
E
G
H
B C D F G
EA
David Luebke 11-2-98
Cells & PortalsCells & Portals
A
D
H
FCB
E
G
H
B C D F G
EA
David Luebke 11-2-98
Cells & PortalsCells & Portals
A
D
H
FCB
E
G
H
B C D F G
EA
David Luebke 11-2-98
Cells & PortalsCells & Portals
A
D
H
FCB
E
G
H
B C D F G
EA
David Luebke 11-2-98
Cells & PortalsCells & Portals
A
D
H
FCB
E
G
H
B C D F G
EA
David Luebke 11-2-98
Cells & PortalsCells & Portals
Can even figure out which cells a Can even figure out which cells a particular cell will particular cell will nevernever see: see:
Ex: H will Ex: H will nevernever see F; B can see F; B can onlyonly see H see H
This can further speed up cullingThis can further speed up culling
A
D
H
FCB
E
G
David Luebke 11-2-98
OverviewOverview
Recap: visible surfaces; Z-bufferRecap: visible surfaces; Z-buffer Other exact algorithmsOther exact algorithms
– BSP treesBSP trees– Ray castingRay casting
Conservative algorithmsConservative algorithms– View-frustum cullingView-frustum culling– Cells & portalsCells & portals– OcclusionOcclusion cullingculling
David Luebke 11-2-98
Occlusion CullingOcclusion Culling
When cells and portals don’t work…When cells and portals don’t work…– Trees in a forestTrees in a forest– A crowded train stationA crowded train station
Need general Need general occlusion cullingocclusion culling algs: algs:– Dynamic scenes, aggregate occludersDynamic scenes, aggregate occluders– Open problem, little work so far:Open problem, little work so far:
Hierarchical Z-Buffer (Greene 93)Hierarchical Z-Buffer (Greene 93) Hierarchical Occlusion Maps (Zhang 97)Hierarchical Occlusion Maps (Zhang 97)