This page has been translated automatically.
UnigineScript
The Language
Core Library
Engine Library
Node-Related Classes
GUI-Related Classes
Plugins Library
High-Level Systems
Samples
C++ API
API Reference
Integration Samples
Usage Examples
C++ Plugins
Content Creation
Materials
Unigine Material Library
Tutorials
Внимание! Эта версия документация УСТАРЕЛА, поскольку относится к более ранней версии SDK! Пожалуйста, переключитесь на самую актуальную документацию для последней версии SDK.
Внимание! Эта версия документации описывает устаревшую версию SDK, которая больше не поддерживается! Пожалуйста, обновитесь до последней версии SDK.

Adding Terrain

Learn how to create a terrain in Unigine Editor using the existing Height map generated in some third-party application.

We are going to assign to the terrain additional detail materials to get high resolutional textures when viewing close-by. Keep in mind that the detail materials always blend with diffuse colors of terrain. Using such an approach your terrain will never look dull and tiled. Instead, you will easily create a realistically looking terrain, that varies its coloring without any effort from artists. Once we have created a properly colored diffuse texture, the same detail material of the grass will be green on the low ground - and yellowish and withered in the mountains. Fast, easy and performance-wise!

Also you will learn how to optimize the rendering of the big terrain in the few steps by means of Terrain Occluder.

Step 1. Preparation

For this tutorial you will need the following textures:

Notice
For more information about all these textures see Terrain dimensions and texture formats.

Textures Exporting

We will export Height, Diffuse and Mask textures from the terrain_00 sample to apply this textures in the tutorial. If you already have your own prepared textures, skip this part.

  1. Run Unigine Editor.
  2. Click Open world button.

  3. Open samples/objects directory, select terrain_00 scene and press Ok.

  4. In the loaded world click the Nodes tab on the Editor interface panel or press N.
  5. Select ObjectTerrain_1 and go to the Terrain tab.
  6. To export the textures click Export:
    • Heights to export the Height map
    • Diffuse to export the Diffuse texture
    • Mask to export the Mask texture for the details

  7. Save the textures under Unigine evaluation/data folder.
  8. Close Nodes tab.

Create a New World

  1. To create a new world, click Create new world button on the editor interface panel, or press CTRL + N.

  2. Choose the directory and a File Name for the new world. It must be created under <Unigine>/data folder.

A new world with the default sun node is created.

Step 2. Add Terrain

  1. On the editor panel, click Add an object button and choose Terrain in the rollout.

  2. Choose Import tab to create a terrain on the base of a Height map. Set the following parameters:
    • Step - the size of a terrain grid cell in units, can be left the same
    • Height of the terrain depends on the imported Height map and cannot be changed afterwards. It determines the minimum gradation in heights, so it is better not to set bigger than necessary value, so set it to 200
    • LOD distance, from where the first LOD starts, will be tweaked later
    • Size specifies the size of the created terrain in units. According to our Height map, set to 1024
    • Flip Y allows to flip a Height map around Y-axis, if checked. We do not need to check it

  3. Choose the Height map to be imported.

  4. Set a name and a path for the created terrain.

After clicking Ok, place the terrain somewhere in the world. To focus a camera on it, press F. Terrain will appear in grey and will be shown in wireframe mode.

Notice
To toggle the wireframe mode off, press 2, or press T -> Tools settings -> Object wireframe flag.

Step 3. Add Terrain Textures and Detail Materials

To make the terrain look realistic and variegate, we will add basic terrain textures and additional detail materials.

  1. In the Nodes settings, select the terrain, go to the Terrain tab and select the Diffuse: Import option.

  2. Select a path to the Diffuse texture.

  3. Choose the size of a coarse Diffuse texture, which will be used for the furthest LOD of terrain.
    Notice
    Avoid setting too big size, because this texture is always loaded in the memory; however, too low resolution will result in terrain being too blurry in the distance.

    We will set the size to 2048.

    Notice
    You can regenerate the coarse Diffuse texture of appropriate size later by modifying Update coarse diffuse option.
  4. The big Diffuse texture will be split into small patches each corresponding to one terrain surface. The result we'll have:

  5. Select Normal: Import option to import normals for the terrain.

  6. Choose the size of a coarse normal map, just like for a Diffuse texture.

  7. The normal map will be also split into small patches on the per-surface basis. The terrain becomes lit up. The specular component (alpha channel of the Diffuse texture) is also revealed.

    At the bottom of the Terrain tab you can find both coarse textures. (Split diffuse textures and normal maps are displayed for each surface on the Surfaces tab).

  8. Now we can add detail materials that will be used across the terrain. They should be added in the order of masking.
    Go to the Materials tab and select Add option.

    Notice
    The number of detail materials across the whole terrain is unlimited; however, each surface can take no more than 4.
  9. Set the name for this new material.

  10. Load a Diffuse texture for the material by clicking the folder icon.

  11. Choose compressed texture to load.
    For material textures neither Compress terrain textures option nor automatic compression works. Textures can be compressed manually with ImageDDS tool.

  12. Load a normal map.

  13. Choose compressed normal map to load.

  14. Load all other detail materials of the terrain in the same way.

    After that, we can import a material mask according to which materials will be revealed. Each channel of this mask controls the visibility of one detail material (according to their order on Materials tab):

    • R channel defines the visibility of the 1st material
    • G channel - of the 2nd material
    • B channel - of the 3rd material
    • A channel - of the 4th material.
    Go back to Terrain tab and choose Import mask option.

  15. Select a path to the Mask texture.

  16. Set the Threshold for the mask. It is useful when there are more than 4 material textures on the terrain. In our case, there are only 3, so 0 is set.

  17. The Mask texture is also split per-surface.

    Detail materials are seen only on the four closest LOD levels:

  18. Now materials can be tweaked.
    Go back to the Materials tab, choose a material and set a texture tile along X and Y axes in the Transform fields. The higher the value, the smaller and more repetitive the tile. Set Transform to 5.0 to both X and Y axes for every material.

    Here, all materials are tiled with the respect of the mountains scale:

  19. Use Diffuse scale to increase the color intensity of the material.

  20. Use Normal scale to create more prominent relief.

  21. The terrain is almost set, so let's gain some productivity. The relief of the furthest mountains does not need to be so sharp for a such a far distance.
    Go back to the Terrain tab and decrease the Lods distance until noticeable.

    The mountains on the horizon became less refined, while the FPS increased:

  22. Increase the Flatness within reasonable limits. This will allow to decrease the number of rendered triangles on the flat terrain areas. (It is strongly recommended to rebake a Height map with new flattened relief. For more details, see here).

    Toggle the wireframe mode on by pressing 2 to see the result:

  23. Set the Shadow range to 1000. After that the terrain relief will cast shadows from any of the light sources only within 1000 units from the camera. It is almost unnoticeable, while the performance increases.

  24. If the terrain will not be modified any more, go to the compression step.

