Advanced Game Technology CMPCD3026 CMPSEM044 - PowerPoint PPT Presentation

1 / 59
About This Presentation
Title:

Advanced Game Technology CMPCD3026 CMPSEM044

Description:

... km requires a higher tessellation than when observed from a ... The quality of the tessellation can be changed at run time to achieve constant frame rates ... – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 60
Provided by: abdennour8
Category:

less

Transcript and Presenter's Notes

Title: Advanced Game Technology CMPCD3026 CMPSEM044


1
Advanced Game TechnologyCMPCD3026-CMPSEM044
Abdennour El Rhalibi Room 723 a.elrhalibi_at_livjm.ac
.uk
2
Course Details (Attempt)
  • 3D Game Engines Components
  • DirectX D3D, 3D Modelling and Rendering
  • Meshes, Level Loading and Editing
  • Terrain Rendering and LOD
  • Camera Setting and Animation
  • Spatial Data structure BSP and PVS
  • NPC Behaviour and 3D PathFinding A, Flocking,
    Scripting
  • 3D Collision Detection and Response
  • Shading languages
  • Game networking Issues Architecture, Protocol,
    Event Synchronisation
  • Introduction to Console Programming

3
Terrain Rendering and LOD Lecture 4
  • Abdennour El Rhalibi

4
Terrain
  • Terrain is important to many games
  • As a model, it is very large
  • Creating every point explicitly by hand is not
    feasible, so automated terrain generation methods
    are common
  • When rendering, some of the terrain is close, and
    other parts are far away, leading to terrain LOD
    algorithms

5
Terrain
  • A terrain mesh is nothing more than a triangle
    grid, with has heights of each vertex in the grid
    specified in such a way that the grid models a
    smooth transition from mountain to valley,
    simulating a natural terrain.
  • To make it realistic we apply a nice texture
    showing sandy beaches, grassy hills, and snowy
    mountains

6
Terrain
  • To generate terrain a simple solution consists in
    using a brute force approach.
  • it simply stores the entire terrain vertex/index
    data and then renders it.
  • For games requiring a small terrain, this
    approach is workable with modern graphics cards
    that support hardware vertex processing.
  • However, for games requiring larger terrains, you
    have to do some kind of level of detail or
    culling because the enormous amount of geometry
    data needed to model such huge terrains can be
    overwhelming for a brute force approach.

7
What is the Problem?
  • Terrains tend to be huge
  • Visualizing a terrain of 16384 x 16384 samples
    (164 x 164 km, samples 10 m apart) requires
    drawing 536.805.378 triangles (268.435.456
    vertices)
  • Adding a 32 bit RGBA texture and having 16 bit
    heights, the total memory consumption is above
    1.5 Gb!

8
Examples of Terrain with LOD
9
Examples of Terrain with LOD
10
Terrain Generation Methods
  • Paint the height field (artist generated)
  • Various pseudo-random processes
  • Independent random height at each point
  • Fault generation methods (based on random lines)
  • Particle deposition
  • Fractal terrain from meshes
  • Triangulated point sample methods
  • Plenty of research and commercial tools for
    terrain generation
  • http//www.vterrain.org/LOD/Implementations/

11
Surface Attributes
  • Rather than painting texture and color directly,
    paint attributes
  • E.g. Grass, Trees, Water,
  • Features can have game-play characteristics
    speed of motion, impassable,
  • Then automatically generate colors/textures
  • Care must be taken at the boundaries of the
    regions
  • Can also work for the terrain itself
  • E.g. Maps that have a finite number of possible
    heights, with ramps between them

12
Terrain Representation
  • Terrains are often represented using elevation
    maps
  • An elevation map is a 2D array of regularly
    spaced height samples

13
Painted Terrain Example
Color
Texture
Height
14
Representing Terrain
  • The base representation for terrain is usually a
    height field
  • zf(x,y) for (x,y) within the limits of the space
  • There are two common ways to represent the
    function f(x,y)
  • Explicitly store the value of f(x,y) for a
    discrete grid of (x,y) locations
  • Generally interpolate or triangulate to get
    points not on the grid
  • Easy to figure out what the height of the terrain
    is at any given (x,y)
  • Expensive to store the entire terrain
  • Store a polygonal mesh
  • Cheaper if the terrain has large flat areas
  • Harder to figure out what the height is under the
    player (have to know which triangle they are in)

15
Heightmaps
  • We use a heightmap to describe the hills and
    valleys of the terrain.
  • A heightmap is an array where each element
    specifies the height of a particular vertex in
    the terrain grid.
  • One of the possible graphical representations of
    a heightmap is a grayscale map, where darker
    values reflect portions of the terrain with low
    altitudes and whiter values reflect portions of
    the terrain with higher altitudes.

