Visibility II CS 446: Real-Time Rendering & Game Technology David Luebke University of Virginia
Demo Time: Matt Spear NOTE: I’ve reorganized the next few demos: Feb 21: Paul Tschirhart Feb 23: Erin Golub Feb 28: Sean Arietta Mar 2: Jiayuan Meng If this is a problem, let me know! Real-Time Rendering 2 David Luebke
Assignment 3 Go over it Groups will be assigned before C.O.B. today… Give your preferences on the forum! Feel free to augment these by saying what you like about each idea Real-Time Rendering 3 David Luebke
Recap: Visibility Calculations Motivation: avoid rendering redundant geometry Huge speedup, especially for indoor environments Basic idea: don’t render what can’t be seen Off-screen: view-frustum culling Occluded by other objects: occlusion culling Real-Time Rendering 4 David Luebke
Recap: Potentially Visible Set Our goal: quickly eliminate large portions of the scene which will not be visible in the final image Not the exact visibility solution, but a quick-and-dirty conservative estimate of which primitives may be visible Z-buffer& clip this for the exact solution This conservative estimate is called the potentially visible set or PVS Real-Time Rendering 5 David Luebke
Recap: Cells & Portals Occlusion culling technique specialized for architectural models (buildings, cities, catacombs) These divide naturally into cells Rooms, alcoves, corridors… Transparent portals connect cells Doorways, entrances, windows… Notice: cells only see other cells through portals Real-Time Rendering 6 David Luebke
Cells & Portals Idea: Cells form the basic unit of PVS Create an adjacency graph of 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 So cell visibility reduces to testing portal sequences for a line of sight… Real-Time Rendering 7 David Luebke
Cells & Portals A D E F B C G H A E B C D F G H Real-Time Rendering 8 David Luebke
Cells & Portals A D E F B C G H A E B C D F G H Real-Time Rendering 9 David Luebke
Cells & Portals A D E F B C G H A E B C D F G H Real-Time Rendering 10 David Luebke
Cells & Portals A D E F B C G H A E B C D F G H Real-Time Rendering 11 David Luebke
Cells & Portals A D E F B C G H A E B C D F G H Real-Time Rendering 12 David Luebke
? Cells & Portals A D E F B C G H A E B C D F G H ? Real-Time Rendering 13 David Luebke
Cells & Portals A D H F C B E G X Real-Time Rendering 14 David Luebke
Cells & Portals View-independent solution: find all cells a particular cell could possibly see: C can only see A, D, E, and H A D H F C B E G A D E H Real-Time Rendering 15 David Luebke
Cells & Portals View-independent solution: find all cells a particular cell could possibly see: H will never see F A D H F C B E G A D E B C G Real-Time Rendering 16 David Luebke
Cells and Portals Questions: The key insight: How can we detect whether a given cell is visible from a given viewpoint? How can we detect view-independent visibility between cells? The key insight: These problems reduce to eye-portal and portal-portal visibility Real-Time Rendering 17 David Luebke
Recap: “Luebke/Georges” algorithm Depth-first adjacency graph traversal Render cell containing viewer Treat portals as special polygons If portal is visible, render adjacent cell But clip to boundaries of portal! Recursively check portals in that cell against new clip boundaries (and render) Each visible portal sequence amounts to a series of nested portal boundaries Kept implicitly on recursion stack Real-Time Rendering 18 David Luebke
Recap: “Luebke/Georges” algorithm Recursively rendering cells while clipping to portal boundaries is not new Visible-surface algorithm (Jones 1971): general polygon-polygon clipping Elegant, expensive, complicated Conservative overestimate (pfPortals): use portal’s cull box Cull box = x-y screenspace bounding box Cheap to compute, very cheap to intersect Real-Time Rendering 19 David Luebke
Recap: “Luebke/Georges” algorithm How badly does the cull box approximation overestimate PVS? A: Not much for most architectural scenes Note: Can implement mirrors as portals with an extra transformation! Some clipping & Z-buffering issues Must limit recursion Real-Time Rendering 20 David Luebke
Cells & Portals: Old Skool Show the video… Real-Time Rendering 21 David Luebke
Creating Cells and Portals Given a model, how might you extract the cells and portals? Airey: k-D tree (axis-aligned boxes) Teller: BSP tree (general convex cells) Luebke: modeler/level designer (arbitrary cells) Problems and issues Running time Free cells Intra-wall cells Real-Time Rendering 22 David Luebke
Cells and Portals: Discussion Good solution for most architectural models Use the simplest algorithm that suffices for your needs: pfPortals-style algorithm: lightweight view-dependent solution, reasonably tight PVS, no preprocess necessary (except partition) Teller-style algorithm: even tighter PVS, somewhat more complex, can provide view-independent solution for prefetching Real-Time Rendering 23 David Luebke
General Occlusion Culling Clearly cells and portals don’t work for all models… Trees in a forest A crowded train station Other specialized visibility algorithms exist From colonoscopy to cityscapes… Need general occlusion culling algorithms: Aggregate occlusion Dynamic scenes Non-polygonal scenes Real-Time Rendering 24 David Luebke
Image-Space Occlusion Culling Many general occlusion culling algorithms use an image-space approach Idea: solve visibility in 2D, on the image plane Real-Time Rendering 25 David Luebke
Hierarchical Z-Buffer Replace Z-buffer with a Z-pyramid Lowest level: full-resolution Z-buffer Higher levels: each pixel represents the max depth of the four pixels “underneath” it Basic idea: hierarchical rasterization of the polygon, with early termination where polygon is occluded Real-Time Rendering 26 David Luebke
Hierarchical Z-Buffer Idea: test polygon against highest level first If polygon is further than distance recorded in pixel, stop—it’s occluded If polygon is closer, recursively check against next lower level If polygon is visible at lowest level, set new distance value and propagate up Real-Time Rendering 27 David Luebke
Hierarchical Z-Buffer Z-pyramid exploits image-space coherence: Polygon occluded in a pixel is probably occluded in nearby pixels HZB also exploits object-space coherence Polygons near an occluded polygon are probably occluded Real-Time Rendering 28 David Luebke
Hierarchical Z-Buffer Exploiting object-space coherence: Subdivide scene with an octree All geometry in an octree node is contained by a cube Before rendering the contents of a node, “test render” the faces of its cube (i.e., query the Z-pyramid) If cube faces are occluded, ignore the entire node Real-Time Rendering 29 David Luebke
Hierarchical Z-Buffer HZB can exploit temporal coherence Most polygons affecting the Z-buffer last frame will affect Z-buffer this frame HZB also operates at max efficiency when Z-pyramid already built So start each frame by rendering octree nodes visible last frame Real-Time Rendering 30 David Luebke
Hierarchical Z-Buffer: Discussion HZB needs hardware support to be really competitive Hardware vendors haven’t entirely bought in: Z-pyramid (and hierarchies in general) a pain in hardware Unpredictable Z-query times generate bubbles in rendering pipe But we’re getting there… ATI HyperZ Similar technology in NVIDIA Both “under the hood”, not exposed to programmer At the user level, hardware now supports occlusion queries Real-Time Rendering 31 David Luebke
Modern Occlusion Culling Support from hardware would be nice Want an “occlusion test”: would this polygon be visible if I rendered it? How could you use such a test? Test portal polygons before rendering adjacent cell Test object bounding boxes before rendering object Yay! GL_HP_OCCLUSION_TEST extension Problems: CPU/GPU synchronization == bad Might want to know “how visible” is the polygon Real-Time Rendering 32 David Luebke
Modern Occlusion Culling GL_ARB_OCCLUSION_QUERY to the rescue Non-blocking query “Is this occlusion query done yet?” Multiple queries in flight Returns number of fragments visible Note: can actually render object or not Still lots of issues for efficient culling Real-Time Rendering 33 David Luebke
111 uses for Occlusion Queries Occlusion culling (duh) Others? Approximate culling LOD size estimation Lens flare effects Transparency Collision detection (!) Convergence testing Real-Time Rendering 34 David Luebke