Instancing and Procedural Motion · Chapter 8 of 9
Instancing: Trails and Memory
Written for version 2.7.0
A layer can remember: an object on a data layer leaves a mark that fades, and the grass it crossed stays pressed down and slowly stands back up.
An effector, from the last chapter, tells the field where something is. Take it away and the grass is up again in the same instant. A trail tells the field where something has been. It needs memory, and the Instancer FX graph has none: it works every blade out afresh on every frame. A layer does have memory, because a layer is a picture, and a picture can be kept from one frame to the next. This chapter adds a second data layer beside Wind, lets a Ball draw itself into it, and reads the marks it leaves.
Node Transform, Distance and a soft falloff, and masks from pictures.
1. A second data layer: Trail
The Wind layer holds a picture that a graph paints. The Trail layer will hold a picture of real things in the model, seen from straight above, so that a spot in the picture is a spot in the field.
- In the Selection Panel, under Rendering, tap + beside Layers and tap the new layer.
- In the detail panel, name it Trail. Its picture is now a texture called Trail Target.
- Under Point of View, choose the saved camera that looks straight down. The grass chapter made one: Top in the axis views, then Add Current View under Cameras in the Stage group, then Projection set to Orthographic.
- Select that camera and set its Ortho Scale to half the width of the field, 3.2 here, and its Target to the middle of the field, 0, 0, 0.
- Back on the Trail layer, under Render Target, tap Custom and type 128 for Width and 128 for Height.
- Leave Background on Transparent.
- The camera is what lines the picture up with the field. An orthographic camera looking straight down has no perspective, so the picture is a flat map. Ortho Scale is half the height of what it sees, and a square target is as wide as it is tall, so 3.2 frames a field 6.4 units across, edge to edge.
- Framed like that, Grid's U and V point at the right spot of the picture with no extra nodes: the first row of blades lies along its top edge, as it does for Wind.
- Transparent matters here. The picture is empty wherever nothing has been drawn, and its Opacity says how much mark there is at each spot. That is the number the Instancer will read.
- 128 pixels across 6.4 units is 20 pixels to a unit, enough for a ball. The Wind layer keeps its own small target: each layer has its own size.
Put the Ball on the layer
A layer draws only the nodes that are on it. So far nothing is on Trail.
- Select the Ball.
- At the top of the detail panel, in Rendering, tap the + beside Add to Layer and choose Trail.
- Trail is now listed under Main. The Ball is drawn in both.
- To look at the picture, tap Trail in Layers. The viewport shows the Ball from above on an empty background. Tap the radio beside Main to go back to the model.
- The grass is not on Trail, so it is not in the picture. Only the Ball is.
- The Ball is drawn with its own material and the layer's lighting. Its colour does not matter. What matters is that the picture is solid where the Ball is.
- The size of the spot is the size of the Ball as the camera sees it. A bigger node, or a flat disc under it, leaves a wider mark.
- A node can be on Trail alone. Remove it from Main with the red button on that row and it leaves marks without being seen in the final picture.
2. Memory
As it stands the layer forgets everything: Clear Each Frame wipes the picture before every frame, so it only ever shows the Ball where it is now. There are two ways to make it remember.
Keep everything
- Select the Trail layer.
- Under Render Target, switch Clear Each Frame off.
- The note under the switch changes to say so: the target keeps what it previously rendered and draws over it, and clears only when it is created or resized.
- Nothing fades. A mark stays until the picture is cleared. Changing Width or Height clears it, and so does switching Clear Each Frame back on.
- A layer's Shader FX graph cannot fade it. The graph reads the kept picture and writes its result somewhere else, so the kept picture itself is never changed. Multiplying by a little under 1 in the graph dims what you see this frame and nothing more.
- This is the mode for marks that should last: a path drawn by dragging a node through the field once.
Fade: the layer as its own background
For a mark that fades, the layer has to start each frame from a weaker copy of the frame before. A layer can do that by using its own target as its background.
- Switch Clear Each Frame back on.
- Under Background, choose Texture.
- A Texture row appears, set to some other texture. Tap it and choose Trail Target, the layer's own.
- Leave Fit on Fill.
- Drag Opacity down a little, to about 96%.
- Every frame now goes like this: the picture is cleared, last frame's finished picture is drawn into it at 96%, and then the Ball is drawn on top at full strength.
- A layer that reads its own target always gets the frame before. That is by design, and it is what makes this a memory and not a loop.
- Opacity is the fade, once per frame. At 96% a mark is down to about a third after 25 frames and about a tenth after 55. At 100% nothing fades and the picture fills up. At 90% a mark is gone in under a second.
- A fading mark also goes dark as it fades, faster than it goes transparent. Read its Opacity, not its Color.
- With Shader FX switched on as well, the background is last frame's picture after the graph. A graph can then spread or shape the mark a little more on every frame.
3. Reading the trail
Go back to Main, select Grass Field and open its Instancer FX graph. Reading Trail Target takes the same two nodes as reading Wind Target.
- Add a Texture Object and choose Trail Target in its Texture menu.
- Add a Sample Texture. Wire the Texture Object into Texture and the Construct Vector2 of Grid's U and V into UV, the same one the Wind sample uses.
- Add a Smoothstep. Wire Opacity from the Sample Texture into Value, and set Edge 0 to 0.15 and Edge 1 to 0.7. Its output is the mark: 1 on a fresh track, 0 where there is none.
- To flatten, add a Remap with the mark in Value, Out Min 1 and Out Max 0.15. Multiply the blade's height by it and wire the result into Y of the scale.
- To press the blades over, add a Float with the Label Press and the value 60, and Multiply it by the mark.
- Add an Add. Wire the wind's tilt into A and that Multiply into B, and wire the Add into X of the rotation.
- The wind is still wired in. In Z it is untouched, and in X the press is added on top, so pressed grass still stirs and standing grass sways as before.
- The Smoothstep is not decoration. The picture stores each value in 256 steps, and a slow fade cannot take a faint mark below a certain trace: about 0.05 at 96%, about 0.2 at 99%. Edge 0 sits above that trace so that an old track counts as no track.
- Edge 1 is where a mark counts as fresh. Lower it and the grass stays fully down for longer before it starts to rise.
- Press tips every blade the same way, forward. For grass that falls away from the track, combine this chapter with the last: the trail for how much, an effector for which way.
- If the track shows beside the Ball and not under it, the camera does not frame the field. Check its Ortho Scale and Target.
4. Tuning
| Control | Where it is | What it changes |
|---|---|---|
| Opacity, under Background | The Trail layer's panel | Recovery time. Nearer 100% the grass stays down longer |
| The size of the node on the layer | The node itself, or a disc placed under it | The width of the track |
| Width and Height | The Trail layer's panel | Detail. A small target gives a soft, blocky track, a large one a crisp edge. Changing it clears the trail |
| Edge 0 and Edge 1 | The Smoothstep in the Instancer FX graph | When a fading mark stops counting, and how long a fresh one holds |
| Press, and Out Max on the Remap | The Instancer FX graph | How far over and how flat the grass goes |
- The fade happens once per frame, so the same Opacity gives a shorter trail at a higher frame rate. Tune it at the frame rate you will use.
- Raise the target size only when the track looks blocky. A larger picture is more to draw and more to hand to the Instancer every frame.
- A trail is one channel of one picture. Two kinds of mark can share a field by using two layers.
Recipes
| To get | Build |
|---|---|
| The track of a rolling ball | This chapter as built: the ball on Trail, 96%, the mark into Scale Y and a lean |
| Footprints | A small flat disc on the Trail layer only, moved from step to step and scaled down to nothing between them. Each touch leaves a print that fades |
| A ripple that trails behind | Multiply the mark by One Minus of itself before using it. The result is strongest half way through the fade, so the blades react a moment after the object has passed and then settle |
| A path worn through a field | Clear Each Frame off and no background texture, and the mark into Visibility through One Minus. It lasts until the layer is resized or the model is closed |
It is tempting to make grass heat up or change colour where something has passed. The Instancer sets each copy's place, turn, size and whether it shows, and nothing else. There is no colour per copy. Show a trail with what there is: flatten, lean, shrink or hide.
Limits, stated plainly
- In the viewport the Instancer reads the picture the layer finished one frame earlier, so the grass answers a frame late. Rendered frames draw the layer first.
- The trail lives in the picture and nowhere else. It is not saved with the model. It starts again when the layer is created or resized, and when the model is opened. Just after that the picture may begin full and fade out over the first moments.
- The Ray Traced preview holds the field still while it refines. Rendered frames follow the trail.
- The camera looks from above and does not know height. A node floating over the field leaves a mark too.
- A slow fade never reaches nothing. The Smoothstep's Edge 0 is what hides the trace it leaves.
- The picture is as wide as the camera's view. Something that leaves the view leaves no mark.
Give the blade bones, and let a second graph bend every copy on its own.
Tell us how the Trail layer was set up: its camera, its size, Clear Each Frame and its Background. Say what the picture showed when you selected the layer, and what the field did. Screenshots of the layer's panel and the graph help.