View
215
Download
0
Tags:
Embed Size (px)
Citation preview
Tomas Mőller © 2000
Speed-up Techniques forSpeed-up Techniques forReal-Time RenderingReal-Time Rendering
or “What makes your real-time video game fly”or “What makes your real-time video game fly”
Tomas MöllerTomas MöllerChalmers University of Technology, SwedenChalmers University of Technology, Sweden
Speed-up Techniques forSpeed-up Techniques forReal-Time RenderingReal-Time Rendering
or “What makes your real-time video game fly”or “What makes your real-time video game fly”
Tomas MöllerTomas MöllerChalmers University of Technology, SwedenChalmers University of Technology, Sweden
Tomas Mőller © 2000
MotivationMotivation
Graphics hardware 2x faster in 6 months!Wait… then it will be fast enough!NOT!We will never be satisfied
– Screen resolution: 2000x1000– Realism: global illumination– Geometrical complexity: no upper limit!
Tomas Mőller © 2000
Keep this in mind during lecture…Keep this in mind during lecture…
Rendering pipeline: 3 stages– Application (CPU but also bandwidth from CPU
to graphics hardware)– Geometry (transform, lighting)– Rasterizer (fill, texture, per pixel ops)
To get faster overall performance:– Reduce time spent in bottleneck stage!
Tomas Mőller © 2000
Overview of lectureOverview of lecture
The scene graphCulling techniquesLevel-of-detail rendering (LODs)Combination of techniquesCollision detectionResources and pointers
Tomas Mőller © 2000
The Scene GraphThe Scene Graph DAG – directed acyclic graph
– Simply an n-ary tree without loops Uses: collision detection and faster rendering
internal node=
Tomas Mőller © 2000
Contents of Scene GraphContents of Scene Graph
Leaves contains geometryEach node holds a
– Bounding Volume (BV) – pointers to children– possibly a transform
Examples of BVs: spheres, boxes The BV in a node contains all geometry
in its subtree
Tomas Mőller © 2000
Scene graph exampleScene graph example
circles=BVsscene graph
root
Tomas Mőller © 2000
Transforms in the Scene GraphTransforms in the Scene Graph Put a transform in each internal node Gives instancing, and hierarchical animation
Move right,Rotate 45°
Move up
Tomas Mőller © 2000
Example: a running legExample: a running legA B CNo hierarchy:
one transform
21 3Hierarchy:3 transforms
Leg
Xform
Xform
Xform
Knee
Foot
Hip
Xform
Tomas Mőller © 2000
Culling TechniquesCulling Techniques
“To cull” means “to select from group” In graphics context: do not process data
that will not contribute to the final imageThe “group” is the entire scene, and the
selection is a subset of the scene that we do not consider to contribute
Tomas Mőller © 2000
Culling: OverviewCulling: Overview
Backface cullingHierarchical view-frustum cullingPortal cullingDetail cullingOcclusion culling
Tomas Mőller © 2000
Culling examplesCulling examples
view frustum detail
backface
portal occlusion
Tomas Mőller © 2000
Backface CullingBackface Culling
Simple technique to discard polygons that faces away from the viewer
Can be used for: – closed surface (example: sphere)– or whenever we know that the backfaces never
should be seen (example: walls in a room)
Two methods (screen space, eye space)Which stages benefits? Rasterizer, but
also Geometry (where test is done)
Tomas Mőller © 2000
Backface culling (cont’d)Backface culling (cont’d)
Often implemented for you in the APIOpenGL: glCullFace(GL_BACK);How to determine what faces away?First, must have consistently oriented
polygons, e.g., counterclockwise
0
1
2
front facing0
1
2
back facing
Tomas Mőller © 2000
How to cull backfacesHow to cull backfaces
screen space
1
0
2
front
01
2
back
front
backeye
eye space
Tomas Mőller © 2000
View-Frustum CullingView-Frustum Culling
Bound every “natural” group of primitives by a simple volume (e.g., sphere, box)
If a bounding volume (BV) is outside the view frustum, then the entire contents of that BV is also outside (not visible)
Avoid further processing of such BV’s and their containing geometry
Tomas Mőller © 2000
Can we accelerate VF culling Can we accelerate VF culling further?further?
Do what we always do in graphics…Use a hierarchical approach, e.g,
the scene graphWhich stages benefits?
– Geometry and Rasterizer – Bus between CPU and Geometry
Tomas Mőller © 2000
Example of Hierarchical View Example of Hierarchical View Frustum CullingFrustum Culling
root
camera
Tomas Mőller © 2000
Portal CullingPortal CullingImages courtesy of David P. Luebke and Chris Georges
Average: culled 20-50% of the polys in view Speedup: from slightly better to 10 times
Tomas Mőller © 2000
Portal culling examplePortal culling example In a building from above Circles are objects to be rendered
Tomas Mőller © 2000
Portal Culling AlgorithmPortal Culling Algorithm
Divide into cells with portals (build graph)For each frame:
– Locate cell of viewer and init 2D AABB to whole screen
– * Render current cell with VF cull w.r.t. AABB– Traverse to closest cells (through portals)– Intersection of AABB & AABB of traversed portal– Goto *
Tomas Mőller © 2000
Portal overestimationPortal overestimation
To simplify:
actual portal overestimated portal
Tomas Mőller © 2000
Portal Culling AlgorithmPortal Culling Algorithm
When to exit:– When the current AABB is empty– When we do not have enough time to render a
cell (“far away” from the viewer)
Also: mark rendered objectsWhich stages benefits?
– Geometry, Rasterizer, and Bus
Source (for Performer): http://www.cs.virginia.edu/~luebke/
Tomas Mőller © 2000
Detail CullingDetail Culling
Idea: objects whose projected BV occupy less than N pixels are culled
This is an approximative algorithm as the things you cull away may actually contribute to the final image
Advantage: trade-off quality/speedWhich stages benefits?
– Geometry, Rasterizer, and Bus
Tomas Mőller © 2000
Example of Detail CullingExample of Detail Culling
detail culling OFFNot much difference, but 80-400% fasterGood when moving
detail culling ON
Images courtesy of ABB Robotics Products, created by Ulf Assarsson
Tomas Mőller © 2000
ProjectionProjection
Projection gets halved when distance is doubled
eye
Tomas Mőller © 2000
Projection (cont’d)Projection (cont’d)
dot(d, (c-v)) is distance along d p=nr/dot(d, (c-v)) is estimation of projected
radius p2 is the area
(eye) v
(near plane) n
d (normalized view direction)
r
c
Tomas Mőller © 2000
Occlusion CullingOcclusion Culling
Main idea: Objects that lies completely “behind” another set of objects can be culled
Hard problem to solve efficiently
Tomas Mőller © 2000
ExampleExample
final image
Note that “Portal Culling” is an algorithm for occlusion culling
Tomas Mőller © 2000
Occlusion culling algorithmOcclusion culling algorithm
Use some kind of occlusion
representation OR
for each object g do:
if( not Occluded(OR ,g)) render(g);
update(OR ,g); end;end;
Tomas Mőller © 2000
Occlusion culling algorithm Occlusion culling algorithm exampleexample
Process from front to back Maintain an occlusion horizon (yellow)
Tomas Mőller © 2000
Occlusion culling algorithm Occlusion culling algorithm exampleexample
To process tetrahedron (which is behind grey objects):– find axis-aligned box of projection– compare against occlusion horizon
culled
Tomas Mőller © 2000
Occlusion culling algorithm Occlusion culling algorithm exampleexampleWhen an object is considered visible:Add its “occluding power” to the
occlusion representation
Tomas Mőller © 2000
Level-of-Detail RenderingLevel-of-Detail Rendering Use different levels of detail at different
distances from the viewer More triangles closer to the viewer
Tomas Mőller © 2000
LOD renderingLOD rendering Not much visual difference, but a lot faster
Use area of projection of BV to select appropriate LOD
Tomas Mőller © 2000
Scene graph with LODsScene graph with LODs
Car chair
Tomas Mőller © 2000
Far LOD renderingFar LOD rendering
When the object is far away, replace with a quad of some color
When the object is really far away, do not render it (detail culling)!
Which stages benefits? – Geometry, Rasterizer, and Bus
Tomas Mőller © 2000
Combinations of TechniquesCombinations of Techniques
Not trivial to combine!VF Cull + LOD == minimal if serious
about performance Indoors: LOD + portal cullingOutdoors (cities, suburbia): VF Cull +
LOD + occlusion culling
Tomas Mőller © 2000
Real-Time Rendering?Real-Time Rendering? In computer graphics, “real-time” is used
in a soft way: say >30 fps for most frames
In other contexts, it’s a tougher requirement: the framerate must never be <30 fps, i.e., constant framerate
What can we do?– Reactive LOD algorithm– Reactive detail culling– Reactive visual quality
Tomas Mőller © 2000
Collision DetectionCollision Detection
To get interesting and more realistic interaction between geometric objects in an application
Cannot test each triangle against each other: O(n*m)
Alas, need smarter approachesUse BVs because these are cheap to testUse a scene graph (hiearchy)
– For efficiency use only one triangle per leaf
Tomas Mőller © 2000
How to collide two scene graphs?How to collide two scene graphs? Three cases: Reach two internal nodes’ BVs
– If not overlap, then exit– If overlap, then descend into the children of the internal
node with largest volume
Reach an internal node and a triangle– Descend into the internal node
If you reach two triangles– Test for overlap
Start recursion with the two roots of the scene graphs
Tomas Mőller © 2000
Bounding Volumes in Collision Bounding Volumes in Collision DetectionDetection
Wanted: tight fitting BV, and fast to test for overlap
Common choices are– Spheres– Axis aligned box– Oriented box
Tomas Mőller © 2000
Triangle-triangle overlap testTriangle-triangle overlap test
Compute the line of intersection between the two planes
Compute the intersection interval between this line and triangles – gives two intervals
If intervals overlap then triangles overlap!
Tomas Mőller © 2000
Simpler collision detectionSimpler collision detection Only shoot rays to find collisions, i.e.,
approximate an object with a set of rays Cheaper, but less accurate Can use the scene graph again or a BSP tree
Tomas Mőller © 2000
Can you compute the time of a Can you compute the time of a collision?collision?
Move ball, test for hit, move ball, test for hit… can get “quantum effects”!
In some cases it’s possible to find closed-form expression: t=s/v
v
s
Tomas Mőller © 2000
Collision detection resourcesCollision detection resources
Check out www.realtimerendering.comRAPID: uses OBBsSOLID: handles deformable objectsEberly: code for dynamic CD
– where no quantum effects can occur– Each object has a velocity direction
Tomas Mőller © 2000
Resources and PointersResources and Pointers
http://www.realtimerendering.comJournal of Graphics Tools
– http://www.acm.org/jgt/– source for projected screen area of box– intersection test routines– occlusion culling
http://www.magic-software.com