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
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

Adding Vegetation: Creating a Tree

Learn how to create vegetation (trees, bushes, flowers) in Unigine application from a static model. This includes preparing a model (here, a tree with billboard leaves), exporting it and quickly animating it directly in the engine. With vegetation animation system, a tree will realistically move under the wind without much effort from an artist.

If you are familiar with the general guidelines for tree creation, you can jump straight to the billboard leaves preparation part.

Step 1 (Optional). Create a Tree in a Procedural Generator

If you are completely new to vegetation creation pipeline, here are some notes that will help you get started.

  1. The easiest way to create vegetation is to use specialized procedural tree generators. They allow to create trees faster, and generate different variants of a tree in a few clicks.
    Notice
    Make sure that in a procedural generator of your choice four-sided polygons are supported for leaves. (It is required to convert them into billboards in Unigine. It is also possible to use usual polygons for leaves, but they are more expensive performance-wise.)
  2. Using photos as references, create a tree model by specifying such parameters as the number of boughs, branches and twigs, if they are horizontal, vertical or diagonal, their size, if there are crotches, etc. The more accurately these parameters are set up, the more realistic a tree will look like as a result.
  3. To make a tree mesh real-time friendly, limit the number of polygons for branches and density of billboard leaves.
  4. Try out different tree shapes by modifying a random seed for its parameters.
  5. Export a tree into 3ds Max or other supported 3D editor.

Step 2. Create Textures

Once we have our tree, let's prepare textures for it.

  1. You can create textures for leaves either in 2D or in 3D editors. It's better to use 3D editors, however, since in Unigine a realistic, Phong shading-based lighting model (with normal map support) is used for them.
  2. Create a diffuse texture for leaves. The alpha value should be from 0.5 (at the edges) to 1 (in the center). Such approach is used to smoothly switch LODs with alpha dithering (fading). Lower alpha values are not supported by Unigine.
    Keep the empty space on the texture to a minimum (see details in the Troubleshooting section).

    Diffuse texture
    Alpha channel in range [0.5;1]
  3. Create a specular map for leaves.
    • RGB values set reflection color and intensity (black means no reflection)
    • Alpha value specifies the specular power:
      • 0 for specular highlights to be very bright and intense
      • 256 for specular highlights to be dull

    Specular map
  4. For leaves not to look flat, bake a normal map for leaves.
    Note that in Unigine only two-channel normal maps are used, so we will need to convert it later.

    Normal map
  5. Additionally, in Unigine leaves can be modulated with a one-channel Thickness texture. It specifies how transparent the leaves are under the sunlight. We will use a default one, since it will be enough.
  6. A trunk with branches is textured in a usual way. Create a diffuse texture, normal and specular maps. Here are textures shown up close and in full:
                        
    Diffuse texture
    Normal map
    Specular map
    As you can see, we will use the diffuse texture for a specular map since it's it works in this case: white trunk is glossy and back spots are matt.

Step 3. Create LODs and Prepare Billboard Leaves

Now we need to create LODs for a tree. Leaves also need to be set up before they are exported as billboards into Unigine.

  1. Let's set up the closest, most detailed LOD of the tree. If required, reduce the number of polygons for branches even further (in case the procedural generator did not cope with this task well enough).

  2. Prepare leaves for export: downsize leaf polygons until they are very small. It's not what their real size will be like. Unigine engine will simply use them for reference when billboard leaves are rendered. Four vertices of each of these polygons will be stretched to the actual size of a billboard and oriented.
    Notice
    If polygons will be big (bigger than the actual billboard size), billboard leaves will not be rendered correctly.

  3. Create the 1st UV set for the tree trunk, branches and leaf polygons. They are textured in a usual way.
  4. Now set up the real size and orientation of the billboard leaves. For that, create the 2nd UV set.
    • Position the leaf billboards relative the anchor point (shown below). Billboards will rotate around this point when leaves are animated in Unigine.
      • In 3ds Max, the anchor is the top left corner of the UVW zero-to-one square (at [1,0] coordinates).
      • In Maya, it is the lower left corner.
    • Scale the real size of billboards. A 1x1 quad in UV equals a billboard of 1x1 unit size in Unigine.
    Here, the cursor indicates the anchor point. Our first leaf billboard will be hanging down.

  5. The second billboard also hangs down and is oriented to the right.

  6. The third one is oriented to the left. It will give a nice counter motion of leaves towards each other.

  7. For leaves to look naturally, select random billboards (for example, via the Selection tab → By Random) and scale all of them differently.

  8. Create a low-poly mesh of the tree. It will be used as a distant LOD.
  9. Reduce the number of reference polygons for leaves.

  10. Slightly shift the leaf polygons, for example, via the Noise modifier.
    Notice
    If all leaf LODs have the same coordinates, it will cause z-fighting artifacts when LODs are faded.
  11. In the 2nd UV channel, create larger leaf billboards for this LOD. Scale and orient them randomly.

