0% found this document useful (0 votes)
11 views80 pages

7280 Lecture5 Visibilityprocessing

The document discusses principles of computer game software production, focusing on rendering techniques such as visibility processing, clipping, and culling. It covers various data structures like Octrees, BSP trees, and Quadtrees used for efficient rendering in indoor and outdoor environments, as well as hybrid approaches and hardware-assisted occlusion tests. Additionally, it addresses challenges in rendering complex environments and the importance of level of detail in terrain rendering.

Uploaded by

rkrams1989
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views80 pages

7280 Lecture5 Visibilityprocessing

The document discusses principles of computer game software production, focusing on rendering techniques such as visibility processing, clipping, and culling. It covers various data structures like Octrees, BSP trees, and Quadtrees used for efficient rendering in indoor and outdoor environments, as well as hybrid approaches and hardware-assisted occlusion tests. Additionally, it addresses challenges in rendering complex environments and the importance of level of detail in terrain rendering.

Uploaded by

rkrams1989
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 80

Principle of Computer Game

Software
Visibility Processing

CSC7280 Computer Game Software Production


Outline
• Visible surface determination
• Indoor consideration
• Outdoor consideration

CSC7280 Computer Game Software Production


Rendering
• Clipping : Camera with 90 will clip
0

around three quarters of the global


geometry
• Culling: ½ geometry is back facing,
culled away
Backface polygon
not rendered

Not rendered

900 FOV
CSC7280 Computer Game Software Production
Rendering
• The surviving 1/8
geometry will be
rendered i.e. within
the viewing frustum.
• We still want to
render only those
visible polygons i.e.
those camera can
see Still have to render all the walls here

CSC7280 Computer Game Software Production


Indoor rendering
• Clipping & culling A camera
can now mostly facing a wall
performed by
hardware
• Indoor rendering
would be faster if
occlusion culling can Need not render
be performed by those polygons
taking advantage of behind the wall
walls which are
occluders
CSC7280 Computer Game Software Production
Idea of Occlusion Test
• O(num_triangles2) if simply testing each triangle
against all the others
for i=1 to N polygon
for j=1 to N polygon
check if polygon(j) is
occluded by polygon(i)
• Can be further reduced by partitioning the set into
potential occluder and occluded triangle
• Viewing distance can be used to further reject the
outlier

CSC7280 Computer Game Software Production


Indoor rendering
• Most games take place inside building
• Use spatial subdivision hierarchies to help
answer this question:
if the viewing frustum intersect with an
object/mesh/polygon?
• Popular approaches:
1. Octree
2. Binary Space Partitioning(BSP) with potential
visibility set(PVS)
3. Portal

CSC7280 Computer Game Software Production


Octree
• Divide the space into 8
sub-regions
• Each node representing
a region will thus have 8
children
• Any sub-node can thus
be decomposed further,
which depends on
some measures e.g. no.
of polygons

CSC7280 Computer Game Software Production


Octree

CSC7280 Computer Game Software Production


Octree
• Easy to code –
using recursion
• Quickly reject lots of
polygons (colored
on right)
• Useful in collision
detection and
shadow as well An octree from the top and a
viewing frustrum

CSC7280 Computer Game Software Production


Quadtree
• Single layer version of Octree
• Having 4 child nodes for every parent
node
• Concept similar to Octree
• Suitable for terrain rendering

CSC7280 Computer Game Software Production


Binary Space Partitioning
• Used in most modern 3D engines
• Advantage – view point independent
polygon ordering
• 2 phases:
1. Tree generation (next slide)
2. Tree traversal - given viewpoint, will
return the list of triangles ordered by Z-
value by tree traversal i.e. back-to-front
CSC7280 Computer Game Software Production
BSP Tree Generation
1. Select a partition hyperplane.
2. Partition all polygons with the initial
hyperplane, storing them in either the
front or back polygon list.
3. Recurs through the front and back
polygon list, creating a new tree node
and attaching it to the left or right leaf of
the parent node.
CSC7280 Computer Game Software Production
BSP Tree example
• Given

normal

Add a
Polygon 3
Splitting of polygon
CSC7280 Computer Game Software Production
BSP tree example
Add
Polygon 4

Add
Polygon 5

