Subscribe

I recently received a comment asking for details on the terrain generation algorithm I used in my XNA shoot ‘em up proof of concept. Here’s my edited reply and sample code for anyone interested.

It’s not very complex and it doesn’t do any culling currently because I didn’t find that to be a problem given the ammount of terrain samples that I’m rendering. I generally spend most of my time on the game play first before tweaking the graphics engine.

Here is the code used for generating and rendering the terrain in the screenshots:

http://jrepp.com/code/Terrain.cs

The method used is as follows:

Given a grid of height samples

  1. For some number N
  2. Choose a random X,Y sample in the grid
  3. Write a random value into the sample
  4. Blend that sample with all adjacent samples recursively
The blending adds some jitter so you get some variation in the blends but as a rule you can only blend between two samples by so much. I built some tolerances into the blending so that it will never generate height differences that are greater than the [horizontal] distance between two samples.

The verts are colored to get the basic effect of having land and sea.

Overall it’s a pretty simple algorithm that produces fairly decent looking results.

Please let me know if you have any questions, I’ll be happy to answer them.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Technorati
  • Reddit
  • Digg
  • del.icio.us
  • StumbleUpon
  • DZone
  • ThisNext

Related posts:

Trackback URI | Comments RSS

Leave a Reply