16
Create Heightmap as Grayscale
  • Heightmaps can be generated either
  • procedurally
  • or
  • In an image editor such as Adobe Photoshop.
  • Using an image editor is probably the easiest way
    to go, and it allows you to create the terrain
    interactively and visually as you want it.
  • In addition, you can take advantage of your image
    editor features, such as filters, to create
    interesting heightmaps.

17
Random Processes Generation
  • The claim is that real terrain looks random
    over many scales
  • Hence, random processes should generate realistic
    terrain
  • The catch is knowing which random processes
  • Some advantages
  • Lots of terrain with almost no effort
  • If the random values are repeatable, the terrain
    can be generated on the fly, which saves on
    storage
  • Some disadvantages
  • Very poor control over the outcome
  • Non-intuitive parameter settings

18
Random Points
  • Randomly choose a value for each grid point
  • Can make each point independent (dont consider
    neighbors)
  • Can make points dependent on previous points - a
    spatial Markov process
  • Generally must smooth the resulting terrain
  • Various smoothing filters could be used
  • Advantage Relatively easy to generate on the fly

19
Fault Formation
  • Claimed to model real fault lines, but not at all
    like real faults
  • Process 1
  • Generate a random line and lift everything on one
    side of the line by d
  • Scale d and repeat
  • Process 2
  • Generate a random line and lift the terrain
    adjacent to the line
  • Repeat (maybe with a scale function)
  • Smoothing is important

20
Fault Formation Example
Initial
Smoothed
21
Fault Formation Example
22
Particle Deposition
  • Supposed to model lava flow (or glacial
    drumlins!)
  • Process
  • Drop a particle onto the terrain
  • Jiggle it around until it is at most one unit
    higher than each of its neighbors
  • Repeat
  • Occasionally move the drop point around
  • To do volcanoes, invert everything above a plane
  • To do sinkholes, invert the hill
  • To do rows of hills, move the drop point along a
    line

23
Particle Deposition Process
?
?
In 3D, more scope for random choices on jiggling
particles
24
Particle Deposition Image
25
Fractal Terrain
  • Based on subdivision of a course polygon mesh
  • Each subdivision adds detail to the mesh in a
    random way
  • Algorithm (starting with a triangular mesh)
  • Split each edge, and shift the new vertex up or
    down by a random amount
  • Subdivide the triangles using the new vertices
  • Repeat
  • Also algorithms for quadrilateral meshes

26
Subdivision Method No 1
Note Works on any triangular mesh - does not
have to be regular or have equal sized triangles.
27
Subdivision Method No 2
  • Generates a triangle bintree from the top down
  • Useful for LOD,
  • Ideally, works for right-angled isosceles
    triangles

28
Subdivision Method No 3
  • Assume quadrilateral meshes

29
Fractal Terrain Details
  • The original mesh vertices dont move, so it
    defines the overall shape of the terrain
    (mountains, valleys, etc)
  • There are options for choosing where to move the
    new vertices
  • Uniform random offset
  • Normally distributed offset small motions more
    likely
  • Procedural rule eg Perlin noise
  • making patterns from pseudo-random numbers
  • If desired, boundary vertices can be left
    unmoved, to maintain the boundary edge

30
Fractal Terrains
Very jagged terrain
http//members.aol.com/maksoy/vistfrac/sunset.htm
31
Terrain, clouds generated using procedural
textures and Perlin noise http//www.planetside.co
.uk/ -- tool is called Terragen
32
Populating Terrain
  • Coloring terrain
  • Paint texture maps
  • Base color on height (with some randomness)
  • Trees
  • Paint densities, or randomly set density
  • Then place trees randomly within regions
    according to density
  • Rivers (and lakes)
  • Trace local minima, and estimate catchment areas

33
Terrain Generation Trade-Offs
  • Control vs Automation
  • Painting gives most control
  • Fractal terrain next best control because you can
    always specify more points
  • Random methods give little control - generate
    lots and choose the one you like
  • Generate on-the-fly
  • Random points and fractal terrain could be
    generated on the fly, but fractal terrain
    generation is quite slow
  • Tilings can also be generated on the fly

34
Static LOD
  • Depending on the roughness of the terrain and the
    application, 5-50 of the vertices and triangles
    can be removed
  • With 536.805.378 triangles still more than
    200.000.000 triangles to draw in best case.
  • Frustum culling further reduces number of
    triangles to draw
  • In most cases we still draw the terrain at full
    resolution near the far plane

