# Procedural Graphics with DirectX 11

Λογισμικό & κατασκευή λογ/κού

2 Δεκ 2013 (πριν από 4 χρόνια και 5 μήνες)

94 εμφανίσεις

Procedural Graphics with DirectX 11

James Reid

Meshes

A

mesh is what all the textures are laid on.

Meshes are deformed to give us the nice
terrains seen in games today using height
maps or procedural methods.

More vertices require more GPU power!

Goal: reduce number of vertices in a mesh
without sacrificing quality.

Height Maps

E
asily modeled by an artist.

Easily implemented.

Normal maps can be paired for lighting.

Use far less memory than meshes.

Easier on the CPU/GPU.

Only able to show 256 distinct heights in grayscale.

Can quickly consume hard disk space when having to store
height/normal/tangent/etc maps.

Image: The Elder Scrolls V: Skyrim

What is Procedural?

From Wikipedia: “
content generated
algorithmically rather than
manually”

Content is created at run time, not compile
time or stored in file.

Most games use height maps and models.

Image: The Elder Scrolls III: Morrowind

Why Use Procedural?

Memory usage is far less on both the hard disk
and in RAM.

Size limitations are much larger than those
involving height maps.

Allows games to be released on a single CD/DVD.

Image: Minecraft

Basis For Procedural

Noise algorithms.

Perlin

Voronoi

Can be implemented in different dimensions.

1D

2D (used for terrain/clouds)

3D (used for clouds the user can fly through)

How Noise Works

Summing up of static maps generated with
pseudorandom numbers.

Basic Algorithm:

double t = 0;

double amplitude = 1;

double freq = m_dFrequency;

for(
int

i

= 0;
i

< m_nOctaves;
i
++)

{

t += GetValue(x * freq + m_nSeed, y * freq + m_nSeed) * amplitude;

amplitude *= m_dPersistence;

freq *= 2;

}

return t;

Using Perlin Noise

2
𝑛

2
𝑛

mesh.

Generate a height field using Perlin Noise.

Assign the


coordinate for each
[

,

]

pair in
the mesh.

Result:

Scalability

Makes very convincing terrain.

Issues:

High number of vertices.

Static meshes can’t adapt to camera’s view.

Solution:

Use a quadtree structure to store the data.

Similar to binary trees, but has 4 nodes

View frustum culling.

Level of detail (LOD).

Collision detection.

Grid location.

Reducing total vertices.

View Frustum

Field of view the camera has.

Used in culling and LOD.

Frustum Culling

Removing of primitives that are not seen from
the graphics pipeline to increase performance.

More types:

Backface

Contribution

Occlusion

Level of Detail (LOD)

The amount of detail shown being based on
the camera’s view point.

Where DirectX 11 makes a difference.

Vertex Interpolation Error

When changing LOD the new vertices may
cause popping.

Several solutions to this, most common is to
just take the midpoint of both vertices.

Texture Morphing

LOD can cause textures to not line up and
varying levels of detail.

Solution: Use texture blending to hide the
effect.

Vertex Reduction

Use minimum number of vertices based on
slope of terrain.

Image: Shamus Young (Twenty Sided)

Top right: no optimization

Bottom left: optimized grid, removed about two
-
thirds of total vertices (Huge performance
increase!)

Tessellation

Started in DirectX 10

can be controlled by
user with DirectX 11

Take a mesh and add more primitives to
smooth it out.

Putting It All Together

Use CPU to determine LOD and any culling to
be done based on view frustum.

Use noise algorithm in real time on the GPU to
generate height field.

Remove any unwanted vertices based on
slope of terrain (e.g. flat areas will use two
triangles instead of filling up the mesh).

Morph the textures at the LOD breaks.

Tessellate the mesh in high detail locations.

Examples

http://

Start at 3:20

http://
ezjC8&v=oUSdSjnDB_E

Start at 0:49

http://
HQ

Start at 0:25

References

Schneider, J., &
Westermann
, R. (2006).

Gpu
-
friendly high
-
quality terrain
rendering
., Computer Graphics and Visualization Group,
Technische

Universität

München
, Munich, Germany
.

Yusov
, E., &
Turlapov
, V. (2007).

Gpu
-
-
tree based
progressive
multiresolution

model for interactive large scale terrain rendering
.,
Department of Computational Mathematics and Cybernetics, Nizhny Novgorod
State University, Nizhny Novgorod, Russia
.

Perlin, K. (2001).

Improving noise
., Media Research Laboratory, Dept. of Computer
Science, New York University , New York City, NY,
.

Verts
, W. T., & Hill, Jr., F. S. (1989).

meshes
, COINS Department, ECE
Department, University of Massachusetts, Amherst, MA,
.

Olsen, J. (2004).

Realtime

procedural terrain generation
., Department of
Mathematics And Computer Science (IMADA), University of Southern Denmark,
.

Bernhardt, A.,
Maximo
, A., Velho, L.,
Hnaidi
, H., &
Cani
, M. (2011).

Real
-
time
terrain modeling using
cpu

gpu

coupled computation
., INRIA, Grenoble Univ., Univ.
Lyon 1, IMPA, France, Brazil.