Tuesday, June 16, 2009

The Terrain Less Traveled

There is no shortage of tutorials about doing terrain in XNA, including some great tutorials about GPU based heightmap terrain and various LOD methods that can be implemented. As I went through each of these with very little knowledge of C# and no knowledge of XNA I learned a lot, and fairly quickly felt much more comfortable with the framework.

But who wants to make something that everyone else has made, and while tutorials are great, if all of your components are simple carbon copies of various tutorials all mashed together I don't think you learn or grow. So in order to make things interesting I have started working on a GPU based Terrain using Hardware Instancing.

Initial Tests were promissing, right off the bat I was seeing a lot of improvement in frame rate over a simple static vertex buffer pre-generated during the load content process. Here you can see an early implementation of the instance based terrain, using 64x64 vertex grids instanced to match the heightmaps resolution per vertex. Early on I realised that I made a basic mistake in building my vertex buffer and only had 63x63 cells.

Fixing this and then making a couple small adjustments to how the texture coordinates were generated in the HLSL Vertex Shader things started looking much more promissing.

It should be noted that with the full instanced terrain, no LOD and no Culling I was seeing a solid 25-30 FPS performance boost over the static vertex buffer with and without the vertex buffer height sampling.

So now with some of the initial issues squashed I am moving on to implementing an initial crude LOD system. I plan on testing two approaches, the first being multiple draw calls with instance data for each LOD level and a few different grids stored in the vertex buffer, or alternatly would be swapping index buffers then drawing each LOD level. I think this will be a better choice since I can maintain my extremely small memory footprint with only a single 64x64 grid stored in memory. More pictures and results from that later.

It should be noted I would not have gotten nearly as far as I have without the brilliant mind of Jared Belkus making timely suggestions when I find myself in a corner.

No comments:

Post a Comment