CSC7280 Computer Game Software Production


BSP tree
• Choice of partitioning plane is critical in :
1. Balance of tree
2. Doubling up of polygons in case of any split
• Set up cost functions as below
• Determine the best plane in each
partitioning during compilation phase

score( p) = abs( front _ faces − back _ faces) + f (no _ of _ splits )


e.g. f(no_of_splits) = no_of_splits * 8
CSC7280 Computer Game Software Production
Balance of tree
• If the choice of
partition plane on
right is 0,1,2,3 the
BSP tree created
will be
unbalanced.

CSC7280 Computer Game Software Production


BSP tree Rendering
Result=Classify(CameraPosition,CurrentNode->Polygon);
if (Result==Front) {
if (CurrentNode->BackChild!=NULL)
RenderBSP (CurrentNode->BackChild);
DrawPolygon(CurrentNode->Polygon);
if (CurrentNode->FrontChild!=NULL)
RenderBSP (CurrentNode->FrontChild);
Back to front
}
rendering
else {
if (CurrentNode->FrontChild!=NULL)
RenderBSP (CurrentNode->FrontChild);
DrawPolygon(CurrentNode->Polygon);
if (CurrentNode->BackChild!=NULL)
RenderBSP (CurrentNode->BackChild);
} CSC7280 Computer Game Software Production
Advantage of BSP
• Can emanate polygons in Z-sort order
in linear time
• Rendering back to front is useful in 80’s
when not all display card has hardware
Z-buffer
• With little change, can render in front to
back

CSC7280 Computer Game Software Production


Operation of accelerator card
1. Test pixel’s Z-value
2. If not affecting Z-buffer, skip this pixel
3. If does,
• Texture map the pixel
Lots of • Interpolating color
efforts • Light the pixel
• Paint the resultant color & update Z-
buffer
CSC7280 Computer Game Software Production
BSP in rendering
• If renders from back to front, many Z-
overlapping polygons will be rendered,
resulting in performance hit(overdraw)
• Thus better to use front to back for
better performance (with Z-buffer)

CSC7280 Computer Game Software Production


Solid Leafy BSP Tree
• A solid BSP tree can provide additional
information of solid space for use in
collision detection B
solid
A C A

solid solid solid


B D F
F C
solid solid solid
D e2 e1
solid
solid solid empty
e1 E e2
empty
solid
CSC7280 Computer Game Software Production
Solid Leafy BSP Tree
• A leaf in the tree contains the polygons
forming the convex hull of an empty space
• Polygons inside each cell may be rendered
in any order with back face culling
solid
A
B
B
solid

F C C,D,e2
solid B,A,
F,e1
D solid
e1 E e2
CSC7280 Computer Game Software Production
solid
Solid Leafy BSP Tree
• Combining the two to have all the
advantages
B

C A
solid solid solid
A D F

solid solid solid


B e2 e1
C Use in collision
F
solid detection solid solid
B,A,
D
C,D,e2 F,e1
solid
e1 E e2
Use in PVS(later)
solid
CSC7280 Computer Game Software Production
Problems of BSP
• Indoor environment – high complexity and
high occlusion =>
• BSP did not cope well with complex interior
models – single BSP tree for many rooms
results in many polygons drawn without
being seen on screen (overdraw)
• Seek ways to prune away unseen polygons

CSC7280 Computer Game Software Production


Potential Visibility Set(PVS)
• An array that store for each leaf the visibility
information of all other leafs from that leaf
e.g. assume 128 leaves level, if PVS[8] of
leaf 100 equals to 1, then cell 8 is visible to
cell 100.
• Unseen polygons can then be skipped
before any processing need be done by
looking up the PVS
• Much overdraw can then be avoided
CSC7280 Computer Game Software Production
Rendering with Solid leaf PVS
• For a given camera position
Traverse the BSP tree to find which leaf the
camera in
Loop through that leaf’s PVS data
Render leaf that is visible from within the
current leaf i.e. PVS[] is 1, with Z-buffer on
(no depth sort information needed)

CSC7280 Computer Game Software Production


Portal stabbing(PVS calculation)
• The gates/portal(different from portal
rendering) between leafs are checked against
visibility
• A stab tree is created for each leaf
• Cell to cell visibility is determined by depth
first search (DFS) on the tree

