# Frustum Aligned Rendering Solution in VR with Unity’s Scriptable Rendering Pipeline – Part 5

## Implement details (Unity 2018.1.20f1)

### Vegetation Wind

After all the render pipeline upgrade work has been done, we encountered a new problem. All the vegetations the art team made with SpeedTree cannot be affected by wind now. Whether we remake the vegetation models or not, we need a wind solution.

The basic idea of moving vegetation is dividing it into several parts. For every part, we apply a kind movement based on its physical properties. At last, we add all the movements together to get the final animation. Let’s have a tree as an example for further explanation. We divide a tree into 3 parts: trunk, branches, and leaves. A trunk was only moved by the wind. Branches are moved by the trunk and wind. Leaves are moved by the trunk, the branches they belong to and also the wind. So the tree is like a hierarchical structure. From trunk to leaves, we compute movement of its own level and then add the movement of its parent levels. Finally, we apply all these movements to the vertex position to animate the vegetation mesh. Based on this idea, there are two major vegetation wind solutions now. One is simpler and the other is more complicated and accurate.

#### Simpler Solution

The simple solution for vegetation wind is generally based on the Crytek solution. We call it a simple solution because the data we need for this method is less and easier to compute.

We use a four channel vertex color(RGBA) in per-vertex data to represent the structural hierarchy of a tree:

A: The height of this vertex to the root/pivot of the tree (all parts);

B: The nearest distance from this vertex to trunk (only branches and leaves);

R: The nearest distance from this vertex to the branch it belongs to (only leaves);

G: A random number between 0 and 1 that all vertex belongs to a branch has the same value. Figure 1. Vertex color data of a tree in every channel

With the vertex color data, we can animate the vertices based on the four channel values:

1. Move all the vertices with the main wind force based on the stiffness parameter and multiply with the A value;
2. Move all the vertices with the main wind force based on the branch stiffness parameter and multiply it with the B value. The B value of trunk vertices are all 0 so only branches and leaves will be moved by this;
3. Move all the vertices with the main wind force based on the branch stiffness parameter and multiply it with the R value. The R value of trunk and branches vertices are all 0 so only leaves will be moved by this;
4. All the movements are driven by a sin function with a random number which has the G value as a seed to create some kind of randomize among different branches.

Three levels of the hierarchy are now enough for us. Other vegetations like bushes, grasses, etc. all have fewer levels than trees. Like the fern below, no trunk and alpha channel are needed actually. Figure 5. Vertex color data of a fern which has no trunk Figure 6. Vertex color datas of a scene full of vegetations

#### Accurate Solution

The simpler solution only keeps a distance information. All the movements are applied based on a simple periodic function and the distance. When the wind goes more drastic, the artifact became very obvious because we don’t have more accurate and detailed geometry information. Figure 7. Artifact of the simple solution when the wind is very strong

So a more physically based solution was found.  Rather than a simple distance for each hierarchy, this method compute the actual attachment position to its parent and the direction of current element. With these information, more complicated transformation can be achieved like rotating branch vertices away from the original direction around the attach point much more like the actual tree works. So this can handle the wind effects in a more natural way even the wind is drastically strong. And the Unity Book of Dead demo also use this method. All the datas are also stored in vertex datas.

So finally, we use the simpler method and carefully tweak the parameters to minimize the artifacts. The models made by SpeedTree are kept and reprocess them to the data from the first method. This process was completed by our TA team inside DCC tools.

### Wind Strength

In the physical world, the wind is a fluid phenominon. The actual wind strength varise at almost every single position. When it encounters objects, the situation become more complicated. So we should find a smipler way to simulate it.

Firt we have a global wind strength to control the main wind trend. The strength of the wind is controlled by a periodic function .

The average, gust strength, frequency can be adjusted with parameters. With this function, the inertia of the trunk can be approximated.

With only the main wind strength, all the vegetations inside the scene will have the same movements which exactly match the wind strength and appears very periodic (Figure 10). Figure 10. Only use the global wind strength results in a all the same movement

To add some random to the whole scene, we scale the wind strength with the world space position of every vegetation model.

Much better, huh? (Figure 12)

With all kinds of vegetations combined together, the result is acceptable for us now. Maybe we’ll switch to the more accurate method when needed.

## Future work

Till now, a basic usable render pipeline has been done. However, there are still a huge amount of work to do to complete a mainstream modern render pipeline:

• Area lights
• Decals
• More BSDF models
• Integration with Shader Graph, Visual Effecs Graph, etc.