Skip to content

TerrainEditor

Gary edited this page Aug 15, 2014 · 8 revisions

Terrain rendering/editing feature for LevelEditor

Preview Video

See how the terrain editor works in the video at LevelEditor Videos.

Note: This video shows pre-release functionality.

Some screenshots

Technical summary

The terrain renderer and editor will be based on a height map, layers, and decoration maps:

  • The height map will be used to deform a 2D grid of vertices.
  • Each layer is used to paint particular ground type (rock, grass, dirt, snow, etc). Each layer is blended using a layer mask.
  • A decoration map is used for rendering billboards (representing ground level vegetation). Each decoration map is used to paint particular vegetation type (grass, flower, etc).
Note: Height-map-based terrain rendering have the following limitations:
  • Vertices can only be displaced vertically, so terrain cannot have overhangs or caves. However, additional static geometry can be used to create the required features.
  • The terrain vertices are uniformly distributed on a 2D grid that is vertically displaced with a height map. A uniform distribution is not ideal because, for example, steep mountains and other high-frequency topographical features benefit from a higher vertex density than do flat lands.

Architecture

Data model

A terrain will be represented by an object (GameObject) called TerrainGob. TerrainGob will have all the required properties and resources to represent terrain.

TerrainGob resources:

1) Height maps:

Height map displaces the 2D grid to form terrain. LevelEditor will provide 3D brushes to sculpt terrain. Each brush stroke is saved to the height map.

2) Layermap:

Each layermap has one diffuse and other optional textures and one alpha mask.

  • The diffuse texture provides the layer features (rock, grass, sand, etc).
  • Normal and specular textures are optional.
  • The alpha mask is a 8 bit one channel texture determines how much the layer will be blended.
The code can be modified to have 32 bit rgba alpha mask. In this case alpha mask define the how much and tint of the layer. For example deep green grass vs yellowish grass.

The resolution of the alpha mask should be at least the same as that of the height map, but it can be larger if the terrain needs to be painted at a finer level than the distance between vertices (or cell size). For example, if the distance between two vertices is three meters, but we want to paint a two-meter wide road, then the resolution of the alpha mask should be set so that the distance between two pixels is at most two meters. Note that using a higher resolution alpha mask for a particular layer is much more practical than increasing the vertex density across the board. The layers will be stacked on top of each other, and users can move them up/down to achieve a particular effect. In the pixel shader, each layer will be blended using its alpha mask. A layer will be painted onto the terrain using 3D brushes. Each brush stroke will modify the alpha mask of the layer.

3) DecorationMap:

A decoration map has several texture resources (diffuse, normal, spec) and one alpha mask. It is used for rendering billboards on terrain. The alpha mask is used to determine how the billboard should be rendered.

Similar to layers, decorations will be painted onto terrain using 3D brushes; each brush stroke is saved in the alpha mask.

Picking

  • Use Ray/AABB intersection to find the closest patch.
  • Compute tri-list for the patch and do ray/tri intersection.
  • Cache tri-list of MRU patches.