• Ref:
graphics.lcs.mit.edu/~seth/talks/siggraph91.p
df
CSC7280 Computer Game Software Production
Portal Stabbing
Stab tree
• Tree node = leaf cell
• Tree edge = stabbed
portal
Top view of level

CSC7280 Computer Game Software Production


Portal Rendering
• Advantage: need not pre-compute
visibility
• Level is designed with connected rooms
• Each room is connecting to the other
through a portal
• Each room should store with its
bounding volume

CSC7280 Computer Game Software Production


Portal
cull boxes for portals Overhead view, showing
(white) and mirrors portal culling frustums active
(red).

CSC7280 Computer Game Software Production


Portal Rendering
• Pseudo code:

detect which room is now in


render the room
locate any portals
for each portal
clip geometry through the portal & render
recurse through any portals in this room

CSC7280 Computer Game Software Production


Portal intersect(portal p1, portal p2)
list<points> result; C++ STL
bool previnside=false;
if p2.contains(p1.vertices[p1.numvertices-1]) previnside=true;
for (I=0; I<p1.numvertices; I++)
curinside = p2.contains(p1.vertices[I]);
if (curinside)
result.push_back(p1.vertices[I]);
if ((previnside && !curinside) || (!previnside && curinside))
int aux=I-1;
if (aux<0) aux+=p1.numvertices;
point inter = compute_intersection(p1.vertices[aux], p1.vertices[I], p2);
result.push_back(inter);
previnside = curinside;
portal presult(result);
return presult;
CSC7280 Computer Game Software Production
Optical Effects using Portal
• Reflections & translucency easily implemented

switch (portal_type)
case REGULAR:
paint destination room;
case REFLECTIVE:
calculate virtual camera using support plane of portal
Invert viewing matrices
Paint destination room
Paint portal using alpha blending
case TRANSLUCENCY:
Paint destination room
Paint portal using alpha blend
CSC7280 Computer Game Software Production
Hybrid Approaches
• BSP require static scene geometry in
general
• Portal techniques has problem in
handling room with huge number of
triangles
• Can combine octree with portal : portal
connecting room walls only, with interior
content in octree
CSC7280 Computer Game Software Production
Hybrid Approaches
• Quadtree-BSP useful in large areas to
be explored
• BSP break a level down to triangle level,
resulting in large tree & long traversal
• Quadtree detect quickly where we are
• BSP refine the location details to help in
collision detection

CSC7280 Computer Game Software Production


Hardware Assisted Occlusion
Tests
• New generations cards support hardware
occlusion test
• Sending the bounding box to the hardware to
check whether update in Z-buffer results
For each object
activate occlusion query
send bounding box
deactivate occlusion query
if pixels were modified
render object
CSC7280 Computer Game Software Production
Hardware Assisted Occlusion
Tests
• speed up using front to back testing
• Further speed up by hierarchical culling(Quadtree)

Sort the four nodes by distance to viewer


for each node
if subnode is not empty
if subnode is not clipped
activate occlusion query
paint bounding box
deactivate occlusion query
if pixels were modified
paint object
CSC7280 Computer Game Software Production
Outdoor rendering
• Talking about large
viewing distance
• Clipping & culling still
be used
• Few occluders in
outdoor scene
• Level of details is the
key to efficient
rendering
CSC7280 Computer Game Software Production
Terrain Rendering
• A smooth switching from low resolution
to high is expected for exploring in
these area
• Large data set is also expected
• Triangle budget i.e. a fixed number of
triangles, will be assumed for each
frame

CSC7280 Computer Game Software Production


Data Structures
• Mostly represented in height field i.e. 2D
array of heights e.g. 256x256 bitmap
with 8 bit color representing 1x1 km of
512 m max height have scale (4,4,2)
• Can convert easily to quadtree
• Grids are also suitable for triangle strips
& indexed primitives rendering

CSC7280 Computer Game Software Production


Example
10 8 8 8 10
8 10 10 10 8
8 10 16 10 8 20
8 10 10 10 8
10 8 8 8 10 15

10 S5

A typical heightmap 5

0
S4

