DirectX 11 graphics and procedural world creation

advertisement
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
• Advantages:
–
–
–
–
–
Easily modeled by an artist.
Easily implemented.
Normal maps can be paired for lighting.
Use far less memory than meshes.
Easier on the CPU/GPU.
• Disadvantages:
– 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.
– Makes downloadable games more manageable.
• 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
• Start with a 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.
Quadtree Structure
• Similar to binary trees, but has 4 nodes
instead of 2.
Quadtree Mesh
Uses For The Quadtree
•
•
•
•
•
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.
– Use of the geometry shader.
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 twothirds 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://www.youtube.com/watch?v=rL8zDgTlXso
– Start at 3:20
• http://www.youtube.com/watch?annotation_id=
annotation_790483&feature=iv&src_vid=OiGADg
ezjC8&v=oUSdSjnDB_E
– Start at 0:49
• http://www.youtube.com/watch?v=uzXB0m3_M
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-optimized efficient quad-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). Quadtree 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.
Download