3D Terrain


The holy grail of the games I want to make is a Tropico-esque simulation game set around the colonization of Mars. Over the past couple of years I’ve built a number of tech demos to support it. In this case, I wanted to generate terrain for a random landing site and the surrounding area. One of the key features of the terrain was that it be pathable so a player could create a base and expand outwards without resorting to terrain editing. Additionally, I used this as an opportunity to explore HLSL and procedural texture generation. The grass and sand are traditional texture maps. The nougaty cliff faces are all procedural.


The process begins with the diamond-square algorithm to generate fractal noise and a a network of valleys is etched into the map using Voronoi diagrams. These valleys help ensure there is a network of pathable terrain later as well as provide an interesting variation from the fractal noise. The world is then supersampled to smooth the heights. After that, a series of weather algorithms work over the terrain. Some simulate water flow carrying dirt from ridges to valleys, others work towards creating flat areas at various heights. The results above show (from upper left, clockwise): No erosion, primarily water erosion, the most pathable blend of both erosion types, primarily non-water erosion.

The terrain generator outputs a list of vertex positions, which is then massaged into a series of XNA Vertex/IndexBuffers with a custom vertex definition. From there, an HLSL pixel shader handles the multitexturing based on elevation and slope.


The maps produced by this technique were typically over 70% pathable, and a quick breadth-first search was able to show that there was one dominant walkable area. From the perspective of creating usable terrain for a world building game, the experiment was a success. With some more effort, it wouldn’t be difficult to identify one way connections in the graph (say, down a cliff) or ‘near’ connections that could be smoothed to increase the walkable area.

From the perspective of creating a procedurally generated rock texture? Well, that needs some work.


Coordinating terrain appearance, pathability, and real time generation was a balancing act. More variegated terrain was less pathable, more pathable terrain took longer to render.