The creation of the Landscape

Xtreme3D

Lesson 15
The creation of the Landscape

Level: medium
Version of the Xtreme3D: 3.0.x
Author: Gecko

The Landscape (Terrain) is an important part of the games many genres, modeling the situation in the real world is Racing, Strategy, many of the shooter and the various games with the open world. Usually the landscape is not modeled manually and is generated from the so-called card heights - the image, where the dark areas indicate lower height and bright - increase. The generation of the landscape can occur both in the program of the 3D modeling as well as in the game - in the latter case, there is a possibility to optimize the rendering of landscape, dynamically changing the detail depending on the distance from the camera (dynamic LOD). In the Xtreme3D also has support for such technology.
In order to render the landscape, you must first download the map heights, in the terminology of the Xtreme3D - HDS (Height Data Source, the source of data about the height):

The Hds BmpHDSCreate =('heightmap.bmp');
BmpHDSSetInfiniteWarp(hds, 0);

BmpHDSSetInfiniteWarp function can make the map heights endlessly looping in all four sides - very handy if you want to make a limitless world.

Now create the landscape is the object of the Terrain:

The terrain = TerrainCreate(global.scene);
TerrainSetHeightData(terrain, hds);
TerrainSetTileSize(terrain, 32);
TerrainSetTilesPerTexture(terrain, 8);
TerrainSetQualityDistance(terrain, 100);
TerrainSetQualityStyle(terrain, hrsFullGeometry);
TerrainSetMaxCLodTriangles(terrain, 10000);
TerrainSetCLodPrecision(terrain, 50);
TerrainSetOcclusionFrameSkip(terrain, 0);
TerrainSetOcclusionTesselate(terrain, totTesselateIfVisible);

If you run the game at this stage, the landscape is likely to be too high and rotated 90 degrees. This is easy to fix by installing the desired scale in the Z axis and Rotating an object on the X-axis:

ObjectSetScale(terrain, 1, 1, 0.1);
ObjectRotate(terrain, 90, 0, 0).

Separate the words deserved the overlay textures on the landscape. This can be done in many different ways, I propose the following: first, the texture of the material (diffuse) will be tight on the whole landscape, and the second (the texture of detail) will be repeated many times with the magnitude of the overlying the first in the modulate (i.e., by changing the brightness of the previous). Thus, there is an illusion that the landscape uses huge detailed texture.

MaterialCreate('mTerrain', 'the terrain-diffuse.jpg');
MaterialSetOptions('mTerrain', false, true);
MaterialCreate('detmap', 'the terrain detail.jpg');
MaterialSetTextureScale('detmap', 100, 100);
MaterialSetSecondTexture('mTerrain', 'detmap');
ObjectSetMaterial(terrain, 'mTerrain');

Please note that we switched lighting for landscape material - the fact is that the dynamic LOD does not allows you to define normal for the vertices (since the sets of vertices are constantly changing), which is necessary for the correct lights polygons. Therefore, for the landscape should use static lighting - the map light, combined with the diffuse texture.

Still another challenge: movement of the character on the landscape. This is easily done with the help of the designated functions - TerrainGetHeightAtObjectPosition, which returns the height of the land in the point, which coincides with the absolute position of the object:

ObjectSetPositionY(camPos, TerrainGetHeightAtObjectPosition(terrain, camPos) + 1);