The tree is ready for export.

Step 4. Export a Tree Mesh

  1. Group leaves and trunk (with branches) into LODs: one group for the first LOD trunk, another group for the first LOD leaves, second LOD trunk, second LOD leaves, etc.
  2. On the Exporter panel at the side check Groups as surfaces to export tree LODs.

  3. Specify that the second UV channel with billboard data should be exported as well.

  4. If necessary, change other options (the model's scale, a pivot point to use) and click Export As.

  5. Specify a name and save a Unigine static mesh.

Step 5. Add a Tree Mesh

  1. On the editor panel, click Add an object button, and then Static or skinned mesh in the rollout.

  2. Select a path to the mesh:

    Place the mesh in the world.

  3. It is better to turn off all distant LODs to set up materials.
    Press N to go to the Nodes settingsSurfaces tab. Holding CTRL (or SHIFT), select LOD surfaces and disable them.

Step 6. Create Material for the Tree Trunk

Now we can start to create materials for our birch.

  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) mesh_stem_base material in the list and click Inherit the material.

  3. Choose a material library associated with the world (into this library a new stem material will be saved). Specify the material name as well.

  4. To assign the created material, go back to the Nodes settings → Surfaces tab. Holding CTRL (or SHIFT), select all trunk-related surfaces and click Load the material icon:

  5. Choose the material from the list:

    A tree trunk is now rendered and animated according to the assigned material:

  6. Disable the animation for now, so it is possible to set up trunk colors.
    Go back to the Materials settings → Parameters tab and set Stem offset to 0.

    The birch stands still again:

  7. Go to the Textures tab and load the diffuse texture for trunk and branches.

  8. Select a path to the diffuse texture.
    Notice
    If you have an uncompressed diffuse texture (in any format other than DDS), the engine can automatically convert it into a necessary format and compress it. For that:
    1. Add _d postfix to the texture name (for example, birch_bark_d.png).
    2. Create a folder named uncompressed and place a texture into it.
    A compressed texture (here, birch_bark_d.dds) will be placed into a folder one level up from the uncompressed one.

  9. Load a normal map.

  10. Select a path to the normal map. Make sure it is a 2-channel map (in red-green colors) rather than a 3-channel one. Otherwise, lighting will be incorrect!
    Notice
    To automatically convert an uncompressed normal map into a right 2-channel format and compress it:
    1. Add _n postfix to the texture name (for example, birch_bark_n.png).
    2. Create a folder named uncompressed and place a texture into it.

  11. Load a specular map.

  12. Select a path to the specular map. Here, we are going to use the diffuse texture for a specular map.
    Notice
    To automatically compress a specular map:
    1. Add _s postfix to the texture name (for example, birch_bark_s.png).
    2. Create a folder named uncompressed and place a texture into it.

    Now there are no reflections from black areas on the bark:

  13. The textures are not mapped right, obviously. To fix that, go to the Parameters tab and double-click on the Transform Base field. (Or you can modify the expression right in this field).

  14. In order to be tiled properly, the textures need to have higher Scale. For X axis, set it to 16.

  15. Right now the bark is too shiny:

    Double click on the Diffuse color field.

  16. Instead of pure white, select a grayish color.

    Now the colors are less bright:

  17. Decrease the Glossiness down to, let's say, 4. It makes the highlights wider, though the trunk becomes too bright again.

    What to set for this parameter, as well as for the ones below, highly depends on the lighting in the scene.

  18. Since reflections are too bright, decrease the Fresnel bias parameter down to 0.05. It will decrease the reflectance level.

  19. Let's make the trunk look whiter at the edges (since white bark reflects a lot of light). Increase the Phong rim scale up to 0.04. Phong shadowing is now brighter.

Step 7. Set Up Trunk Animation

  1. Set Stem offset to 0.03 so that the tree sways from left to right.

  2. Decrease Stem radius so it does not bend so close to the ground.

  3. Increase Stem scale to speed up the movement of the trunk.

  4. Increase Stem noise. When several trees with such stem material will be added to a scene, all of them will move differently. This option is important when a forest is created.

The trunk gently sways in the wind, and we are done with it.

