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.

Random Scattering of Objects

Learn how to randomly position objects upon a surface (a terrain or any of your meshes) using a World Clutter. With it you will scatter your props very fast and easy: trees, bushes, flowers, stones — anything at all. They are also will be automatically scaled and oriented for more diversity.
Here we are going to create a forest by scattering birch trees. This is the second part of Adding vegetation tutorial.

Required Textures

A texture needed to set up World Clutter scattering is as follows.

A one-channel Mask in the R8 format. The whiter the area, the more densely trees will be scattered across it. Black areas will have no trees. This texture was generated basing on the terrain's diffuse texture.

Required Settings

You may need to increase the precision of the depth buffer. Otherwise, flickering of the grass in the distance may occur.
Press T to go to the Tools settings -> Camera tab. Increase the Near clipping up to 0.3.

Step 1. Create a Node Reference out of the Tree

A World Clutter works only with reference nodes. In addition, using reference nodes also allows not to set up each and every tree in the forest separately. Instead, when editing one node reference of the birch, all other birches will be changed as well.

  1. Click on the tree to select a node. We have a tree set up already:

  2. Open a Nodes panel. Reset position of the node to zero; otherwise, a node will be exported with offset relative to the world zero.

    Our node disappears, because it is repositioned to the world zero of coordinates:

    If you would like to, you can press F hot key to focus on the node (and G to reset the pivot back to normal after that).
    Notice
    To turn off rendering object bounding box, uncheck the Tools -> Interface -> Object bounds.

  3. Choose Export into a node file button.

  4. Select a name of the .node file into which a reference node will be saved.

  5. Disable or delete the node from the world. We do not need it any more.

  6. In the same way export all other trees that will be scattered to create a forest.

Step 2. Create a World Clutter

  1. On the editor panel, click Add an object button, and then World Clutter in the rollout.

  2. For now specify the following settings — we will readjust them later:
    • Set the Visible distance to 10 units. It is a distance around the camera within which scattered objects will be rendered.
    • Set the Fade distance to 0 so that are not rendered any further.

    Drop the clutter somewhere in the world. Right now there are no objects in it so it is empty:

  3. Now we need to align the Clutter with the terrain so that objects could be scattered across it.
    Make the grass a child of the terrain: press ALT and drag the World Clutter node to the terrain node.

  4. Rename the node if necessary.

  5. Reset coordinates of the Clutter to 0 relative its parent. It will synchronize its position with the terrain.

  6. Go to the Clutter tab. Check the Intersection option to create a forest right upon its surface and repeat its relief.

  7. Set the Size X and Size Y (sizes along X and Y axes) of the World Clutter. In our case, it will be of the same as the terrain.

Step 3. Scatter Objects

Now we can add objects saved as reference nodes and set up how they are scattered.

  1. Click Add button to add a node reference.

  2. Select a path to the node reference.

  3. In the same way add other nodes into the World Clutter, if necessary. In our forest there will be birches of three kinds randomly scattered.

  4. There are way too many trees per square unit and it cases performance degradation.
    Increase the Step of cells in which the Clutter is rendered up to 40.

    The cells became bigger. Notice that the visible distance also moved a way a bit, because it is actually measured to the cell rather than to each separate tree.

  5. Decrease the Density in a cell to 0.015.

    That looks better:

  6. Now we can readjust the Visible distance as needed. Increase it to 140.
    Notice
    Remember that the real radius of visibility will depend also on the object (surface) maximum visible distance.

    The line where the trees end is pretty abrupt.

  7. Increase the Fade distance to 30.

    The line where the trees stop to be rendered softens:

    It is best to combine fading out of Clutter visibility range with smooth fade-out of the last tree LOD. (See how to set up object fade out.)
    Notice
    After the node references were edited, it is necessary to do one of the following for changes to be applied to the World Clutter:
    • Save and reload the world (R hot key)
    • Remove and add again nodes into a World Clutter

  8. Let's load a Mask that specifies across what areas and how dense the trees will be placed.

  9. Select the path to the mask:

    The trees no longer grow across stony areas.

  10. To increase the strength of masking, increase the mask Threshold up to 0.7. The trees will be rendered in smaller groups, because the density of areas (according to the mask) around this tree groups became not enough to render anything there.

  11. Right now the trees are scattered equally upon the hill slopes as well as upon flat planes:

    Increase the Angle up to 0.8 to exclude steep areas from scattering.

    The steeper the slope, the less trees grow upon it:

Step 4. Randomize Scattered Objects

  1. At the moment all objects that were loaded into the World Clutter are present in equal proportion: we've got about the same number of birches of each type.
    To decrease the number of some objects, drag its probability slider to the left. In our case, the number of birches 2 will be significantly lower and there will be just a few birches 3.

    Now the forest consists mostly of the birches 1 while the density has remained the same:

  2. Let's place some of the birches lower than the terrain surface and some higher above the ground.
    Set the Offset to -0.3. This is a mean value. It determines that all birches will be placed 0.3 units lower into the ground.

  3. We have set the initial position and now it can be randomized.
    Set the Offset Spread value to -0.3. As a result, the possible offset will be from -0.6 to 0 units.

    Each birch is offset by a random value from the possible range:

  4. To scale each birch differently, set the Scale Spread value to 0.15. In this case, each birch will be scaled randomly, but no lower than 0.85 and no higher than 1.15.

  5. To randomly rotate the birches around their axes, set Rotation Z Spread value to 180. It will give us birches randomly rotated by 360 degrees.

Last update: 03.07.2017
Build: ()