420 likes | 750 Views
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
E N D
Visibility Algorithms for Computer Graphics CS 551/645 Introduction to Computer Graphics Guest lecture by David Luebke David Luebke 11-2-98
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 • Speed: Occlusion culling, level-of-detail, texture tricks • Hardware: rendering pipeline, graphics architectures • Non-photorealism: pen-and-ink, painterly rendering • Image-based rendering: image warping, sprites, layered-depth images • Will also be taught in grad/undergrad formats David Luebke 11-2-98
Overview • Recap: visible surfaces; Z-buffer • Other exact algorithms • BSP trees • Ray tracing • Conservative algorithms • View-frustum culling • Cells & portals • Occlusion culling David Luebke 11-2-98
Recap: The Visible Surface Problem • Problem: Many polygons may map to same pixel on screen. • Goal: Correctly color pixels, using only unoccluded polygons • Formally, a occludes b if: • a and b are on the same projector • a is closer to the center of projection David Luebke 11-2-98
Recap: Painter’s Algorithm • Idea: do what painters do • Sort objects by depth • Draw objects from distant to near • Just overwrite already-drawn objects as you go David Luebke 11-2-98
Recap:Painter’s Algorithm • Pros: • Simple, fast rasterization • Cons: • Sorting is O(n lg n), and n can get big • Some objects can’t be sorted by depth: David Luebke 11-2-98
Recap: Z-Buffer • Idea: resolve visibility at each pixel • Store depth of nearest polygon at pixel • Reset pixel color & depth only if nearer polygon is found • Embed this test in rasterization loop • Pros: simple, linear-time algorithm • Cons: Read-Modify-Write in inner loop demands large, fast, dedicated memory bank (the Z-buffer) David Luebke 11-2-98
Overview • Recap: visible surfaces; Z-buffer • Other exact algorithms • BSP trees • Ray tracing • Conservative algorithms • View-frustum culling • Cells & portals • Occlusion culling David Luebke 11-2-98
Binary Space Partition(BSP) Trees • Fuchs et al, 1980 • Assumptions: • Static scene • Moving camera • Commonly used in 3-D video games (e.g., Quake), but going out of style • Still a very powerful, general idea, used in many graphics algorithms David Luebke 11-2-98
BSP Trees • Preprocess: overlay a binary (BSP) tree on objects in the scene • Runtime: correctly traversing this tree enumerates objects from back to front • Idea: divide space recursively into half-spaces by choosing splitting planes • Splitting planes can be arbitrarily oriented • Notice: nodes are always convex David Luebke 11-2-98
BSP Trees David Luebke 11-2-98
BSP Trees David Luebke 11-2-98
BSP Trees David Luebke 11-2-98
BSP Trees David Luebke 11-2-98
BSP Trees David Luebke 11-2-98
BSP Trees: Rendering renderBSP(BSPtree *T) BSPtree *near, far; if (T is a leaf node) renderObject(T) if (eye on left side of T->plane) near = T->left; far = T->right; else near = T->right; far = T->left; renderBSP(far); renderBSP(near); David Luebke 11-2-98
BSP Trees: Rendering David Luebke 11-2-98
BSP Trees: Rendering David Luebke 11-2-98
Ouch BSP Trees: The Catch • No bunnies were harmed in my example • But what if a splitting plane passes through an object? • Split the object; give half to each node: • Worst case: can create up to O(n3) objects! David Luebke 11-2-98
Overview • Recap: visible surfaces; Z-buffer • Other exact algorithms • BSP trees • Ray tracing • Conservative algorithms • View-frustum culling • Cells & portals • Occlusion culling David Luebke 11-2-98
Ray Tracing • Idea: • trace a ray from the eyepoint through the center of each pixel • Color pixel according to the first object the ray hits • Simple! No need for: • Perspective projection matrices • Clipping • Scan conversion of polygons David Luebke 11-2-98
Ray Tracing • An example: Eyepoint Screen Scene David Luebke 11-2-98
Ray Tracing • An example: Eyepoint Screen Scene David Luebke 11-2-98
Ray Tracing • Two flavors of the algorithm: • Ray casting just finds visible surfaces • Recursive ray tracing traces additional rays from those surfaces for sophisticated shading • Shadows • Reflection • Refraction David Luebke 11-2-98
Ray Tracing: The Catch • Ray tracing is a simple, powerful way to determine visibility & shading • So why don’t we always use it? David Luebke 11-2-98
Ray Tracing: The Catch • Ray tracing is a simple, powerful way to determine visibility & shading • So why don’t we always use it? • Too slow! • Complexity proportional to # of pixels • Typical screen: ~1,000,000 pixels • Typical scene:« 1,000,000 polygons David Luebke 11-2-98
Overview • Recap: visible surfaces; Z-buffer • Other exact algorithms • BSP trees • Ray casting • Conservative algorithms • View-frustum culling • Cells & portals • Occlusion culling David Luebke 11-2-98
Conservative Algorithms • Rendering with a Z-buffer finds exact visibility of n polygons in O(n) time • Conservative visibilityalgorithms quickly compute a potentially visible set of v polygons, v « n • v = all visible polygons + a few others • Z-buffer can then render this set in O(v) time David Luebke 11-2-98
View-frustum culling • Simple way to quickly reject many polygons at once: • Associate simple bounding volumes (e.g., spheres) with each object • Before rendering object, test its bounding volume for visibility PotentiallyVisible Not Visible David Luebke 11-2-98
Overview • Recap: visible surfaces; Z-buffer • Other exact algorithms • BSP trees • Ray casting • Conservative algorithms • View-frustum culling • Cells & portals • Occlusion culling David Luebke 11-2-98
Cells & Portals • Goal: walk through architectural models (buildings, cities, catacombs…) • These divide naturally into cells • Rooms, alcoves, corridors… • Transparent portalsconnect cells • Doorways, entrances, windows… • Key observation: cells only see each other through portals! David Luebke 11-2-98
Cells & Portals • Idea: • Create an adjacency graphof cells • Starting with cell containing eyepoint, traverse graph, rendering visible cells • A cell is only visible if it can be seen through a sequence of portals • Need a line of sight • So cell visibility reduces to testing portal sequences… David Luebke 11-2-98
Cells & Portals A D E F B C G H A E B C D F G H David Luebke 11-2-98
Cells & Portals A D E F B C G H A E B C D F G H David Luebke 11-2-98
Cells & Portals A D E F B C G H A E B C D F G H David Luebke 11-2-98
Cells & Portals A D E F B C G H A E B C D F G H David Luebke 11-2-98
Cells & Portals A D E F B C G H A E B C D F G H David Luebke 11-2-98
A D E F B C G H Cells & Portals • Can even figure out which cells a particular cell will never see: Ex: H will never see F; B can only see H • This can further speed up culling David Luebke 11-2-98
Overview • Recap: visible surfaces; Z-buffer • Other exact algorithms • BSP trees • Ray casting • Conservative algorithms • View-frustum culling • Cells & portals • Occlusionculling David Luebke 11-2-98
Occlusion Culling • When cells and portals don’t work… • Trees in a forest • A crowded train station • Need general occlusion culling algs: • Dynamic scenes, aggregate occluders • Open problem, little work so far: • Hierarchical Z-Buffer (Greene 93) • Hierarchical Occlusion Maps (Zhang 97) David Luebke 11-2-98