Step 8. Create Material for Tree Leaves

  1. Select a basic (and hence unchangeable) mesh_leaf_base material in the list and click Inherit the material.

  2. Choose a material library associated with the world (into this library a new leaf material will be saved). Specify the material name as well.

  3. To assign the created material, go back to the Nodes settings → Surfaces tab. Holding SHIFT (or CTRL), select all surfaces with leaves LODs and click Load the material icon:

  4. Choose the material from the list:

    The leaf material is assigned and our leaves start to move:

  5. Go to the Materials settingsStates tab. Choose the option to render leaves as billboards.

    Instead of polygons, billboards are now rendered. They became as big as defined in the 2nd UV channel by export.

  6. Disable the animation for now, so it is possible to set up how the leaves look like. Uncheck the Animation box.

    The leaves stand still.

  7. Go to the Textures tab and load the diffuse texture for leaves.

  8. Select a path to the diffuse texture.

    Notice
    Diffuse texture that has _d postfix and is located in folder named uncompressed will be automatically compressed by the engine.

  9. Now leaves are lit uniformly across the whole billboard. For them to look lifelike under the sun, we need lighting by a normal map.
    Go back to the States tab and enable Phong shading.

  10. Go to the Textures tab and load a normal map.

  11. Select a path to the normal map. Make sure it is a 2-channel normal map, or use an option to automatically convert it.

    Notice
    To be automatically converted and compressed, a normal map should have a _n postfix and be located in the uncompressed folder.

  12. Load a specular map as well.

  13. Select a path to the specular map.

    Notice
    To be automatically compressed, a specular texture should have a _s postfix and be located in the uncompressed folder.

  14. To add natural color variations to the leaves, go back to States tab and enable Color noise. This option colors leaves by a noise texture (default or a custom one).

  15. Go to the Textures tab and load a Color gradient texture. We have a texture to vary leaf colors from light yellow to darker saturated ones.

  16. Select a path to the color gradient texture.

    Notice
    To be automatically compressed, a gradient texture should have a _dr postfix and be located in the uncompressed folder.

  17. To change how the color noise is distributed, transform the noise texture coordinates. Let's make differently colored areas bigger in scale, so that from a distance the tree looks more flecked.
    Go to the Parameters tab. Click on the Noise Transform field and change the expression to vec3(0.03f). It will decrease the number of tiles of the spatial noise texture. (Also, you can double click on the filed and edit texture tiling along X, Y and Z axes).

  18. Increase the noise Scale up to 0.9 to make color variations even brighter and more prominent.

  19. When you look at the leaves against the sun light, they are too dark, while in real life they are transparent.

    Increase Translucency up to 0.9 to make them more transparent to light.

  20. Now they look translucent, but the colors are too bright. Decrease Diffuse down to 0.7 to darken diffuse colors.

  21. To simulate more dense foliage, increase Thickness up to 0.6. It will darken leaves based on a Thickness texture we've left default. As the texture is plainly colored, leaves will be darkened all at once.

  22. To add even more depth to the foliage, increase Shadow up to 0.1. This option allows to control the shadow depth for leaves.

Step 9. Set Up Leaves Animation

  1. First of all, enable the animation that we've disabled earlier.
    Go to the States tab and check the Animation box.

  2. Go back to the Parameters tab and find that animation parameters have appeared there. We have to synchronize movement of the trunk and its branches with leaf movement.
    Set the SAME stem parameters as used for the trunk. They are:

    The animation becomes synchronized:

  3. To decrease the amplitude of sway from left to right, decrease Leaf offset down to 0.05.

  4. To make the sway faster, increase Leaf scale up to 7.

  5. To make all the leaves move more randomly, increase Leaf noise up to 10.

Step 10. Set Up Tree LODs

Enable and set up the distance to switch LODs of the tree as described here.

Step 11. Optimize Leaves. Troubleshooting

For leaves to be rendered faster and not to flicker in the distance (due to the limited depth buffer precision), you can do the following.

  • Go to the Materials panel → States tab and check the Ambient light box. With this option, leaves will be rendered only once rather than redrawn multiple types. However, only one world light is possible in this case (it does not apply to other types of light sources).

  • If the scene is GPU-bound (in the performance profiler, the Present counter value is high), decrease the empty space on leaf textures. The fill rate increases when multiple overlapping alpha blended polygons need to be rendered. If leaves cover most of the polygon, it helps lessen the GPU load and draw trees faster.
  • To increase the depth buffer precision, if necessary, increase the camera's near clipping plane distance. Go to Tools panel → Camera tab and increase Near clipping to 0.3 units.

Last update: 2017-07-03
Build: ()