Efficient Map, Road, Terrain, Text and POI Rendering on ... · 2D Performance Improvement in fps...
Transcript of Efficient Map, Road, Terrain, Text and POI Rendering on ... · 2D Performance Improvement in fps...
© 2008 NVIDIA Corporation.
Tom McReynolds, NVIDIA
Efficient Map, Road, Terrain, Text and POI Rendering on OpenGL-ES
© 2008 NVIDIA Corporation.
• Embedded platform: weak CPU with small cache, slow bus
• Need consistent latency, must be smooth all the time
• Similar to Vis-Sim apps• Constant frame rate, similar techniques• But lots of annotations: text, icons,
landmarks, etc.
• Different “graphics culture”
Mapping is Different
© 2008 NVIDIA Corporation.
• Scrolling landscape• Terrain geometry, land use and roads
• Terrain and roads have level-of-detail control
• Multiple icons/text/landscape features• Must be clear and uncluttered
• Scene realism features• Sky/fog, lighting, bump mapping
Mapping Elements
© 2008 NVIDIA Corporation.
Rendering Architecture
TerrainTiles
MapTiles
MapDBase
TerrainDBase
On Disk SystemMemory
Textures+
VBOs
VBOs
VideoMemory
© 2008 NVIDIA Corporation.
• Use good graphics programming practice
• Performance tune application• Solve mapping problems
• Use “tricky” OpenGL-ES techniques• Stay within application constraints
Strategy
© 2008 NVIDIA Corporation.
• VBOs vs. vertex arrays• Optimize rendering thread
• Start rendering early in the frame• Maximize pipelining; keep input fifo full
• State sorting• Minimize state changes
• Primitive grouping• Combine primitives where possible, re-
use verts, textures
Good OpenGL-ES Practice
© 2008 NVIDIA Corporation.
• Benchmark to find bottlenecks, don’t assume you know!• Look for performance that varies as well
• Look for latency as well as bandwidth problems• Can wait for bus, disk, context switch,
etc.• Having some kernel and user tracing
tools essential
Performance Tuning
© 2008 NVIDIA Corporation.
Extensive Benchmarking2D Performance Improvement in fps
10.045
7.02
3.84
7.21 7.458.725
11.65
15.79
12.785
8.86
5.285
14.985
26.31
10.7657692310.965
7.68
4.04
7.555 7.7459.15
12.145
18.76
13.995
9.24
5.43
17.31
29.275
11.7915384610.395
7.685
4.765
12.0711.025
12.375
22.285
7.265
36.68
19
7.905
29.425
45.46
17.41038462
14.775
8.69
5.46
11.78513.425
15.73
22.82
37.34
27.5326.17
16.06
31.715
45.525
21.30961538
31.2
23.235
15.51517.355
15.99516.89
24.005
38.63
28.34527.12
16.5
29.915
41.54
25.09576923
33.52
27.78
19.09520.15
17.585 17.59
25.9
39.705
29.6528.695
17.78
31.07
44.265
27.13730769
0
5
10
15
20
25
30
35
40
45
50
55
60
5000
1000
0
2000
0
5000
0
1000
00
2000
00
5000
00
1000
000
2000
000
5000
000
1000
0000
2000
0000
5000
0000
Aver
age
Zoom Level
FPS
Baseline
R6 Baseline
08.03.07 Baseline
08-10-07 Baseline .21DB
08.22.07 Baseline .21DB
08.27.07 Baseline .21DB
© 2008 NVIDIA Corporation.
Tracing to find timing delays
© 2008 NVIDIA Corporation.
Visualizing your Data: PerfHUD
© 2008 NVIDIA Corporation.
Measuring Data
© 2008 NVIDIA Corporation.
• Roads and land usage• POI collision detection• Terrain scrolling• 3D terrain generation• Bump mapping• Sky and fog• Color correction
Mapping Requirements
© 2008 NVIDIA Corporation.
• High quality AA is expected• Better than what FSAA can routinely
achieve
• Roads complex to draw• Fancy joins and ends• Road segments have multiple elements
• Straightforward implementation too slow• Low bus bandwidth from CPU to GPU
Roads
© 2008 NVIDIA Corporation.
• Use textures on tri-strips• Texture with alpha + alpha blend: high
quality AA edges• Simplifies geometry: reduces CPU and
bus bandwidth requirements• Works around slow wide lines on GPU
Road Techniques
© 2008 NVIDIA Corporation.
• Create “bullseye texture”• May need multiple resolutions to achieve
good texel sampling at different zoom levels.
• “Stretch” texture over tri-strip road segments• S coords 0 at one end, 1 at other, .5 at
line end transition.• T coords span width of line
AA Roads using Textures
© 2008 NVIDIA Corporation.
AA Roads using Texture
Road detail textures, different resolutions(if needed)
Road texture stretched onto tri-strip
Tri-strip with texture coordinates
0,0 0,1
.5,0 .5,1
.5,0 .5,1
1,0 1,1
© 2008 NVIDIA Corporation.
• Not limited to line ends• Can also do joins (curves) and
intersections• Use finer tessellation of base strip to get
smooth curves• Discontinuous texture coordinates
possible by doubling vertices
AA Roads using Texture (cont).
© 2008 NVIDIA Corporation.
• Same technique as roads• Expand to general polygons• Wrap polygons with textured tri-strips
• Alternatively you can surround polygons with AA lines
Land Use Features
© 2008 NVIDIA Corporation.
• POI = Points of Interest• Think road signs: food, gas, lodging, etc.• Usually round or square• 2D: a point on map, stays upright• 3D: billboard floating over point on
terrain
• Text• City, county, country, names etc.• Sometimes aligned to stay upright
POI, Text Collision Detection
© 2008 NVIDIA Corporation.
Roads, Land Use,Text and POIs
© 2008 NVIDIA Corporation.
• Need to decide how many POIs to show• They shouldn’t overlap, or crowd each
other: make map too busy or unreadable• More complex problem for 3D maps
• Need to keep POIs, rotated text from overlapping with upright text• Some apps require culling, not clipping
POI/Text Collision Detection
© 2008 NVIDIA Corporation.
• Can blit POIs and text to map image• But this prevents fast updates• Corrupts base image, limiting reuse
• Better to add text, POIs as textured polygons• Rotation, scale invariant (within limits)
• Billboarding used to keep text, POIs upright• Can group billboarding rotations
Applying POIs and Text
© 2008 NVIDIA Corporation.
• Precompute geometry extents, overlaps with CPU
• If objects can clip each other, depth buffering and stenciling will work• Sort objects by priority; higher priority
objects obscure lower priority ones
• Pixel picking methods to find overlap• Use colors as object ids• Needs fast readback, histogram
Collision Detection Approaches
© 2008 NVIDIA Corporation.
• Potentially large amount of bandwidth required
• Different techniques possible: best depends on hardware capabilities• Render speed• Blit Speed• Texturing
• Want to minimize CPU bandwidth, maximize GPU performance
Terrain Scrolling
© 2008 NVIDIA Corporation.
• Surface larger than visible area• Render a buffer around visible region• Render extra in direction of travel• Blit to scroll
• Optimal if there is not texturing h/w• Uses a lot of video memory• Blits may be slow, use up frame time• Won’t handle rotations, scales
Blitting
© 2008 NVIDIA Corporation.
Blitting (cont)
VisibleRegion Ex
tra
© 2008 NVIDIA Corporation.
• Surface the same size as visible area• Re-render entire scene each frame• No wasted video memory• No copies, handles rotation, scaling• Requires scene update, render update
is very fast• H/W accelerated transforms• VBOs or other methods to minimize
triangle bandwidth
Re-Render
© 2008 NVIDIA Corporation.
Re-Render (cont)
© 2008 NVIDIA Corporation.
• Texture larger than visible region• Used texture coordinate wrapping• Render to region in front of direction of
travel• Render with transformed texture
coordinates to scroll
• No copy, handles rotation, some scaling
• Must have fast render-to-texture
Wrapped Textures
© 2008 NVIDIA Corporation.
Wrapped Textures
VisibleRegion
© 2008 NVIDIA Corporation.
• Usually store height fields, create tessellated surfaces
• Multiple constraints• Must be fast with a slow CPU, bus• Data divided into tiles with different
resolutions to ease loading, save space• Flat vs. mountainous terrain• Near vs. far tiles
• Tiles must connect cleanly even when resolutions don’t match
3D Terrain Generation
© 2008 NVIDIA Corporation.
Terrain Generation
© 2008 NVIDIA Corporation.
• Sophisticated algorithms like SOAR• Good storage but high CPU load
• Simple regular grid• Fast but uses large amount of storage
• Simplified “quadtree” approach• Fast traversal to appropriate resolution
tiles• Regular at each level, fast tessellation
3D Terrain Representation
© 2008 NVIDIA Corporation.
• The more the map matches windshield view the better, but:• Too busy = hard to understand• Too much detail, map goes out of date
quickly
• The right amount of realism:• Easy for viewer to orient to map• Symbolic enough to quickly find useful
details
Adding realism to Terrain
© 2008 NVIDIA Corporation.
More Detail not Always Better
© 2008 NVIDIA Corporation.
• Terrain shape• Simplified terrain ok, but can’t make
distinct features unrecognizable!
• Lighting• Daytime: time of day (exact sun position)• Night: modified headlight view
• Sky, fogging• Adds realism that doesn’t distract• Simplifies view, eases terrain generation
Appropriate Terrain Realism
© 2008 NVIDIA Corporation.
• Normal maps• Less computation for CPU• Per pixel lighting, high quality
• Fog maps• OpenGL-ES fog too primitive• Maps give fine control of fogging function• Can change fog color with height (haze)• Can combine: RGB = color A = fogging
Terrain rendering tricks
© 2008 NVIDIA Corporation.
Fog Maps
© 2008 NVIDIA Corporation.
Terrain with Normal, Fog Maps2D Map (Cm)
Normal Map (Cn)
Diffuse Light (CD)
Cm * dot(Cn, CD) = CMapShaded
V
Fog map RGB
V
U
Fog map A
Pass 1 goes to RenTarget
Pass 2 goes to BackBuffer
Terrain Diffuse Color (CTerrain)
Fog (CFog)
= Cfinal
© 2008 NVIDIA Corporation.
• Content designers choose specific colors• Especially route colors
• They don’t like it if your shading changes their colors!
• Approaches• Tone mapping: adjust colors to “undo”
shading effect• Use stencil to mask out shading
Color Correction
© 2008 NVIDIA Corporation.
• OpenGL-ES 1.X (fixed functionality) can do a lot
• But there’s room for improvement• Better map quality• Better performance
• Newer maps need more of both• Higher resolution displays• More detail (with on-line updates)• Driver viewpoint
Going Forward
© 2008 NVIDIA Corporation.
• Displacement mapping• Use height field and flat grids as
inputs• Grids can be 2D and low precision coords
• Height field stored as mipmap• Grid vertex + ds/dx, dt/dy used to
mipmap to height value
• Fragment shader used for lighting• Compute normal from height map
Areas to Improve: Terrain
© 2008 NVIDIA Corporation.
• Vertex shader can do billboard computations on GPU
• Can batch multiple billboards into single draw call + uniform data
• Can also adjust billboard height based on height field stored as a texture
• Billboard position/orientation info reduced to an 2D point
Going Forward: Billboarding
© 2008 NVIDIA Corporation.
• Minimize geometry needed to render buildings
• Assume simplified buildings: floorplan + constant height• Reasonable for non-landmark buildings
• Send convex outlines of buildings• Can build arbitrary buildings from these
• Render as fans for tops• Use geometry shader to build walls
Areas to Improve: Buildings
© 2008 NVIDIA Corporation.
• Geometry shader to build walls• Send floorplans twice• Use primitive restart to separate array
into building pieces• Geometry shader offsets per attribute
height value, stitches quad array• Wall id attribute can be used to choose
wall texture, etc.• Facet normals computed from quads
Areas to Improve: Buildings (cont)
© 2008 NVIDIA Corporation.
Questions?