shown in other instead.
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.
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.
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.
- Click on the tree to select a node. We have a tree set up already:
- 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: hot key to focus on the node (and G to reset the pivot back to normal after that).
- Choose Export into a node file button.
- Select a name of the .node file into which a reference node will be saved.
- Disable or delete the node from the world. We do not need it any more.
- In the same way export all other trees that will be scattered to create a forest.
Step 2. Create a World Clutter
- On the editor panel, click Add an object button, and then World Clutter in the rollout.
- 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:
- 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.
- Rename the node if necessary.
- Reset coordinates of the Clutter to 0 relative its parent. It will synchronize its position with the terrain.
- Go to the Clutter tab. Check the Intersection option to create a forest right upon its surface and repeat its relief.
- 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.
- Click Add button to add a node reference.
- Select a path to the node reference.
- 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.
- 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.
- Decrease the Density in a cell to 0.015.
That looks better:
- Now we can readjust the Visible distance as needed. Increase it to 140.
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.
- Increase the Fade distance to 30.
The line where the trees stop to be rendered softens: smooth fade-out of the last tree LOD. (See how to set up object fade out.)
- Let's load a Mask that specifies across what areas and how dense the trees will be placed.
- Select the path to the mask:
The trees no longer grow across stony areas.
- 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.
- Right now the trees are scattered equally upon the hill slopes as well as upon flat planes:
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
- 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:
- 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.
- 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:
- 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.
- 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.