S3
1 S2
2
3
4
S1
5

CSC7280 Computer Game Software Production


Grid structure
• Disadvantage:
– hole structure e.g. arch is not possible with
this representation alone
– Not well suited for LOD modeling
• Call for second level of derived data
structures

CSC7280 Computer Game Software Production


Quadtrees
• 4-ary trees that subdivide each node
into four subnodes
Level N Level N+1

CSC7280 Computer Game Software Production


Quadtrees
• Can be adaptive that expand nodes
only when more details is found
• Metric of details can be the variance
between real data and a quad at this
place
N
σ = ∑ (x − x)2
2 1
N i =1 i
quad
• Larger variance imply more detail
CSC7280 Computer Game Software Production
Quadtrees
• during runtime
– Renderer select the maximum depth (of
quadtree) based on distance to player and
the detail in the mesh
– Select coarser representation for distant
elements & maximum detail for nearby
objects

CSC7280 Computer Game Software Production


StarSeige Tribes 2
• Used by Star Seige
Tribes 1 & 2 to
produce outdoor
landscapes

CSC7280 Computer Game Software Production


Binary Triangle Trees(BTT)
• Adaptive structure that grows where more
details are present
• Different in that triangles used instead of
quads – divided into two new triangles

CSC7280 Computer Game Software Production


Geomipmapping
• Mipmapping : texture mapping
technique aimed at improving visual
quality of distant textured primitives
• Texture mipmap
– Pre-computing a series of scaled-down
texture maps - mipmaps 1(, 1 .. of
original size ) 2 4
– Selecting appropriate mipmap texture by
distance to viewer

CSC7280 Computer Game Software Production


Geomipmapping
• Geomipmaps – mipmaps on terrain
geometry
• Same concept with seams handling needed
• Terrain size must be a power of 2
• A terrain block contains 4x4 mesh

Terrain block
(32 triangles total, 5x5 vertices)
CSC7280 Computer Game Software Production
Geomipmapping
• each node contains its bounding box
• 4 descendants => 4 subquadrants
• Until a node contains exactly a terrain
block
• depth traverse the tree & perform
hierarchical clipping
• Distant triangles must still be rendered!

CSC7280 Computer Game Software Production


Geomipmapping
• When reach the leaves, decide which
geo-mipmap level to render
• Metric: quantity of detail & distance to
viewer
• Two issues:
1. Gaps between two blocks with different
resolution
2. Change in details easily perceived
CSC7280 Computer Game Software Production
Seamless gap between blocks
with different resolution
• Alter the connectivity of higher detail mesh

CSC7280 Computer Game Software Production


Sudden Pops(change in resolution)
• Geomorphing – transition by linear
interpolation
• Start with high detail mesh with vertices
aligned with plane of low resolution
• Change a low-res mesh by high-res with Y
the same
• Interpolated Y shift to final position as
camera approaches

CSC7280 Computer Game Software Production


ROAM
• Two pass CPU-centric algorithm that
allows fast terrain rendering
• Pass 1
– Terrain data scanned into a bintree & view
independent error metric computed
• Pass 2
– Construct a second bintree which performs
actual mesh construction & rendering
CSC7280 Computer Game Software Production
• Typical patch of terrain. From left to right,
wireframe (overhead view), Lit, and Textured

CSC7280 Computer Game Software Production


ROAM(Pass 1)
• Metric for details: variance

Interpolated value
N
σ 2 = ∑ (x − x)2
1
variance
N i =1 i
Heightmap value

• For non-leaf node, the variance is the


maximal variance of descendants

CSC7280 Computer Game Software Production


ROAM(Pass 1)
• Each base node correspond to a single
pixel in height map
• Use binary tree to represents the nested
behavior of variances
• The tree mapped to static array for fast
access

CSC7280 Computer Game Software Production


ROAM(Pass 2)
• Mesh building (BTT)
– Use view independent error metric
(variance) coupled with a view dependent
component(distance to viewer) to form a
metric
– Recurse until error level of the node
examined is lower than a threshold

CSC7280 Computer Game Software Production


Terrain displayed at Low, Optimal and
High variance settings

CSC7280 Computer Game Software Production


