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
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

Adding Grass

Learn the tips and tricks how to create an animated grass, swaying and moving as if with the wind. Your grass will also realistically vary in color across the field, so that it does not look unnatural like a freshly-painted lawn. More important, you will keep the framerate high when rendering all these polygons. No matter how big your grass field should be (the whole terrain? no problem!), the grass appears only around the camera. Basically, you need to tweak only two parameters to achieve optimum performance (if you can't wait, these are Density and Step).
As not to prolong this any further, here is a first tip: the grass looks better upon a hilly terrain. As for planes, low and non-dense grass would be a reasonable choice. Go ahead and be armed with knowledge!

Required Textures

The textures needed to set up the grass are the following:

  • Diffuse texture. It should contain 4 slots in a row and any number of such rows (here, for example, it is two rows). In our case, it will be colorless to use spatial coloring.

  • Spatial noise texture (RGB). It will cover the whole terrain and allows to color the grass differently in all locations. This texture is generated based on the terrain's diffuse texture colors. However, it does not have the same size as the terrain. For example, for the 8193 × 8193 terrain, 2048 × 2048 texture is enough.

  • Mask texture (RGBA8) that determines spreading of the grass across the terrain. This texture is generated based on the terrain's height map. For example, for the 8193 × 8193 terrain, the reasonable size could be 1024 × 1024.
    Notice
    This texture is not included into the SDK, so you have to create it yourself.

    Each channel of the mask (R, G, B and A) control if the grass from the 1st, 2nd, 3rd and 4th columns (respectively) is rendered or not. The grass will grow only across areas with a channel color value (here, the grass from all columns will be rendered where white color is):

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. Add Grass

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

    Drop the grass somewhere in the world:
  2. Press N to open Nodes settings. Rename the grass, if necessary.

  3. First of all, go to the Surfaces tab. Here, we will define the area of visibility for our future grass field. All the grass blades cannot be rendered all at once, especially, if the field is huge. Instead, they are going to be rendered in a small area around the camera.

    Set the Maximum Visible distance to 4 units. Within this distance from the camera all grass blades are visible.

  4. Set the Maximum Fade distance to 90 units. Over this distance the grass will gradually fade out according to the alpha channel value of its diffuse texture.

  5. Now we can safely set the real size of the grass field.
    Go to the Grass tab and set Size X (along the X axis) and Size Y (along the Y axis) to repeat the size of our 8193 × 8193 terrain.

  6. For now, increase Density up to 1.1, so that the grass is generated.
    We see a corner of our grass field appear and fade out up to the set distance (94 units).

  7. Make the grass a child of the terrain, so it can grow upon it repeating its relief: press ALT and drag the grass node to the terrain one.

  8. Check Intersection option to enable intersection with a parent node.

    Now the grass grows upon the terrain, but our field is obviously not positioned properly:

  9. Go to the Node tab and reset coordinates of the occluder to 0 relative its parent.

    Its position becomes the synchronized with the terrain:

Step 2. Set Up Grass Color

It's time to create material for the grass before tweaking its spread any further.

  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) grass_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.

  4. Click Assign material to apply it to the currently selected node — the grass, in our case.

  5. Let's adjust the material for our grass. Go to the Textures tab and load the diffuse texture.

    Notice
    You may want to manually edit the alpha channel of the mipmaps, because on automatically generated mipmaps thin blades may disappear incorrectly or unpleasantly.

  6. Select a path to the diffuse texture. You can use the following texture form the SDK:
    <Unigine SDK>\data\demos\heaven\textures\environment\grass_regular_d.dds

    The diffuse texture is now loaded, but the number of vertical columns is wrong:

  7. Go to Nodes settings -> Grass tab. Set the proper number of horizontal rows in diffuse texture in Num textures field. For example, we only have 1.

    As you can see, our diffuse texture is colorless:

  8. Go back to the Materials settings -> States tab. Check Color noise option. It will allow to color our grass blades differently across the whole field.

  9. Go to the Textures tab and load the Spatial noise texture.

  10. Select path to the color noise texture. You can use the following texture form the SDK:
    <Unigine SDK>\data\demos\heaven\textures\environment\grass_irregularity_d.dds

    The grass coloring appears to be off:

  11. Go to the Parameters tab. Double-click on the Noise Transform field. (Or you can modify the expression right in this field).

  12. Our color noise texture should cover the entire terrain. Set the scale by X and Y axes to 1.

    You can see patches of dark green, light green and yellow:

  13. The colors are too vivid to match the terrain ones. Decrease the Scale down to 0.35 to dim the color noise color.

  14. The blades are quite thin, so let's make them a little bit more transparent to light when it shines from behind.
    Increase the Translucency up to 0.6.

    The grass will become more transparent and lighter:

  15. Increase the Diffuse to 1.1 to brighten diffuse coloring of the grass.

  16. Go to the Common tab and disable shadows from the grass:

    The grass blends with the terrain smoother and that will allow us to make a denser looking filed:

Step 2. Set Up Grass Density and Spread

First of all, let's set up the density of the grass.

  1. Go to the Nodes settings -> Grass tab and increase the Step up to 15. It make the cells which are used to render the grass field larger, but not so large as to hit the performance when it is created.

    The grass is regenerated. The density also changed, because it is defined for one cell. As we made the cell bigger, it the grass turned out to be slightly more sparse.

  2. Increase the Density of the grass in a cell up to 2.5 to add more grass blades on the field.

  3. It's time to tweak the spread of the grass. Click to load a Mask image that will specify the areas where the grass grows.

  4. Select path to your mask texture, if any.

    The grass no longer grows on mountains peaks and stony areas:

  5. Decrease the Threshold down to 0.3 to lower the mask intensity.

    This will increase the area that the grass covers:

  6. Usually the grass does not grow on the steep hillsides.

    Increase the Angle up to 0.7 to make steep areas grassless.

    Now the spread of the grass is more realistic:

Step 4. Set Up Grass Shape

  1. When changing from bare areas to grassy ones, our grass starts to grow as small and thinned out. But on the stones it does not look too good:

    Increase the Min height up to 1.2. In areas with low density (according to the mask) the grass will be higher. You can set different height values for each of four columns in the diffuse texture, or leave it the same for all.

  2. Increase the Max height up to 1.2. of the grass blades up to 1.5 units. In areas with high density (according to the mask) the grass becomes higher. We'll use the same height for all four columns in the diffuse texture as well.

  3. We have set the mean value of the grass height. It is an average height that is randomized. As a result, higher and lower grass blades are randomly planted. However, the difference between the highest and the lowest is pretty big.

    Decrease Spread for Max height and Max height down to 0.1 units. It controls how blades can possibly vary in height. In our case, it will make the grass on the field more uniform in height.

  4. Check the Variation box, so that the grass blades from diffuse texture are flipped horizontally at random.

  5. From above the grass seems too flat:

    Go to the Materials settings -> Parameters tab. Increase the Slope up to 0.7 to make it more billboard-like.

  6. Grass blades are too thin and sometimes appear in dashed lines:

    Increase the Alpha up to 2 to make the blades look thicker and the grass denser.

Step 5. Set Up Grass Animation

  1. For now, set the Stem noise to 0 to make all the grass blades move uniformly. It will help to learn how to adjust the animation.

  2. Decrease the Stem offset down to 0.1 to make the grass sway and stretch horizontally to a lesser degree.

  3. Decrease the Stem radius down to 0.1 so that the grass does not bend down to the ground.

  4. Increase the Stem scale up to 2 to make the grass move two times faster.

  5. At last, increase the Stem noise up to 2 to make the blades movement more random.

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