Transcript 24

Visibility
CS 445/645
Introduction to Computer Graphics
David Luebke, Spring 2003
David Luebke
1
7/27/2016
Recap:
The Z-Buffer Algorithm
● Both BSP trees and Warnock’s algorithm were
proposed when memory was expensive
■ Example: first 512x512 framebuffer > $50,000!
● Ed Catmull (mid-70s) proposed a radical new
approach called z-buffering
■ (He went on to help found a little company named Pixar)
● The big idea: resolve visibility independently at each
pixel
David Luebke
2
7/27/2016
Recap:
The Z-Buffer Algorithm
● We know how to rasterize polygons into an image
discretized into pixels:
David Luebke
3
7/27/2016
Recap:
The Z-Buffer Algorithm
● What happens if multiple primitives occupy the same
pixel on the screen? Which is allowed to paint the
pixel?
David Luebke
4
7/27/2016
Recap:
The Z-Buffer Algorithm
● Idea: retain depth (Z in eye coordinates) through
projection transform
■ Recall canonical viewing volumes
■ Can transform canonical perspective volume into canonical
parallel volume with:
1
0
M 
0

0
David Luebke
0
0
1
0
1
0
1  zmin
0
1
5

0 
 zmin

1  zmin 
0 
0
7/27/2016
Recap:
The Z-Buffer Algorithm
● Augment framebuffer with Z-buffer or depth buffer
which stores Z value at each pixel
■ At frame beginning initialize all pixel depths to 
■ When rasterizing, interpolate depth (Z) across polygon and
store in pixel of Z-buffer
■ Suppress writing to a pixel if its Z value is more distant
than the Z value already stored there
○ “More distant”: greater than or less than, depending
David Luebke
6
7/27/2016
Recap:
Interpolating Z
● Edge equations: Z is just another planar parameter:
z = Ax + By + C
■ Look familiar?
■ Total cost:
○ 1 more parameter to
increment in inner loop
○ 3x3 matrix multiply for setup
■ See interpolating color
discussion from lecture 10
● Edge walking: can interpolate Z along edges and across
spans
David Luebke
7
7/27/2016
The Z-Buffer Algorithm
● To think about:
■ How much memory does the Z-buffer use?
■ Does the image rendered depend on the drawing order?
■ Does the time to render the image depend on the drawing
order?
■ How much of the pipeline do occluded polgyons traverse?
○ What does this imply for the front of the pipeline?
○ How does Z-buffer load scale with visible polygons? With
framebuffer resolution?
David Luebke
8
7/27/2016
Z-Buffer Pros
● Simple!!!
● Easy to implement in hardware
● Polygons can be processed in arbitrary order
● Easily handles polygon interpenetration
● Enables deferred shading
■ Rasterize shading parameters (e.g., surface normal) and
only shade final visible fragments
■ When does this help?
David Luebke
9
7/27/2016
Z-Buffer Cons
● Lots of memory (e.g. 1280x1024x32 bits)
● Read-Modify-Write in inner loop requires fast
memory
● Hard to do analytic antialiasing
● Hard to simulate translucent polygons
● Precision issues (scintillating, worse with perspective
projection)
David Luebke
10
7/27/2016
Visibility Culling
● The basic idea: don’t render what can’t be seen
■ Off-screen: view-frustum culling
■ Occluded by other objects: occlusion culling
David Luebke
11
7/27/2016
Motivation
● The obvious question: why bother?
■ Off-screen geometry:
solved by clipping
■ Occluded geometry:
solved by Z-buffer
● The (obvious) answer: efficiency
■ Clipping and Z-buffering take time linear to the number of
primitives
David Luebke
12
7/27/2016
The Goal
● 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 might be visible
○ Z-buffer& clip this for the exact solution
■ This conservative estimate is called the potentially visible
set or PVS
David Luebke
13
7/27/2016
Visibility Culling
● The remainder of this talk will cover:
■ View-frustum culling (briefly)
■ Occlusion culling in architectural environments
■ General occlusion culling
David Luebke
14
7/27/2016
View-Frustum Culling
● An old idea (Clark 76):
■ Organize primitives into clumps
■ Before rendering the primitives in a clump, test a bounding
volume against the view frustum
○ If the clump is entirely outside the view frustum, don’t render any
of the primitives
○ If the clump intersects the view frustum, add to PVS and render
normally
David Luebke
15
7/27/2016
Efficient
View-Frustum Culling
● How big should the clumps be?
■ Choose minimum size so:
cost testing bounding volume << cost clipping primitives
■ Organize clumps into a hierarchy of bounding volumes for
more efficient testing
○ If a clump is entirely outside or entirely inside view frustum, no
need to test its children
David Luebke
16
7/27/2016
Efficient
View-Frustum Culling
● What shape should the bounding volumes be?
■ Spheres and axis-aligned bounding boxes: simple to
calculate, cheap to test
■ Oriented bounding boxes converge asymptotically
faster in theory
■ Lots of other volumes have been proposed, but most
people still use spheres or AABBs.
David Luebke
17
7/27/2016
Cells & Portals
● Goal: walk through 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
David Luebke
18
7/27/2016
Cells & Portals
● An example:
David Luebke
19
7/27/2016
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…
David Luebke
20
7/27/2016
Cells & Portals
E
A
D
B
F
C
G
H
A
B
E
C
D
F
G
H
David Luebke
21
7/27/2016
Cells & Portals
E
A
D
B
F
C
G
H
A
B
E
C
D
F
G
H
David Luebke
22
7/27/2016
Cells & Portals
E
A
D
B
F
C
G
H
A
B
E
C
D
F
G
H
David Luebke
23
7/27/2016
Cells & Portals
E
A
D
B
F
C
G
H
A
B
E
C
D
F
G
H
David Luebke
24
7/27/2016
Cells & Portals
E
A
D
B
F
C
G
H
A
B
E
C
D
F
G
H
David Luebke
25
7/27/2016
Cells & Portals
E
A
D
B
C
?
F
G
H
A
B
E
C
D
F
G
?
H
David Luebke
26
7/27/2016
Cells & Portals
E
A
D
B
C
X
F
G
H
A
B
David Luebke
E
C
D
X
H
27
F
G
7/27/2016
Cells & Portals
● View-independent solution: find all cells a particular cell could
possibly see:
E
A
D
B
F
C
G
H
C can only see A, D, E, and H
David Luebke
28
7/27/2016
Cells & Portals
● View-independent solution: find all cells a particular cell could
possibly see:
E
A
D
B
F
C
G
H
H will never see F
David Luebke
29
7/27/2016
Cells and Portals
● Questions:
■ 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
David Luebke
30
7/27/2016
Cells and Portals
● Airey (1990): view-independent only
■ Portal-portal visibility determined by ray-casting
○ Non-conservative portal-portal test resulted in occasional errors in
PVS
■ Slow preprocess
■ Order-of-magnitude speedups
David Luebke
31
7/27/2016