Heightmap Generation

From EQUIS Lab Wiki

Jump to: navigation, search

Our heightmap generation is based on two inputs:

  • An image showing using colours to show where different types of terrain are placed.
  • An XML document specifying the height and texture properties of the terrain.

These can be processed, generating a heightfield and a world texture, which can in turn be processed at runtime with our terrain rendering tools.

Contents

Format of XML Terrain Description

A terrain description is made up of the following XML tags.

equislandscape

This is the top-level tag describing a terrain. Attributes for terrains are:

  • hfsmooth (default 0): Specifies the amount of blurring to be performed on the heightmap. This is largely useful to smooth the areas between the terrain types.
  • terrainmap (no default): The terrain map image providing the location of the each terrain type.

This element contains one or more terrain elements.

terrain

This specifies the attributes of a part of the terrain. Attributes are:

  • name (no default): The name of the terrain type (e.g., "hill", "mountain", etc.)
  • mapcolour (no default): The colour used in the terrain map to identify this kind of terrain.

A terrain is described with three parts:

  • edge specifies how different terrains blend into each other at their edges
  • height specifies the height properties of this area
  • texture describes how the base texture for this terrain area is to be generated

There are three ways that the texture for each terrain type can be specified:

  • colour: Uses a single colour used for the entire texture
  • noisycolour: Uses a noisy texture interpololated between two given colours
  • heightbasedcolour: Uses multiple noisycolour or colour techniques based on height.

edge

This specifies what happens at the edge of the terrain when it blends with another terrain. Simple having one terrain stop and the next start leads to unsightly lines in the rendered terrain. There are two ways of dealing with this, each specified by an attribute:

  • bleed (default 0): A Guassian filter is used to "bleed" each terrain into its neighbouring terrain types. This feature currently uses the latest version of ImageMagick using a system call (win32 platform-specific). The value passed here represents the gaussian blur neighbourhood radius; smaller values give less obvious blurring and require less processing time.
  • crumble (default 0): The edges of the terrain are "crumbled" into the adjacent terrain. For some terrains this works well (e.g., mountain into hill), while for others it works poorly (e.g., river into plain). Crumbling is performed using the minimum crumble value of the two terrain types.

height

This specifies the range of heights within this kind of terrain. Mountains will have higher heights than plain, for example. Attributes are:

  • scale (default 1.0): The higher this number, the more noisy the terrain
  • bottom (default 0.0): Lowest height for this terrain type; in range [0,1]
  • top (default 1.0): Highest height for this terrain type; in range [0,1]
  • offset (default 0): Using different offset values modifies the terrains; if you don't like the terrain you got, you can try again with a different offset. This also can be used to ensure that different terrains don't repeat each other.

colour

Specifies a colour. Attributes are:

  • value (default: none): This may be a colour in hexadecimal RGB form (e.g., "FF0000" = red) or in decimal tuple form (e.g., "(255,0,0)" is also red.)

noisycolour

Specifies a random texture whose colours range between two given colour values. For example, a grassy area could be specified via a range of green colours. Attributes are:

  • scale (default 1.0): The higher this number, the noisier the resulting texture.
  • weight (default 0.5): A weighting factor. Weight = 0.5 gives approximately equal amounts of colour 1 and colour 2. Lower weight values give more of colour 1; higher values, more of colour 2.
  • offset (default 0): Modifies the starting point of the random generation of the texture. Modifying these give you back different texture patterns. Probably makes little real difference.

In addition, two colour elements must be specified to give the colour.

heightbasedcolour

This allows different parts of a terrain to be textured based on their height. A set of (at least one) range elements placed within this element specify how each height range is to be textured.

The colour for a particular height is calculated by finding the correct height range, and then blending the colour for that height with that of the height below.

range

Textures can be differently coloured depending on their height. range elements must appear within a heightbasedtexture element.

  • bottom (no default): The height above which this technique should be used.
  • top (no default): The height below which this technique should be used.

If ranges overlap, they are blended together, creating a more smooth transition from one colour to the next. The range must contain a colour or noisycolour tag to specify the texture of this part of the range.

Example

Here is an example XML terrain description.

<equislandscape hfsmooth="6" terrainmap="rsrcmap.png">
    <terrain name="hill" mapcolour="07ab0b">
	<edge bleed="30" crumble="5" />
	<height scale="0.03" bottom="0.01" top="0.20" offset="2" />
	<noisycolour scale="0.02" offset="10" >
	    <colour value="(95,150,16)" />
	    <colour value="(82,111,58)" />
	</noisycolour>
    </terrain>
    <terrain name="mtn" mapcolour="6a6a6a">
	<edge bleed="55" crumble="10" />
	<height scale="0.05" bottom="0.15" top="1.0" offset="3" />
	<heightbasedcolour>
	    <range bottom="0.15" top="0.85">
		<noisycolour scale="0.02">
		    <colour value="969a9a" />
		    <colour value="d8dada" />
		</noisycolour>
	    </range>
	    <range bottom="0.75" top="1.0">
		<noisycolour scale="0.02" weight="0.7">
		    <colour value="d3dcdb" />
		    <colour value="ffffff" />
		</noisycolour>
	    </range>
	</heightbasedcolour>
    </terrain>
    <terrain name="tree" mapcolour="46320b">
	<edge bleed="30" crumble="10" />
	<height scale="0.03" bottom="0.01" top="0.20" offset="4" />
	<noisycolour scale="0.02" offset="10" >
	    <colour value="103100" />
	    <colour value="634d02" />
	</noisycolour>
    </terrain>
    <terrain name="lake" mapcolour="1a314d">
	<edge bleed="30" />
	<height scale="0.03" bottom="0" top="0" offset="5" />
	<colour value="1a314d" />
    </terrain>
    <terrain name="river" mapcolour="4a96f3">
	<edge bleed="20" />
	<height scale="0.03" bottom="0" top="0" offset="6" />
	<colour value="1a314d" />
    </terrain>
    <terrain name="plain" mapcolour="b9e05b">
	<edge bleed="30" crumble="10" />
	<height scale="0.01" bottom="0.01" top="0.07" offset="7" />
	<noisycolour scale="0.02" offset="7">
	    <colour value="d4e879" />
	    <colour value="d7b86e" />
	</noisycolour>
    </terrain>
</equislandscape>

Source and Generated Images

The example XML settings file listed above was used to process the following image.

rsrcmap.png

Resulting height field and world texture

newhf-sm.png Heightfield
myhftex-sm.png World Texture

Resulting alpha maps

hill-sm.png Hills
lake-sm.png Lake
mtn-sm.png Mountains
tree-sm.png Trees
plain-sm.png Plains
river-sm.png River

Resulting shadow maps

normals-sm.png Terrain local shading
shadowmap-sm.png Terrain Self-occlusion