Transcript ppt

Visibility III:
Occlusion Queries
CS 446: Real-Time Rendering
& Game Technology
David Luebke
University of Virginia
Demo Time: Paul Tschirhart
REMINDER: I’ve reorganized the next few demos
Feb 23: Erin Golub
Feb 28: Sean Arietta
Mar 2: Jiayuan Meng
If this is a problem, let me know!
Today: Project Offset
Real-Time Rendering
2
David
Assignment 3
• Olsson 002a: I feel your pain
– Working on fixing these problems, and on
communicating their urgency…
Real-Time Rendering
3
David
Recap: General Occlusion Culling
• Need general occlusion culling algorithms:
– Aggregate occlusion (trees in forest)
– Dynamic scenes (waving trees in forest; crowd scene)
• Many general occlusion culling algorithms use an
image-space approach
– Idea: solve visibility in 2D, on the image plane
Real-Time Rendering
4
David
Recap: 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
5
David
Recap: Hierarchical Z-Buffer
• Z-pyramid exploits image-space coherence:
– A polygon occluded at a pixel is probably occluded at nearby pixels
• HZB can also exploit object-space coherence
– Polygons near occluded polygon are probably occluded
– Idea: Z-query (hierarchical) bounding volumes before rendering
their contents
• HZB can also exploit temporal coherence
– Polygon visible last frame probably visible this frame
– Idea: start each frame by rendering what was visible last frame
Real-Time Rendering
6
David
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 tech now in NVIDIA
• Supports image-space coherence
• 8x8 one-level hierarchical z-buffer
• “Under the hood”, not exposed to programmer
– At the user level, hardware now supports occlusion queries
• Supports object-space coherence, temporal coherence
Real-Time Rendering
7
David
Modern Occlusion Culling
• Occlusion query posited in original HZP paper
– 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
8
David
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
• Allows object-space, temporal coherence
• Still lots of issues for efficient culling
Real-Time Rendering
9
David
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
10
David
Occlusion Culling Grab Bag
• Portal textures
– Dan Aliaga and others
• From-region visibility
– Generalizes view-independent cell-portal problem
• Special case: 2.5D from-region visibility
– Michael Wimmer and others
• Linear-time view-independent portal cull box approach?
– Nina Amenta and others
• Modeling issues for cells-and-portals
– Daniel Cohen-Or and others
Advanced Texturing
CS 446: Real-Time Rendering
& Game Technology
David Luebke
University of Virginia
Terminology
• A note on terminology:
– The following terms are used loosely in the literature
– Don’t take my definitions as canonical
Real-Time Rendering
13
David
Billboards
• A billboard is a textured polygon (usually a quad) that
rotates to face the viewer
– Build a rotation matrix for each billboard
– Screen-aligned billboard: quad is parallel to the screen and has
a constant up vector
• Similar to old-school 2D sprites
• Useful for text, HUDs, lens flare, etc
• Build rotation matrix with camera u, n = -v, r=uXv
– World-oriented billboard
• Sprite’s native up vector not always appropriate
• World-oriented billboard: use the world up vector
• Still faces viewer  n = -v, r=uXv
Billboards
• Viewpoint-aligned
– v = vector to eye (Fig. 8.5)
– Resulting quads capture perspective distortions across
view-frustum
– Ex: clouds (Fig 8.6)
• Axially-alligned
– Rotates around a fixed world-space axis
– Ex: trees (Fig 8.7)
– Problem: from above, look like cardboard cutouts
Real-Time Rendering
15
David
Point Sprites
• A point sprite is a screen-aligned textured square
(i.e., a billboard) placed by rendering a single vertex
– Ideal for particle systems
– When GL_POINT_SPRITE_NV is enabled:
• Point antialiasing state ignored – all points  quads
• Points are rendered with point width as usual
• Tex coords of points can be replaced by special “point sprite”
tex coords s,t,r between 0,1
– Tex coord r is special, can set to zero (default) or use to ‘play
back’ an animation stored in 3D tex (COORD_REPLACE_NV)
– See http://www.nvidia.com/dev_content/nvopenglspecs/GL_NV_point_sprite.txt
– See http://www.codesampler.com/oglsrc.htm; search for “point sprite”
Imposters
• Imposter : general term for texture that replaces geometry
– Billboards == imposters that rotate to face viewer
– Often used in the context of LOD
• A dynamic imposter is an imposter created on the fly to
“cache” rendered imagery
– Once rendered, cost of rendering an imposter is just a single
textured quad (note poor texture cache coherence though)
– Can use for a few frames before updating
– Can use for a few instances of the object
• Works best on distant objects (why?)
• Great example: portal textures
Imposters & “Depth Sprites”
• Can render an object with a depth texture, so depth
buffer affects/is affected by the rendering (Fig 8.16)
– Can also do depth-affected lighting
– Needs to be orthogonal or nearly orthogonal to look right
– Under the right circumstances, might allow combining
imposters with dynamic geometry
• Ex: portal texture with monster moving around the textured cell
Real-Time Rendering
18
David
Imposters Continued
• Sometimes “imposter” used to refer to what I’ll call
depth meshes
– UNC MMR system
– Imposters for urban environments
Real-Time Rendering
19
David
Imposters Continued
• Can represent an object as collection of imposters
– Common trick for trees, usually manually placed
– Billboard clouds apply this idea to other (all) objects
– The trick is to compute these automatically…
Real-Time Rendering
20
David
Multitexturing
• Modern hardware can read
from multiple textures at
once, even with mipmapping
– Light maps
– Detail texturing
– Decals
x
=
From UT2004 © Epic Games Inc
Textures: Other Important Stuff
• Render to texture – framebuffer objects (FBOs)
• Environment maps
– Sphere map, cube maps (hardware supported)
• Shadow maps
– Basically, a depth texture from light source point of view
– More later
• Relief textures
– Demo now, details later
Real-Time Rendering
22
David
Textures: Still More Stuff
• Normal maps – especially for bump mapping
– Gloss maps, reflectance maps, etc
• Generally:
– Think of textures as global memory for fragment programs, with
built-in filtering
– Just starting to be able to access
textures in vertex programs too
(NVIDIA hardware only, today)
• Deferred shading
• Projective texture mapping
Real-Time Rendering
23
David
Next topic: Cg
• Many of the tricks we discuss in this class do not
depend on programmable graphics hardware
• But, most are easier to implement this way!
• So, the next topic is a brief intro to Cg
– My apologies to those of you who’ve seen this
– My apologies to those of you who haven’t
Real-Time Rendering
24
David