Step 4. Assign Terrain Material

Terrain material allows to control the terrain shading. When creating the terrain, terrain_base material is assigned by default. However, to tweak its parameters, it is necessary to create a tweakable child material inherited from the base one.

  1. Press M to open Materials settings. For further actions, you should already have a material library associated with the world (see how to add a new material library, steps 1-5).
  2. Select a basic (and therefore unchangeable) terrain_base material in the list and click inherit the material.

  3. Choose the world-associated material library where to save a new material and specify its name. (If there are none, you should create one first).

  4. Clicking the Assign material icon will assign the material to the currently selected node (in the Nodes settings) — the terrain, in our case.

  5. Now we can tweak the material. Right now our terrain is too shiny:

    Go to Parameters tab. Decrease the Fresnel bias to 0 so that it becomes matt.

Step 5. Edit Terrain

We can edit terrain on the spot, for example, to ensure that objects stand firmly on it. In our case, we added a house into the world and now it needs to be placed at the slope of the mountain.

  1. Go to the Terrain tab to open the Terrain Editor and click Edit terrain button.

  2. Choose Heights brush to change the terrain relief.

  3. Press CTR + LMB to grab the current height value of the slope where the house stands. It will be reflected in the Value field.

  4. Drag a slider or press ] to set a bigger Radius of the brush.

  5. Press ALT + LMB to use the brush.

  6. Change the brush mode to the Dilate. It allows to raise the ground covered by the brush up to its upper point (regardless of the brush value).

  7. Decrease the Opacity to apply the brush slower. Also increase the Radius.

    Press ALT + LMB to use the brush. It has given the bottom of the plateau a more natural appearance:

  8. Change the brush mode to the Erode. This brush will lower the ground covered by the brush down to its lower point.

    Change the top of the plateau:

  9. Now we'd want to modify the colors for the plateau. Change the brush to Diffuse + Mask to edit both Diffuse texture and material mask simultaneously.

  10. Grab the color and material by pressing CTR + LMB.

  11. To change the color, press on the Value color field.

  12. Choose the color to paint with:

  13. Change the opacity of the brush for more subtle coloring, and alter the brush radius.

    The result of applying the brush:

  14. To save the brush so it could be used, later click on the Save icon and drag it onto the palette slot while holding the mouse button pressed.

  15. After the editing is finished, press Apply to save the changes and exit the terrain editor.

  16. It is necessary to regenerate coarse textures; otherwise, the color changes would not be seen on the far LODs, but only on the closest ones (1-4 LODs).
    Go to the Nodes settings -> Terrain tab and choose the Update coarse diffuse option to regenerate a coarse diffuse. Again, set its size.

  17. Select also the Create normals option to properly light newly added terrain vertices. Set its size to 2048.

    At last, the result:

  18. If the work with the terrain is finished, and and there will be no further editing of terrain textures, choose the Compress option.

  19. All terrain textures, except for material textures, will be compressed to save the memory.

Step 6. Add the Terrain Occluder

To speed up the rendering of the large-scaled terrain with a lot of objects placed on it, Terrain Occluder should be added.

Notice
If the terrain relief is changed in the runtime, it is not recommended to use a terrain occluder. Another variant is to black out the areas in the Height map, where changes will take place.
  1. On the editor panel, click Add a world object button, and then choose Occluder in the rollout.

  2. Choose the OccluderTerrain tab and set the same dimensions for the occluder as the terrain has: its width, length and height.

    Place the occluder somewhere in the world:

  3. Downsize the Height map used for terrain. As only rough approximation is required, we will use 257x257 occluder texture.

    Notice
    For more details on textures sizes see Terrain Occluder Texture article.
  4. Go to Nodes Settings -> OccluderTerrain tab to load the downsized Height map.

  5. Select a path to the downsized Height map.

  6. It may take some time, while the engine generates the occluder texture. Press Ok to rewrite the texture with generated one:

  7. Let's position the occluder properly.
    Make the occluder a child node of the terrain: in the Nodes Settings hierarchy select the occluder, press ALT and drag it to the terrain node.

  8. Reset coordinates of the occluder to 0. As a child node, it will be positioned relative the parent terrain.

  9. Right now the occluder due to its low texture resolution can cull the visible areas by mistake:

    This artifact can be easily avoided. Position the occluder slightly lower than the terrain.

    Now our terrain is properly occluded:

Step 7. See the Result

Set up light scattering in the scene, so that distant montains look foggy. And that would be our final result:

Last update: 03.07.2017
Build: ()