procedural graphics with directx 11
DESCRIPTION
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! - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/1.jpg)
Procedural Graphics with DirectX 11
James Reid
![Page 2: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/2.jpg)
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.
![Page 3: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/3.jpg)
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
![Page 4: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/4.jpg)
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
![Page 5: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/5.jpg)
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
![Page 6: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/6.jpg)
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)
![Page 7: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/7.jpg)
![Page 8: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/8.jpg)
![Page 9: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/9.jpg)
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;
![Page 10: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/10.jpg)
![Page 11: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/11.jpg)
Using Perlin Noise
• Start with a mesh.• Generate a height field using Perlin Noise.• Assign the coordinate for each pair in the
mesh.• Result:
![Page 12: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/12.jpg)
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.
![Page 13: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/13.jpg)
Quadtree Structure
• Similar to binary trees, but has 4 nodes instead of 2.
![Page 14: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/14.jpg)
Quadtree Mesh
![Page 15: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/15.jpg)
Uses For The Quadtree
• View frustum culling.• Level of detail (LOD).• Collision detection.• Grid location.• Reducing total vertices.
![Page 16: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/16.jpg)
View Frustum
• Field of view the camera has.• Used in culling and LOD.
![Page 17: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/17.jpg)
Frustum Culling
• Removing of primitives that are not seen from the graphics pipeline to increase performance.
• More types:– Backface– Contribution– Occlusion
![Page 18: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/18.jpg)
![Page 19: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/19.jpg)
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.
![Page 20: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/20.jpg)
![Page 21: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/21.jpg)
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.
![Page 22: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/22.jpg)
Texture Morphing
• LOD can cause textures to not line up and varying levels of detail.
• Solution: Use texture blending to hide the effect.
![Page 23: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/23.jpg)
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!)
![Page 24: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/24.jpg)
Tessellation
• Started in DirectX 10 – can be controlled by user with DirectX 11
• Take a mesh and add more primitives to smooth it out.
![Page 25: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/25.jpg)
![Page 26: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/26.jpg)
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.
![Page 27: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/27.jpg)
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=OiGADgezjC8&v=oUSdSjnDB_E– Start at 0:49
• http://www.youtube.com/watch?v=uzXB0m3_MHQ– Start at 0:25
![Page 28: Procedural Graphics with DirectX 11](https://reader033.vdocuments.site/reader033/viewer/2022061520/568151ac550346895dbfda93/html5/thumbnails/28.jpg)
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.