Terrain
Large expansive terrains is one of the most important parts of scene rendering. The appearance of terrain may vary widely depicting a complex and naturally diverse landscape: it can provide either smoothed planes or hilly areas, while avoiding the overhead from managing far-stretching terrains and maintaining robustness at steady frame rate. The built-in terrain editor allows to create richly detailed terrains with unique textures for rendered surfaces. It features brushes for changing terrain relief on the spot and design mountains, cliffs and grooves that have significant height variations, as well as holes.
- Meshes are better to be used instead or to cover such relief.
- It is recommended to enable Triplanar texturing in case of steep slopes.
See also
- A terrain_base material that is applied to terrains
- An Adding Terrain tutorial
- An ObjectTerrain class to edit terrains via UnigineScript
- An Unigine::ObjectTerrain class to edit terrains via C++ API
Overview
The terrain object is represented as a regular 2D grid with a specified step, which stores information about the height of terrain vertices. Each vertex stores its height with a 15-bit precision, that is, there are 32768 height levels available to describe elevation changes in range from 0 to the maximum height in units (specified at creation). Plus one bit is used to store information whether there is a hole in it or not. Such a regular grid structure of terrain provides a number of benefits: simplicity of data structure, efficient memory usage and smooth visual transitions between the LODs. At the same time, it means that such relief features as overhangs and caves are not possible, so static meshes should be used for them.
To create the terrain, the following textures are required:
- Height map, which describes general features of a relief. Height map is a gray-scale texture (usually 16-bit) that describes the altitude value for each point of terrain: pixels of darker gray represent lower altitudes and lighter gray correspond to higher altitudes. The map is necessary only if a terrain is not painted by hand starting from a plain in the editing mode, but created in an external specialized software.
- Normal map is generated on the base of Height map. It is used to grant correct lighting of terrain on all levels of detail.
- Diffuse texture, which describes the basic coloring of the whole terrain, while its alpha channel defines the specular intensity.
- Mask texture, which specifies the areas to detail the terrain, i.e. how detail materials comprising the ground will be blended with the basic diffuse texture.
- Detail materials, which represent fine details like rocks, moss, grass patches or dirt and aim to give the terrain a real-world visual appearance. They have a diffuse texture, which determines their color (RGB channels) and specular highlights (alpha channel), and a normal map of their own.
Height map |
Diffuse texture |
Generated normal map |
Mask texture |
When a terrain is created, its grid is automatically divided into surfaces, that contain 257×257 vertices. Each surface is assigned a unique diffuse texture, normal map and mask texture, which, in fact, are parts cut out from the imported textures. It can also take up to 4 detail materials to diversify the covered terrain region. Surfaces represent the minimum unit for data loading.
Terrain LODs
To visualize a terrain at rendering time, when the landscape needs to be detailed only near the camera and less intricate at a distance, a levels of details (LODs) system is applied. It automatically adapts the density of terrain grid to the distance.
- The furthermost from the camera and the least detailed level is represented with coarse textures. Coarse textures are the imported diffuse texture and generated normal map that were automatically reduced in size. They are always stored in the memory and allow to effectively render extremely large terrains, as they handle distances up to infinity.
- Next comes the closer levels of rendering surfaces. These are four LODs with denser grid, that also use coarse textures where neither detail materials, nor holes are visible. They provide only the basic and the largest relief features and diffuse colors.
- The closest to the camera and most detailed is the level of patches. Each surface is split into 16×16 patches that are rendered with all details: material textures and holes. Patches also provide 4 levels to adapt the grid step to the distance.
All LODs are created automatically with the following tessellation parameters. Distance to switch the appropriate LOD is defined based on the adjustable distance to the first LOD. On the patch level, it is the following: for each following LOD, its distance is multiplied by 2n-1, where n is the LOD number. On the surface and coarse levels, it will be 2n+1-1. The distance between the patch level and the surface level is extended to avoid cracks between the vertices and implement smooth terrain geomorphing.
LOD Name | LOD Distance | Grid Step | Draw Calls | |
---|---|---|---|---|
Patches | LOD 0 (the most detailed, stored in a file) | Non-tessellated LOD | The original terrain size* | 4-8 DIP calls per surface |
LOD 1 (adjustable distance) | Distance to start tessellation | Terrain size / 2 | ||
LOD 2 | LOD 1 × 3 | Terrain size / 4 | ||
LOD 3 | LOD 1 × 7 | Terrain size / 8 | ||
Surfaces | LOD 4 (stored in a file) | LOD 1 × 31 | Terrain size / 16 | 1 DIP call per surface |
LOD 5 | LOD 1 × 63 | Terrain size / 32 | ||
LOD 6 | LOD 1 × 127 | Terrain size / 64 | ||
LOD 7 | LOD 1 × 255 | Terrain size / 128 | ||
Coarse Textures | LOD 8 (the least detailed, stored in a file) | LOD 1 × 511 | Terrain size / 256 | 1 DIP call |
Terrain LODs has smoothly adapting tessellation which allows to avoid seams and cracks in transition regions. Each vertex near the outer perimeter of smaller LOD is seamlessly stitched to the neighboring polygons of bigger LOD with additional triangles. The same technique is used to smoothly fuse heights and holes into the terrain.
Geomorphing
Another problem by switching two tessellation levels is popping of vertices. For example, when polygons that form pyramid-like bump are abruptly switched to one flat polygon, it gives a very unpleasant popping effect. Geomorphing technique introduces an effective way out: before actually switching to the next LOD, it smoothly moves vertices down to their position, morphing the bump into flat surface. As a result, there are no artifacts visible; even in case of a very sparse grid and too small LOD distance only slightly moving vertices can be noticed.
Hummock from close-by |
The same hummock from further away |
Physics simulation
The terrain takes part in physics simulation if it has a standard surface_base property assigned. Collisions with physical bodies use the most detailed LOD 0 and are handled within a set distance, where simulation of physics is in effect.