TerrainTile Class |
Namespace: DigitalRune.Graphics
The TerrainTile type exposes the following members.
Name | Description | |
---|---|---|
TerrainTile(IGraphicsService) |
Initializes a new instance of the TerrainTile class with a default
material.
| |
TerrainTile(IGraphicsService, Material) |
Initializes a new instance of the TerrainTile class with the specified
material.
|
Name | Description | |
---|---|---|
Dispose |
Releases all resources used by an instance of the TerrainTile class.
| |
Dispose(Boolean) |
Releases the unmanaged resources used by an instance of the TerrainTile 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.) | |
Invalidate |
Invalidates the terrain tile in the data cached by the renderer.
| |
Invalidate(TerrainLayer) |
Invalidates the specified terrain layer in the data cached by the renderer.
| |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
OnCreateMaterial |
Called when a new TerrainTile is created without explicitly specifying a
Material.
| |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
Name | Description | |
---|---|---|
Aabb |
Gets the axis-aligned bounding box of the terrain tile.
(Vertical min and max values are not set!)
| |
CellSize |
Gets or sets the world space size of one cell in the height texture.
| |
HeightTexture |
Gets or sets the height texture which stores absolute height values in the Red channel.
| |
HoleTexture |
Gets or sets the hole texture which stores hole information in the Alpha channel.
| |
IsDisposed |
Gets a value indicating whether this instance has been disposed of.
| |
Layers |
Gets the terrain layers.
| |
Material |
Gets or sets the material that is used to render the geometry of this terrain tile.
| |
MaterialInstance |
Gets the material instance.
| |
NormalTexture |
Gets or sets the normal texture which stores normal vectors.
| |
OriginX |
Gets or sets the world space origin of this terrain tile on the x-axis.
| |
OriginZ |
Gets or sets the world space origin of this terrain tile on the z-axis.
| |
Terrain |
Gets the terrain that owns this terrain tile.
| |
WidthX |
Gets the world space size of this terrain tile along the x-axis.
| |
WidthZ |
Gets the world space size of this terrain tile along the z-axis.
|
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.
Geometry textures:
The HeightTexture defines height values
(absolute heights in world space) of the terrain.
NormalTexture contains the terrain normal vectors. This texture encodes the normal vectors like a standard "green-up" normal map, i.e. the world space +x component of the normal is stored in the red channel. The world space up (+y) component is stored in the blue channel. The negative world space z component is stored in the green channel.
HoleTexture defines holes in the terrain. The texture is used like an alpha mask texture. If the alpha channel contains 0, then there is a hole in the terrain.
Tile dimensions:
OriginX and OriginZ define
the tile origin in world space - which corresponds to center of the first texel of the
textures. CellSize defines the horizontal distance between two height values.
The texture coordinate u is aligned with the positive x-axis. The texture coordinate
v is aligned with the positive z-axis. This means, if the cell/texel size is 1 world space
unit and the texture is 1025 x 513 texels large, then the terrain tile covers the area between
(OriginX, *, OriginZ) and (OriginX + 1024, *, OriginZ + 512).
Mipmaps:
All textures should contain mipmaps. Ideally, the mipmaps are
generated using 3 x 3 downsampling instead of the usual 2 x 2 downsampling. - Suitable
textures can be created using the TerrainHelper class.
Miscellaneous:
Please notes that the normal vectors depend on the scale
of the terrain. That means, if height values in the HeightTexture are scaled,
then the normal map has to be updated too. The normal map also needs to be updated if the
CellSize is changed! (This is not done automatically. Normal textures can be
created using the TerrainHelper.)
OriginX and OriginZ should always be an integer multiple of the CellSize. For example, if the cell size is 0.5, valid origin values are -0.5, 0, 0.5, 1, etc.
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).
See Terrain and TerrainLayer for more information.