Instancing and Procedural Motion · Chapter 6 of 9
Instancing: A Field of Grass in the Wind
Written for version 2.7.0
Procedural animation, step by step: a layer renders a moving noise into a small target, and the Instancer reads it as a few degrees of lean for every blade of grass.
This chapter builds one thing from start to finish: a field of grass that leans with the wind. Nothing in it is animated by hand. A layer draws a slowly moving noise into a small picture, the Instancer reads that picture once for every blade, and what it reads becomes a few degrees of lean. It uses the Instancer, Grid and Instance Random from the earlier chapters, and a layer used as data from the last one.
A layer as a picture the Instancer can read: render targets, Texture Object and Sample Texture.
1. The blade
Start with one blade. It can be very plain: the field is made of hundreds of them, and the eye reads the mass, not the blade.
- Add an Empty and name it Grass Field. It will carry the Instancer.
- Add a small flat mesh and shape it in Mesh mode into a thin blade: a narrow quad with a point on top is enough.
- Make sure the foot of the blade is on the node's origin. If it is not, put the 3D cursor at the foot and use Origin to 3D Cursor in the Origin section.
- Parent the Blade under Grass Field.
- The origin matters because every turn the Instancer gives a copy pivots there. With the origin at the foot the blade leans like grass. With it in the middle the blade would rock like a seesaw.
- Leave the Blade standing straight up, with no rotation of its own. That is its rest pose, and the wind will be added on top of it.
- A slight bend in the mesh, the tip a little forward of the base, catches the light better than a perfectly flat card.
2. The field
A grid of blades
- Select Grass Field and tap Add Instancer. Leave Count on Static and type 900.
- Tap Edit Instancer FX. Add a Grid from the Instance folder and set Columns to 30: 900 copies in rows of 30 makes a square, 30 by 30.
- Add two Scale And Offset nodes. Wire Column into the Value of one and Row into the Value of the other.
- On both, set Scale to the gap between blades, here 0.22, and Offset to minus half the distance from the first blade to the last, here -3.3, so the field is centred on the Empty.
- Add a Construct Vector3. Wire the first Scale And Offset into X and the second into Z.
- Wire the Construct Vector3 into Position.
| Grid output | What it carries |
|---|---|
| Column | The copy's place along its row: 0, 1, 2, up to Columns less one |
| Row | Which row it is in: 0 for the first Columns copies, 1 for the next, and so on |
| U | Column as a fraction, 0 at the first column and 1 at the last |
| V | Row as a fraction, 0 at the first row and 1 at the last |
- The number of rows is Count divided by Columns, rounded up. If Count is not a full multiple of Columns the last row is short.
- U and V are not used yet. They are what will tell each blade where it stands in the wind picture.
Breaking the grid up
A perfect grid looks planted by a machine. Three random numbers per blade fix that: a small shift, a small turn and a height.
- Jitter. Add an Instance Random. Multiply its Vector by a Construct Vector3 holding 0.22 in X and Z and 0 in Y, then Add the result to the grid place and wire the sum into Position. Each blade moves up to one gap, never up or down.
- Yaw. Wire the same Instance Random's Value through a Scale And Offset with Scale 50 and Offset -25, into Y of a second Construct Vector3, and that into Rotation (deg). Each blade turns up to 25 degrees either way.
- Height. Add a second Instance Random and set its Seed to 1. Wire its Value through a Scale And Offset with Scale 0.75 and Offset 0.6 into Y of a third Construct Vector3 whose X and Z are 1, and that into Scale. Blades run from 0.6 to 1.35 times their height.
- Value and Vector on one Instance Random are separate rolls, so the jitter and the yaw do not follow each other.
- The second Instance Random has its own Seed, 1, so its numbers are different again. Two Instance Random nodes with the same Seed give the same numbers.
- Every roll is between 0 and 1. Scale And Offset stretches and shifts it to the range you want: Scale is the size of the range, Offset is where it starts.
- The Seed field in the Instancer section reshuffles all of it at once.
Rotation turns a blade on the spot first and then tilts it in its own, turned directions. So a blade turned by 90 degrees leans 90 degrees away from its neighbour when both are given the same tilt. Keeping the yaw within 25 degrees keeps every lean within 25 degrees of the wind's direction, which reads as one wind. A full random turn would send each blade its own way.
3. The Wind layer
The Instancer FX graph has no noise node. Its nodes are worked out on plain numbers, once per copy, and the pattern nodes belong to graphs that paint pixels. A layer bridges the two: its Shader FX graph paints a noise into a picture, and the Instancer reads the picture.
- In the Selection Panel, under Rendering, tap + beside Layers. A layer named Layer appears above Main.
- Tap it. It becomes the working layer and the viewport shows its picture. Nothing is on this layer, so the picture is empty.
- In the detail panel, change its name to Wind. Its picture is now a texture called Wind Target.
- Under Point of View, choose a saved camera that looks straight down. To make one, tap Top in the axis views, tap Add Current View under Cameras, then select the new camera and set its Projection to Orthographic.
- Under Render Target, tap Custom and type 64 for Width and 64 for Height.
- Under Background, choose Color.
- The picture is small on purpose. The Instancer reads it one blade at a time and blends between pixels, and the field is only 30 blades wide, so 64 pixels is plenty. A smaller target is also cheaper: it is painted and handed to the Instancer every frame.
- Color makes the target solid. A layer with a transparent background and nothing drawn on it stays transparent whatever its graph paints, and the Instancer would read black.
- Leave Clear Each Frame on. The noise repaints the whole target every frame anyway.
- The camera does not change this picture: a noise fills the target whatever the camera sees. A fixed camera looking straight down matters as soon as objects are drawn into the layer, which the next chapter does, because it makes the target line up with the field.
A noise that moves
- With the Wind layer selected, scroll the detail panel to Post FX Passes and switch Shader FX on. The layer's graph docks under the viewport, named Wind · Shader FX, with Layer Source wired into Layer Output.
- Add a Scroll Coords from Coordinates and a Noise from Procedural.
- Wire Scroll Coords into the UV of Noise.
- Wire Noise into Color on Layer Output. Leave Opacity as it is.
- Noise gives every pixel a number between 0 and 1, in soft patches. As a colour that is a grey: dark where the number is low, light where it is high.
- Scroll Coords adds time, multiplied by Speed, to the coordinates. The patches drift across the picture without ever changing shape.
- This picture is all the wind there is. Everything after this point only reads it.
4. Reading the wind
Tap the radio beside Main in Layers to make Main the working layer again, so the viewport shows the field. Select Grass Field and open its Instancer FX graph. Two nodes read a texture: Texture Object says which one, and Sample Texture reads a colour from it at a place.
- Add a Texture Object from Parameters. Select it and choose Wind Target in its Texture menu.
- Add a Sample Texture from Texture Processing and wire Texture Object into its Texture input.
- Add a Construct Vector2 from Channels. Wire U from Grid into X and V into Y.
- Wire the Construct Vector2 into UV on Sample Texture.
- UV is a place in the picture: 0, 0 is the top left corner and 1, 1 the bottom right. Grid's U and V run from 0 to 1 across the field, so the field is laid over the whole picture, the first row along its top edge.
- With nothing wired into UV, Sample Texture reads the top left corner, 0, 0, for every copy. The whole field then gets one value and moves as a single block. It is the most common reason a field sways in unison.
- With no texture chosen, Sample Texture gives plain white: 1 in every channel, the same for every copy.
- The colour is read in linear light, the same numbers the layer's graph wrote. A Noise value of 0.5 is read back as 0.5.
- In the viewport the Instancer reads the picture the layer finished one frame earlier. For wind that cannot be seen. Rendered frames have the layer drawn first, so they read their own frame.
5. Turning colour into a lean
The colour is a number from 0 to 1. A lean needs to go both ways, so the number is moved to run from -1 to 1 and then multiplied by how many degrees a full gust should tilt a blade.
- Add a Split Vector from Channels and wire Color from Sample Texture into it. The noise is grey, so X, Y and Z all carry the same number. Use X.
- Add a Remap from Math. Wire X into Value and set Out Min to -1 and Out Max to 1. In Min and In Max stay at 0 and 1.
- Add a Float from Parameters, set its Value to 16 and type Wind Strength as its Label.
- Add a Multiply. Wire the Remap into A and the Float into B.
- Wire the Multiply into X and into Z of the Construct Vector3 that already carries the yaw in Y. That vector is now tilt, yaw, tilt, and it is already wired into Rotation (deg).
- This is a rotation delta: a small amount added on top of each blade's rest pose. At rest X and Z are 0 and the blade stands straight. The wind never sets the pose, it only nudges it by a few degrees either way, which is why the motion reads as subtle and not as blades being thrown about.
- X tilts a blade forwards and back, Z from side to side. Feeding both the same number leans the blade diagonally. For a wind along one axis only, wire one of them.
- To give blades a lean of their own as well, put an Add between the Multiply and the rotation and add a constant or a random number there. The wind still rides on top.
- The noise spends most of its time near the middle of its range, so most blades lean much less than Wind Strength at any moment. Only a strong patch passing over reaches it.
6. Tuning the feel
Three numbers decide how the wind feels, and they live in two graphs.
| Control | Where it is | What it changes |
|---|---|---|
| Wind Strength | The Float in the Instancer FX graph. It also appears under Instancer FX Inputs when Grass Field is selected | How far a blade leans, in degrees. Low is a breath, high is a gale |
| Scale on Noise | The Wind layer's Shader FX graph | The size of the gusts. A low number gives broad swells that move the whole field together, a high number small patches |
| Speed on Scroll Coords | The Wind layer's Shader FX graph | How fast the gusts cross the field, and which way: X for across, Y for front to back |
- Instancer FX Inputs lists every Float in the graph by its Label, so Wind Strength can be changed, by dragging up or down on the number, without opening the graph. A Float with no Label is listed as Float.
- Change Scale and Speed while the Wind layer is the working layer and you can watch the picture itself change. Then go back to Main to see the field.
- Slow, broad and gentle reads as a calm day. Speed is the first thing to raise for a storm, before Wind Strength.
- Speed can be negative. The wind then travels the other way.
7. Limits, stated plainly
- Each blade tilts as a rigid piece. It does not bend along its length. Bending needs a blade with bones, skinned, and Pose FX to move the bones in each copy, which a later chapter covers.
- In the viewport the lean is one frame behind the wind picture.
- The Ray Traced preview does not animate the field. It holds one pose while it refines the picture. Rendered frames follow the wind.
- A smaller render target is cheaper. If the wind looks blocky, lower Scale on Noise before making the target bigger.
- There is no noise node inside Instancer FX, which is why a layer supplies it. The same route works for any pattern a Shader FX graph can paint.
- The wind picture is flat and the same at every height. It knows nothing about the shape of the ground or what stands in the field. The next chapter adds objects that push the grass aside.
Objects drawn into the wind layer, so the grass parts around whatever moves through it.
Tell us which step you had reached, what the Wind layer's picture looked like, and what the field did instead. Screenshots of both graphs help.