35
View-Dependent Dynamic LOD
  • Dynamic simplification of visible part of the
    terrain
  • A mountain observed from a distance of 10 km
    requires a higher tessellation than when observed
    from a distance of 100 km
  • The quality of the tessellation can be changed at
    run time to achieve constant frame rates
  • Terrains can be altered at run time

36
Terrain LOD Algorithms
  • Triangle bintree based
  • ROAMing Terrain Real-time Optimally Adapting
    Meshes Duchaineau et al.
  • Quad tree based
  • E.g. Real-Time, Continuous Level of Detail
    Rendering of Height Fields Lindstrom et al.
  • Progressive mesh based
  • E.g. Smooth View-Dependent Level-of-Detail
    Control and its Application to Terrain Rendering
    Hoppe
  • Geo Mipmapping
  • Fast Terrain Rendering Using Geometrical
    MipMapping de Boer

37
Terrain LOD
  • Terrain poses problems for static LOD methods
  • Must have high resolution in the near field, and
    low resolution in the distance, all in one model
  • Dynamic LOD methods are the answer
  • All based on the idea of cuts through a tree of
    potential simplifications
  • We will discuss the ROAM algorithm in detail
  • Other continuous LOD algorithms are similar in
    style
  • An alternative is to create fixed LODs for
    sub-regions and figure out how to join them at
    the seams

38
Making Terrain LOD Easier!
  • Assumption We are starting with a height field
    defined on a regular grid
  • Assume its a square to make it easier
  • We can mesh it by forming triangles with the data
    points
  • The data is highly structured
  • Every data point has the same number of neighbors
  • Every triangle can be the same size
  • Hence, the tree of possible simplifications is
    very regular
  • Still, multiple possibilities exist for the
    triangulation and the simplification operations

39
Triangle Bintrees
  • Binary trees in which
  • Each node represents a right-angled isosceles
    triangle
  • Each node has two children formed by splitting
    from the right angle vertex to the midpoint of
    the baseline
  • The leaf nodes use vertices from the original
    height field
  • Another way to build a spatial partitioning tree,
    but particularly well suited to simplification
    algorithms
  • Easy to maintain neighbor information

40
Triangle BinTrees
  • A triangle bintree is a binary tree, whose nodes
    consist of right-isosceles triangles
  • the children of a node are defined by splitting
    the triangle along an edge from the apex vertex
    to the midpoint of the opposite edge

41
Triangle Bintree Example
3
1
4
6
2
1
2
5
3
4
5
6
8
7
7
8
9
10
11
12
13
14
10
13
14
9
11
12
42
Bintree Data Structure
  • Parent and child pointers
  • Neighbors
  • A left neighbor, a right neighbor, and a base
    neighbor
  • Note that the base and right angle give us a way
    to orient the triangle
  • Neighbors are not necessarily at your own level
  • Later, error bounds that say how much variation
    in height there is in your children

43
Triangulation
  • Triangle bintrees form a mesh by assigning a
    world space position to each vertex in the tree
  • Higher (lower) levels of detail are obtained by
    splitting (merging) triangles
  • Adds up to traversing the tree one level further
    down
  • Care must be taken to avoid crack in the
    resulting mesh

44
Avoiding Cracks
  • Neighbor triangles are always from same level,
    one finer (left right) or one coarser (base)
  • When splitting a triangle, its base neighbor is
    split at the same time
  • If the base neighbor is at a coarser level, it
    must be split first, which may require further
    recursive splitting

45
Generating Cuts
  • Cuts are generated by a sequence of split or
    merge steps
  • Split Drop the cut below to include your
    children
  • Merge Lift the cut up above two children
  • To avoid cracks, some splits lead to other,
    forced, splits
  • An LOD algorithm chooses which steps to apply to
    generate a particular triangle count or error rate

46
Cuts
3
1
4
6
2
1
2
5
3
4
5
6
8
7
7
8
9
10
11
12
13
14
10
9
47
Neighbors
  • 5 left neighbor 6, right neighbor 9
  • 6 left neighbor 8, right neighbor 5
  • 7 left neighbor 8, base neighbor 10
  • 8 base neighbor 6, right neighbor 7
  • 9 base neighbor 5, left neighbor 10
  • 10 base neighbor 7, right neighbor 9

8
7
10
6
9
5
  • Note that 8 is 6s left neighbor but 6 is 8s
    base neighbor
  • If you are someones left/right/base neighbor
    they are not always your right/left/base neighbor
  • In other words, neighbors need not come from the
    same level in the tree

