Skip to content

Wind on Grass and Trees in Unity URP

Wind on a mesh is done in the vertex shader. Each vertex is pushed sideways by an amount that grows with its height, so the base stays planted and the tips move. The amount comes from a noise that scrolls across the world, which keeps two plants a few metres apart out of step and lets a gust visibly cross a field.

A patch of grass and a tree from the 3D Shader demo under one Wind Controller. Wind Force rises from 0.3 to 1.4 and back: the grass sways harder and gusts cross the patch out of step, while the tree's trunk stands still and its crown leans

Three parts, in any wind shader:

  • A mask that says how much each vertex may move. The usual one is height in the mesh’s own space: 0 at the base, 1 at the top. Painted vertex colours are the other common mask, for leaves that flutter on a trunk that holds still.
  • A wind value that changes over time and place: a sine wave, or better, a noise texture sampled at the vertex’s world position and scrolled.
  • A direction, one for the whole scene or one per axis.

The vertex moves by mask × wind × strength along the direction. Nothing about it needs a physics engine or a script per plant, which is why a whole forest can sway for the cost of a few lines in the vertex shader.

In a Lit or Unlit graph, in the Vertex stage:

  1. Position in Object space, its Y (the G of a Split) through a Remap from your base and top height, a Height Range property, to 0 and 1, then a Saturate: the height mask.
  2. Position in World space, X and Z, divided by a size, plus Time times a speed: the noise coordinates. A Simple Noise or Gradient Noise at those coordinates, with the noise node’s Scale set to 1 so that Size alone decides how far apart the gusts are, minus 0.5 so it pushes both ways: the wind value. Left at Simple Noise’s default Scale of 500, the wind changes every few millimetres.
  3. A second noise at the same coordinates plus an offset (17, 9 here) for Z. The two winds into the X and Z of a Vector 3, its Y at 0 so nothing moves up or down; that times the mask times a Strength property, added to the object space Position, into the Vertex stage’s Position.
The Lit graph's vertex stage: object Position's Y through Remap by Height Range and Saturate for the mask; world Position's X and Z divided by Size, plus Time times Speed, into two Simple Noise nodes at Scale 1, the second offset by 17, 9, each minus 0.5 into the X and Z of a Vector 3 with Y 0; times the mask and Strength, added to object Position into Position. Below, Base Map times Base Color into Base Color

If the grass is single planes, set Render Face to Both in the Graph Inspector. Keep the strength small: the vertices move, the normals do not, so a strong bend shades like a straight blade.

The 3D Shader demo's grass mesh with this graph on it: the blades sway in a scrolling noise, each clump a little out of step, their bases still

Unity’s Wind Zone component moves trees made with Unity’s Tree Creator or with SpeedTree, through their own shaders, and the Particle System’s External Forces module. It does nothing to a plain mesh with a URP Lit material, or to grass made in a modelling program. For those, the wind has to be in the material’s shader, as above or as below.

Don’t own it yet? → Get it on the Unity Asset Store

Two parts: the Wind effect on each material that should move, and one Wind Controller in the scene that sets the wind for all of them at once.

The Wind Controller. Add it to any active GameObject and give it a Wind Noise texture. It starts empty, and without one the plants do not sway: in our test they leaned over to one side and stayed there. The demo’s is Demo/Textures/Wind_NoiseDemo.tif. Its fields, all explained on Wind Effect and Wind Controller:

  • Wind Force, 0 to 3, 1 by default: the overall strength.
  • Noise Speed, how fast the noise scrolls: the speed of the gusts.
  • World Size, 50 by default: how many metres one repeat of the noise covers. Plants much closer together than that move nearly together, and a gust is a wave across the field; lower it for more variety between neighbours.
  • Bidirectional Wind: on, the wind pushes both ways and plants swing; off, it only pushes one way and plants lean.
  • Use Wind Dir: on, the wind blows along the controller’s forward direction; off, it moves vertices on X and Z. It never moves them up or down.
A field of the demo's grass under the same wind at three World Sizes. At 1 every blade moves its own way and the clumps lose their shape. At 8 gusts roll across the field. At 50 the whole field sways together

The controller sends its values to every material each frame, so changing Wind Force from a script, for a storm, changes the whole scene.

The Wind effect, in the material’s Mesh Effects:

  • Attenuation, 0 to 1: this material’s share of the wind. Grass at 1 and tree trunks at 0.2 under the same controller is the usual set up.
  • Use Vertical Mask?, with Min Y and Max Y: the height mask, in the mesh’s own space. A vertex at Min Y does not move, one at Max Y moves fully, and one above Max Y moves even more. Below Min Y, version 2.8 keeps going the other way, so those vertices move opposite to the wind; from 2.81 they stay still.

The defaults are -1 and 1. A blade of grass whose base sits at height 0 still moves at its base with those, so set Min Y to the base: the demo’s grass preset, MAT_Grass, uses 0 and 1.

The demo's grass in the wind with no vertical mask, with Min Y at the default of -1, and with Min Y 0 at the base, where the blades stay rooted

Recalculate Normals, in the same Mesh Effects, makes the lighting follow the bend: it runs the wind again on two points next to each vertex and builds the normal from where they landed. It costs more in the vertex shader, and on thin grass it is rarely noticed; on a big tree whose crown leans far, it is.

The settings that change from one kind of plant to the next:

  • Grass: Min Y at the base, Max Y at the tip, Attenuation 1. Grass is short, so a lower World Size gives each clump its own sway.
  • Bushes: Min Y a little above the ground, so the stems near the soil hold, and Attenuation around half.
  • Trees: leave Wind off on the trunk’s material, so the wood never moves, and turn it on in the leaves’ material only, with Min Y at the bottom of the canopy and Max Y at its top: the leaves where they meet the trunk hold, and the top of the crown moves most. A low Attenuation, around 0.25 against grass at 1, keeps a big tree from swaying like a reed. Keep World Size large, around 50, so the whole crown reads nearly one value of the noise, and Noise Speed low for slow gusts. For a tree that is one mesh with one material, 2.81 holds everything below Min Y still, so Min Y at the top of the trunk keeps the trunk from moving; in 2.8 everything below Min Y moves the opposite way, so give the trunk its own material.
The demo's tree set as above: no Wind on the bark, Wind on the leaves only with Min Y at the bottom of the canopy, Attenuation 0.25 and World Size 50. The trunk stands still and the crown sways slowly as one, joined to the trunk, while the grass around it, at Attenuation 1, sways further

The mask is a straight line from Min Y to Max Y. For leaves that flutter faster than the branch they hang on, give the leaves their own material and mesh, with more Attenuation than the trunk.

The 3D Shader does not support Unity’s Terrain component, so trees and details painted with the Terrain tools do not take its materials or its wind. Place the plants as ordinary GameObjects, or with a scattering tool that places GameObjects, and the wind works on them; or keep Terrain’s own grass and its Wind Zone for the painted parts.

  • Move vertices up or down. The wind pushes sideways only, so a blade bends by leaning, not by shortening.
  • Work on Terrain trees and details.
  • Push plants away from the player. The wind comes from the noise and the controller only; there is no input for a character walking through.