TerrainLayer Class |
Namespace: DigitalRune.Graphics
The TerrainLayer type exposes the following members.
Name | Description | |
---|---|---|
TerrainLayer |
Initializes a new instance of the TerrainLayer class.
|
Name | Description | |
---|---|---|
Dispose |
Releases all resources used by an instance of the TerrainLayer class.
| |
Dispose(Boolean) |
Releases the unmanaged resources used by an instance of the TerrainLayer class
and optionally releases the managed resources.
| |
Equals | (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
Name | Description | |
---|---|---|
Aabb |
Gets (or sets) the axis-aligned bounding box of the area that is influenced by this terrain
layer.
| |
FadeInEnd |
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.)
| |
FadeInStart |
Gets or sets the clipmap level where this terrain layer starts to fade in.
(This is a material parameter - see remarks.)
| |
FadeOutEnd |
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.)
| |
FadeOutStart |
Gets or sets the clipmap level where this terrain layer starts to fade out.
(This is a material parameter - see remarks.)
| |
IsDisposed |
Gets a value indicating whether this instance has been disposed of.
| |
Material |
Gets (or sets) the material that is used to render this terrain layer.
| |
MaterialInstance |
Gets the material instance.
|
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.