Large Scale Terrain Rendering
- Posted: Feb 08, 2012 at 6:00AM
- 15,121 views
- 1 comment
Loading user information from Channel 9
Something went wrong getting user information from Channel 9
Loading user information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
Today's project is hard to apply a "W" name to, maybe we'll just call this "Wow Wednesday" and leave it at that, because once I got this project running, "Wow, that's kind of cool" was my first thought...
Terrain Rendering is a game technology code sample that demonstrates how to render large-scale terrains in real time by efficiently distributing the tasks between the CPU and the GPU. This article provides an overview of the terrain-rendering application and includes a link to the free code.
This sample demonstrates how to render large-scale terrains on Intel® microarchitecture codename Sandy Bridge in real time by efficiently distributing the tasks between the CPU cores and the processor graphics unit. The sample pre-processes an input height map into a hierarchical quadtree representation which is used to render the terrain with adaptively selected level of detail (LOD). The adaptive simplified triangulation calculated during the pre-processing is compactly encoded to save runtime processing and memory space. LOD construction is asynchronously performed by the CPU cores while rendering is done by the processor graphics unit.
Terrain Rendering is an application using DXUT and Microsoft DirectX* 11 with D3D_FEATURE_LEVEL_10_0. The application handles all rendering, user interaction and GUI. Upon initialization, the application loads all models, allocates resources and compiles shaders. On the first run, the application pre-calculates triangulation, which can take some time (up to one minute), and stores it on the disk. On subsequent runs, the application loads the data from the disk.
Terrain rendering demonstrates how to render large-scale terrains on Intel microarchitecture codename Sandy Bridge in real time by efficiently distributing the tasks between the CPU cores and the processor graphics unit. The terrain rendering can be optimized by constructing simplified triangulation, which is adaptive to the terrain surface characteristics. Such triangulation contains more primitives in sharp regions with high-frequency details and allocates a small number of large triangles for flat areas. This significantly reduces the total triangle count while providing almost the same visual quality (compare fig. 1 and 2).
Full-resolution triangulation (fig. 1) is more than 5x redundant compared to adaptive (fig. 2), which results in nearly 3x lower performance with almost the same visual quality.
Pre-computing adaptive triangulation is a complex and computation-intensive task. Doing this at runtime could require a significant amount of time and would lead to perceptible stalls or delays. To solve this problem, the application pre-computes adaptive triangulation for the whole terrain at the pre-process stage and stores the resulting data on the disk in a compact representation (see section 4). For example, the whole encoded triangulation for an 8192×8192 terrain consumes approximately 6 MB (compare this to 128 MB required to store the height map). At the runtime stage, this data is used to efficiently construct the triangulation.
This sample demonstrates how to render large-scale terrains on Intel® microarchitecture code name Sandy Bridge in real time by efficiently distributing the tasks between the CPU cores and the processor graphics unit. The input height map is preprocessed into a hierarchical quad tree representation which is used to render the terrain with adaptively selected level of detail (LOD). The adaptive simplified triangulation is compactly encoded to save runtime processing and memory space. LOD construction is asynchronously performed by the CPU cores while rendering is done by the processor graphics unit, which provides stable frame rate.
- CPU: Intel® Advanced Vector Extensions (Intel® AVX)-enabled x86 (Intel® microarchictecture code name Sandy Bridge or better suggested)
- GFX: uses Microsoft DirectX* 11 graphics API on Microsoft DirectX* 10 (or better) hardware
- OS: Microsoft Windows* 7 SP1 (for Intel AVX support)
- MEM: 2 GB of RAM or better
- Microsoft DirectX* SDK (June 2010 release or later)
- Microsoft Windows* SDK May 2010
- Microsoft Visual Studio* 2010 (Intel AVX support required) or Intel® C++ Compiler version 11
- Microsoft* C Run-Time Libraries (CRT) 2008/2010
Getting this to compile and run on my notebook wasn't hard, once I got the DirectX SDK installed. Here's some snaps of it running on my notebook;
Here's a snap of the Solution;
So what good is this? I'm not really sure...lol. I just thought it was pretty cool and fun, to be able to "fly" around the terrain, to play with the settings and know that I've got the source for how it was generated. That said, the best part was the original CodeProject article with the details and depth it went into. If you've ever wondered about terrain retendering, this is an article you might want to check out...