ROAM(Pass 2)
• Node splitting to avoid
cracks
– If part of a diamond, split
node & base neighbor
– If at the edge of a mesh,
split as needed
– If not part of a diamond,
force-split the base
neighbor before splitting
current node

CSC7280 Computer Game Software Production


ROAM(split only)
T= base triangulation
While T is too inaccurate
identify highest priority node from T (node with
biggest error)
force-split using the rules
update queue:
remove node that just been split
add the new nodes from split

CSC7280 Computer Game Software Production


camera looking to right

CSC7280 Computer Game Software Production


Chunked LODs
• Real time display of massive terrain
data set
• Build quadtree with root node contains
very low res. mesh
• Leaf node contains chunks that cover a
very small area
• Can build the tree bottom up

CSC7280 Computer Game Software Production


Chunked LODs
• Store measure of error w.r.t real data
set in each node
• Screen space error is computed as
delta
Rho = k
D D:distance to viewer
• K given by
viewportwidth
K=
horizontalFOV
2 * tan( )
2
CSC7280 Computer Game Software Production
Rendering
• Quadtree traversed & hierarchical
clipping performed
• At each node, choose between
expanding or using current data
• Pops solved by geo-morphing
• Cracks removed by sowing vertical
ribbons joining together the two meshes

CSC7280 Computer Game Software Production


Sowing Ribbons
• Insert triangle to fill
the crack
• Disadvantages:
1. Need to know the
exact geometry of
area around the crack
2. Involve significant
CPU power to
compute vertex
position of ribbon
crack
CSC7280 Computer Game Software Production
Chunked LOD

CSC7280 Computer Game Software Production


GPU-centric approach
• Store terrain geometry directly on GPU
• Quadtree – its leaf nodes are terrain
blocks, being stored in main memory
• Average normals for each terrain block
computed
• The dot product of this normal with view
vector determine whether the block
render or not

CSC7280 Computer Game Software Production


GPU centric approach
• PVS pre-computed using bounding
column(BC)
• BC contains the terrain block but extends to –
ve ∞

• Cast rays at top of BC towards surrounding


cells, detect reached or intersected

CSC7280 Computer Game Software Production


GPU centric approach
• PVS precomputed

Using the quadtree, find the block the player on


For each block in its PVS
if it can’t be culled via clustered culling
paint the block

CSC7280 Computer Game Software Production


ROAM 2.0(in progress)
• Use diamonds instead of triangles
• Take advantage of AGP chunking

Splitting of
Triangle 1
diamonds
Triangle 2

CSC7280 Computer Game Software Production


ROAM 2.0(1.56 million tris)

CSC7280 Computer Game Software Production


Poll in gamedev.net

CSC7280 Computer Game Software Production


Outdoor Scene Graphs
• Outdoor scenarios – cities, forests ..
• Huge loading on renderer
• To render these details
– Use instance based engines
– LOD analysis
– Fast routine to discard an object

CSC7280 Computer Game Software Production


Outdoor Scene Graphs
• Set up primitive list holding fundamental
building blocks, similar to sprite list in 2D side
scroller
• Each object with LOD support
• Spatial indexing to provide which objects
within frustum :
• Regular grid with bucket holding lists of
objects <primitiveid, position>
• Can help collision detection as well
CSC7280 Computer Game Software Production
Summary
• Clipping, culling and occlusion handling
is vital in indoor scene rendering
• Hardware assisted culling will also
affect the techniques chosen
• Many problem remains, e.g. lighting,
movable geometry, destructible
geometry etc all calls for more
innovative techniques
CSC7280 Computer Game Software Production
Summary
• Outdoor – focus on details handling
• Current research focus on occlusion
detection
• Front-to-back terrain render follow by
other objects render is quick and easy
solution
• But more elegant solution needed

CSC7280 Computer Game Software Production


Further reading
• Textbook - Ch.13, 14
• 3D Games - Realtime Rendering and
Software Technology Volume 1 - Ch.4 & 9
• BSP FAQ
http://www.gamedev.net/reference/articles/arti
cle657.asp
• Discussion of a number of related techniques
& links
http://www.cyberloonies.com/enginecoding.ht
ml
CSC7280 Computer Game Software Production
END

CSC7280 Computer Game Software Production

You might also like