48
Not All Cuts Are Created Equal
3
1
2
1
4
6
2
3
4
5
6
5
7
8
9
10
11
12
13
14
8
7
10
Note the T-vertex - causes cracks in rendering
9
49
A Split
  • A split cuts a triangle in two by splitting its
    base edge
  • If the base edge is on a boundary, just split, as
    shown
  • If the base edge is shared, additional splits are
    forced
  • Add a new triangle to the mesh

2
1
3
4
5
6
6
7
8
9
10
11
12
13
14
50
Forced Splits
  • Triangles are always split along their base
  • Hence, must also be able to split the base
    neighbor
  • Requires neighbors to be mutual base neighbors
  • If they are not base neighbors, even more splits
    are needed
  • Simple recursive formulation

51
Merges
  • A diamond is a merge candidate if the children of
    its members are in the triangulation
  • The children of the 7-10 diamond below are
    candidates
  • Look for parents of sibling leaf nodes that are
    base neighbors or have no base neighbors
  • Reduces the triangle count

8
7
10
9
52
Dual Queue Split-Merge
  • Dynamic triangulation is driven by one or two
    priority queues
  • Greedy split only algorithm uses a split queue to
    determine what triangles to split
  • Incremental algorithm uses both a split queue and
    a merge queue to take advantage of frame-to-frame
    coherence
  • Each triangle is given a priority
  • Triangles with high priorities are split before
    triangles with low priority

53
Split Queue
  • Insert all triangles in base triangulation into a
    queue
  • While stopping criteria is not met
  • Find and split triangle with highest priority
  • Remove that triangle and other split triangles
    from the queue
  • Add any new triangles to the queue

54
Split-Merge
  • If this is the first frame Insert all triangles
    in base triangulation into the split queue
  • Else Update priorities for all elements in the
    two queues
  • While quality of triangulation not satisfactory
    or maximum split priority gt minimum merge
    priority
  • If triangulation is to fine
  • Find and merge lowest priority mergeable diamond
  • Remove merged triangles from split queue and add
    the merge parents
  • Remove diamond from merge queue and add new
    mergeable diamonds
  • Else
  • Find and split highest priority triangle from
    split queue
  • Remove spilt triangles from split queue and add
    any new triangles
  • Remove diamonds from merge queue, whose children
    were split
  • Add any new mergeable diamonds to merge queue

55
Refinement LOD Algorithm
  • Start with the base mesh
  • Repeatedly split triangles until done
  • Stop when a specific triangle count is reached,
    or
  • Stop when error is below some amount
  • To guide the split order, assign priorities to
    each split and always do the one with the highest
    priority
  • After each split, update priorities of affected
    triangles
  • Sample priority High priority to splits that
    will reduce big errors
  • What is the complexity of this? (Roughly)
  • A similar algorithm works by simplifying the mesh
    through merge operations. Why choose one over the
    other?

56
Performance Bottlenecks
  • Storing and managing priorities for out-of-view
    triangles is a waste of time
  • Do standard frustum culling to identify them
  • Sending individual triangles is wasteful
  • Build strips as triangles are split and merged
  • Naively, at every frame, wedgies must be
    projected, new priorities computed and the queues
    re-sorted
  • Use the viewers velocity to bound the number of
    frames before a priority could possibly make it
    to the top of a heap
  • Delay recomputation until then
  • Priority queue Bin priorities to reduce sorting
    cost
  • At low priorities, order within bins doesnt
    matter

57
Additional Enhancements
  • Stop processing after a certain amount of time
  • Easily done just stop processing the next split
    or merge
  • Result no longer optimal, but probably not bad
  • Cost of dual queue algorithm depends on the
    number of steps required to change one mesh into
    another
  • Check ahead of time how many steps might be
    required
  • If too may, just rebuild mesh from scratch using
    refinement algorithm
  • Can get accurate line-of-sight or under-vehicle
    height by manipulating priorities to force
    certain splits

58
Other Algorithms
  • Algorithm from Lindstrom et al is essentially the
    same idea as the ROAM refinement algorithm
  • Based on square blocks of (triangulated) terrain
  • Makes determining forced splits harder
  • Slightly different error bounds
  • An algorithm from the game community
  • For a particular split operation, the viewer
    distance is the primary error factor
  • For each split, store distance at which it should
    occur
  • Check current mesh on each frame for
    splits/merges according to viewer distance
  • Non-optimal, but gets rid of priority queues (the
    big cost)

59
Other Issues
  • Terrain Texturing
  • Terrain Lighting
  • Camera Animation and Fly-through
  • SkyBox
  • Collision
  • Maintaining characters and objects on top of
    Terrain
Write a Comment
User Comments (0)
About PowerShow.com