The terrain system is responsible for rendering the procedural terrain from information defined by terrain control points. The terrain is completely regenerated every frame using the CPU and GPU. The terrain effect requires Pixel Shader 3.0.

CPU Implementation

The CPU is responsible for evaluating the influence of control points at specific points on the screen. This is then assembled into a terrain mesh and sent to the GPU for further processing. Terrain vertices contain a screen space position, a world location, and the influences of all control points in range. The influence values are stored in a float4 so the maximum number of different materials that can effect the terrain simultaneously is four. The terrain system can pick these four materials by proximity to the center of the screen so a level can use more than four materials for terrain as long as they can't all be seen on-screen at once.

GPU Implementation

The GPU is responsible for constructing the final image from the terrain mesh. Since the terrain mesh never moves relative to the screen, the GPU simulates camera movement through calculating the UV coordinates for the terrain texture from the would location values specified in the terrain mesh. The GPU also adjusts the per-pixel material influences with a noise texture. The weights for the noise are specified in the terrain mesh.


The terrain mesh also contains water saturation values. After adjusting for the noise values, the GPU determines whether a specific pixel should be underwater. A pixel is determined to be underwater if the water saturation multiplied by the control point influence is greater that 0.5. If a pixel is determined to be underwater, the GPU calculates a reflection vector off the water and checks it against a sky texture. A specular highlight is also calculated for the sun. The surface normal is computed by summing three moving noise textures at different sizes and offsets.


When designing terrains in the editor, a few limitations apply...
  • The maximum number of materials visible on-screen simultaneously is 4
  • The maximum distance at which the terrain system can find a control point at is 2500 pixels from the center of the screen
  • The maximum distance at which the terrain system will evaluate a control point at is 1500 pixel plus the point's radius
  • The resolution of the terrain mesh is 32 x 24 vertices
  • At 800x600 this means the minimum size of a non-noise terrain feature is >25 pixels
  • All terrain points of the same material in an area must have the same noise and water saturation values