Click or drag to resize
DigitalRuneTerrainLayer Class
Defines a material layer (detail textures, decals, roads, etc.) of the terrain.
Inheritance Hierarchy

Namespace: DigitalRune.Graphics
Assembly: DigitalRune.Graphics (in DigitalRune.Graphics.dll) Version: 1.2.0.0 (1.2.1.14562)
Syntax
public abstract class TerrainLayer : IDisposable, 
	IInternalTerrainLayer

The TerrainLayer type exposes the following members.

Constructors
  NameDescription
Protected methodTerrainLayer
Initializes a new instance of the TerrainLayer class.
Top
Methods
  NameDescription
Public methodDispose
Releases all resources used by an instance of the TerrainLayer class.
Protected methodDispose(Boolean)
Releases the unmanaged resources used by an instance of the TerrainLayer class and optionally releases the managed resources.
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Properties
  NameDescription
Public propertyAabb
Gets (or sets) the axis-aligned bounding box of the area that is influenced by this terrain layer.
Public propertyFadeInEnd
Gets or sets the clipmap level where the fade-in ends and this terrain layer is fully visible. (This is a material parameter - see remarks.)
Public propertyFadeInStart
Gets or sets the clipmap level where this terrain layer starts to fade in. (This is a material parameter - see remarks.)
Public propertyFadeOutEnd
Gets or sets the clipmap level where the fade-out ends and this terrain layer is not rendered anymore. (This is a material parameter - see remarks.)
Public propertyFadeOutStart
Gets or sets the clipmap level where this terrain layer starts to fade out. (This is a material parameter - see remarks.)
Public propertyIsDisposed
Gets a value indicating whether this instance has been disposed of.
Public propertyMaterial
Gets (or sets) the material that is used to render this terrain layer.
Public propertyMaterialInstance
Gets the material instance.
Top
Remarks

A terrain is split into one or more tiles. The terrain tiles defines the geometry (height, normals, holes) of the terrain. Each tile has a set of material layers (dirt, grass, decals, roads) that define the appearance. The material layers are applied (blended) one after the other, which means that a layer can override previous layers.

Example: The first layer draws a dirt texture that covers the whole tile. The second layer draws a grass texture, which covers only parts of the tile defined by a blend map. Additional layers add roads and decals like dirt, leaves, sewer grates, etc.

Each terrain tile can have its own set of terrain layers, but they can also share the same TerrainLayer instances.

Materials:
Each TerrainLayer has a Material which is used to render the layer information. The TerrainClipmapRenderer uses the material to render the layer information into TerrainClipmaps. The TerrainClipmapRenderer requires that the material has a render pass called "Base" when it wants to render information, such as heights, into the BaseClipmap and a render pass called "Detail" when it wants to render information, such as a grass texture, into the DetailClipmap.

Fade-in/out by distance:
The properties FadeInStart, FadeInEnd, FadeOutStart, FadeOutEnd can be used to define into which clipmap levels the layer is rendered. For example if (FadeInStart, FadeInEnd, FadeOutStart, FadeOutEnd) is (1, 3, 5, 7), then the layer is rendered into the clipmap level 1 with a low opacity. The opacity increases in level 2 and reaches 100% in level 3. The layer is rendered with full opacity in level 4. Then the opacity decreases again and reaches 0% at level 7. The default values are (0, 0, MaxValue, MaxValue) which means that fading is disabled and the terrain layer is always visible at all distances.

These fade-in/out properties can be used to render details, like decals, only near the camera. It can also be used to have one layer draw a detailed rock texture only near the camera. Another layer can render a low resolution rock texture only in the distance.

The fade-in/out properties are based on clipmap levels and not view-distance. (The reason: If the distance depends on the camera, then all cached clipmaps have to be redrawn when the camera moves. This needs to be avoided.)

Cache invalidation:
When the Terrain is used with the TerrainNode, then the terrain data is cached in clipmaps. Therefore, it is important to notify the terrain system when a tile or layer has changed and the cached data is invalid. When tiles or layers are added to or removed from the terrain, this happens automatically. But when the properties or the contents of tiles/layers are changed, the affected region needs to be invalidated explicitly by calling the appropriate Invalidate method of the Terrain or the TerrainTile. For example, when the contents of a height map is changed, the affected region on the terrain needs to be invalidated by calling Invalidate(Aabb) or Invalidate(TerrainTile).

Disposing:
TerrainLayers are disposable. Derived classes should dispose all auto-generated resources. Resources set by the user or loaded via a content manager are not disposed by the TerrainLayer.

See Also