Instancing and Procedural Motion · Chapter 5 of 9

Instancing: Layers as Data

Written for version 2.7.0

A layer is a picture the editor redraws every frame, and an Instancer can read it: build a data layer, look at what it sees, sample it once per copy, and turn colour into height, place, turn or visibility.

The last chapter moved copies with Sin and the clock, and ended on what that cannot do: uneven, drifting patterns. This chapter fetches them from outside the graph. A layer is a picture that the Rig Editor paints again on every frame. An Instancer can read that picture, one spot for each copy, and use the colour it finds as a number. The Shaders path used layers for how things look. Here a layer is used as data.

Why a picture

The Instancer FX graph is worked out on plain numbers, once per copy. It has the clock, the Instance nodes and the maths, and no Noise, Gradient or Checker: those belong to graphs that paint pixels. A picture closes the gap. Anything that can be painted, moving or still, becomes something the copies can read.

  • A layer's Shader FX graph can paint any pattern from the Shaders path, and move it.
  • Nodes of the model can be drawn into a layer, so copies can react to where things are.
  • An image texture can stand in for a layer when the pattern never changes, such as a map of where copies should stand.

Make a data layer

Tap + beside Layers and select the new layer: the viewport shows its picture, empty so far. In its panel give it a name, a small Custom render target and a Color background. The picture is now a texture named Data Target.
  1. In the Selection Panel, under Rendering, tap + beside Layers. A layer named Layer appears above Main.
  2. Tap it. It becomes the working layer, and the viewport shows its picture in place of the model.
  3. In the detail panel, change its name to Data.
  4. Under Render Target, tap Custom and type 64 for Width and 64 for Height.
  5. Under Background, choose Color.
  • Every layer has a texture named after it: the layer's name followed by Target. Rename the layer and the texture follows. Data Target can now be chosen wherever a texture is chosen, such as the Texture menu of a Texture Object node.
  • Small is right. The Instancer reads one spot per copy and blends between neighbouring pixels, so the picture needs little more detail than the copies have rows. 64 by 64 is plenty for a field 16 copies wide. Width and Height run from 16 to 4096.
  • Color makes the picture solid. With a Transparent background and nothing drawn on it a layer is empty everywhere, the graph a layer starts with keeps it that way, and an empty picture reads as black.
  • Leave Clear Each Frame on, so each frame starts from the background and not from the frame before.
  • To see the model again, tap the radio beside Main in Layers. Tap the Data row whenever you want to look at the picture.

Three ways to fill it

Its Shader FX graph

The Data layer's Shader FX graph. Gradient wired into Layer Output is a still ramp, 0 on the left and 1 on the right. Scroll Coords into Noise is a pattern that drifts. The viewport shows the picture.
  1. With the Data layer selected, scroll the detail panel to Post FX Passes and switch Shader FX on. The layer's graph docks under the viewport, with Layer Source wired into Layer Output.
  2. For a still pattern, add a Gradient, Checker or Noise from Procedural and wire it into Color on Layer Output.
  3. For a moving one, add a Scroll Coords from Coordinates and wire it into the pattern's UV.
  4. Leave Opacity wired to Alpha on Layer Source.
  • A grey pattern puts the same number in red, green and blue. One use needs no more than that.
  • Scroll Coords moves the coordinates by Speed every second: X across the picture, Y down it. Noise and Checker scroll for ever. A Gradient is a single ramp, so it suits a still picture best.
  • The Shaders chapters on patterns, noise, time and Layer FX cover everything this graph can do. Whatever it paints, the Instancer can read.
  • A picture made only by this graph ignores the layer's camera. The pattern fills the target whatever the camera sees.

Nodes drawn into the layer

A layer also draws the nodes that are on it, seen through the layer's camera. Put a node on the Data layer and its shape lands in the picture, and moves there when the node moves.

The Ball's Rendering section lists the layers it draws on. Add it to Data and the layer's camera, looking straight down, draws it into Data Target. Move the Ball and its mark in the picture moves with it.
  1. Select the node. In the detail panel, under Rendering, tap + beside Add to Layer and choose Data. Data joins the list below.
  2. To keep the node out of the main picture, tap the red minus beside Main.
  3. Make a camera that looks straight down. Tap Top in the axis views, then tap Add Current View under Cameras in the Selection Panel. Select the new camera and set its Projection to Orthographic.
  4. Select the Data layer and, under Point of View, choose that camera in the Camera menu.
  • Left on its first setting, the layer's camera follows the view you are working in, so the picture would change every time you orbit. A saved camera keeps it still.
  • Orthographic has no perspective: a step across the ground is the same step across the picture everywhere. Ortho Scale sets how much ground the picture covers.
  • A node looks in the picture as it would in any render: its material, lit by the layer's lighting. A bright node over a dark Background gives a clear mark.
  • The nodes draw first and the Shader FX graph then works on the result, so the graph can blur or reshape what the nodes drew. Layer FX in Depth, in the Shaders path, covers those nodes.
  • A later chapter uses this to make copies react to objects that move among them.

An image texture

When the pattern never changes, skip the layer. Any image texture in the model is read in exactly the same way: a map painted elsewhere and imported, white where copies should stand. A still map, further down, shows one at work.

Read it: Texture Object and Sample Texture

Make Main the working layer again, select the node that carries the Instancer and open its Instancer FX graph. Two nodes read a picture. Texture Object, in Parameters, says which picture. Sample Texture, in Texture Processing, reads a colour from it at a place.

Texture Object holds Data Target and Sample Texture reads it. With nothing wired into UV every copy reads the top left corner, and all the bars are one height. With Grid's U and V each reads its own spot, and the bars take the shape of the picture.
  1. Add a Texture Object. Select it and choose Data Target in its Texture menu.
  2. Add a Sample Texture and wire Texture Object into its Texture input.
  3. Add a Construct Vector2 from Channels. Wire U from Grid into X and V into Y.
  4. 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. U runs across and V runs down, so the top row of the picture is V 0.
  • Grid's U and V run from 0 to 1 across the copies, so the whole grid is laid over the whole picture: the first row of copies along its top edge, the first column down its left edge.
  • With nothing wired into UV, Sample Texture reads 0, 0, the top left corner, for every copy. All of them get one value and move as a block. If a field acts as one, look here first.
  • With no texture chosen, Sample Texture gives plain white: 1 in every channel.
  • A layer's picture does not repeat. A place past an edge reads the pixel at that edge.
  • Copies need not be in a grid. Any two numbers between 0 and 1 serve as UV: a copy's X and Z, fitted with Remap, lay the picture over the ground the copies stand on.
The small framed picture

The yellow framed picture marked Data Target is drawn on this page to show what the layer holds while the model is on screen. The app has no such window. To look at a layer's picture, tap its row in Layers.

Use what it reads

Sample Texture gives a Color, three numbers between 0 and 1, and an Opacity. Split Vector, from Channels, takes the colour apart: X is red, Y is green and Z is blue. A grey picture has the same number in all three, so X is enough. That number is rarely in the range you want. Remap, from Math, moves it: leave In Min at 0 and In Max at 1, and set Out Min and Out Max to the range you need.

Three fields read the same drifting noise. The first sends it into Y of Scale, the second into Y of Position, and the third straight into Visibility, where a copy that reads less than 0.5 is not drawn.
Wire the number intoThroughYou get
Y of ScaleA Remap to a range such as 0.15 to 2.2A landscape of bars, tall where the picture is bright
Y of PositionA Remap to a height such as 0 to 1.6A surface that rises and falls with the picture
VisibilityNothingA mask: a copy is drawn where it reads 0.5 or more
X or Z of Rotation (deg)A Remap to a few degrees either way, such as -15 to 15A lean that follows the picture. The next chapter is built on this
  • Scale and Position take three numbers. Put yours in one axis of a Construct Vector3, with 1 in the other two for Scale or 0 for Position.
  • To move a mask's threshold, shift the number before Visibility. A Scale And Offset with Offset 0.2 lets more copies through.
  • A hidden copy keeps its number and its place in the grid, so a mask never shuffles the copies that remain.
  • As the picture moves, so does everything built on it. Nothing in this Instancer FX graph reads the clock: the motion is all in the layer.

Two channels, two jobs

The layer paints one noise into red and another into green. Split Vector takes them apart: X, through a Remap, sets each plank's height, and Y, through a second Remap, sets its turn about Y.
  1. In the layer's Shader FX graph, build two patterns. Wire one into X and the other into Y of a Construct Vector3, and that into Color on Layer Output.
  2. In the Instancer FX graph, wire Color from Sample Texture into a Split Vector.
  3. Wire X into a Remap with Out Min 0.15 and Out Max 2, and that into Y of the vector going to Scale.
  4. Wire Y into a second Remap with Out Min -80 and Out Max 80, and that into Y of a Construct Vector3 going to Rotation (deg).
  • One picture can carry three separate patterns, in red, green and blue, for a single read.
  • Two channels wired into X and Z of a Position make a flow: every copy is pushed along the ground by its own spot of the picture.
  • Opacity is the picture's own alpha: 1 where the picture is solid and 0 where the layer is empty.

A still map

An image texture in place of a layer. With no texture chosen Sample Texture reads white and every copy is drawn. Choose the map in the Texture Object's Texture menu and, wired into Visibility, it decides where copies stand.
  • The Texture menu lists the model's image textures and every layer's Target together.
  • An image's colours are read in linear light, like every colour in a graph. The grey in the middle of this map is stored as 0.5 and reads as about 0.2, so no copy stands there. Paint masks in black and white, or move the threshold.
  • An image texture follows its own Wrap X and Wrap Y, set on the texture's panel, outside 0 to 1. A layer's picture always stops at its edge.

What to expect

WhereWhat the copies read
The Rig Editor viewportThe picture the layer finished one frame earlier. With slow patterns this cannot be seen
Rendered framesThe picture of the same frame. The layer is drawn first, then the copies are worked out
The Ray Traced previewOne moment, held while the picture refines. Motion that comes from a layer does not play there
  • Values are linear. The number a layer's graph writes is the number the Instancer reads: 0.5 in, 0.5 out, in 256 steps.
  • The cost grows with the size of the target. The picture is painted and handed to the Instancer on every frame, so keep it as small as the copies need.
  • A picture is flat. Everything above one spot of the ground reads the same value, whatever its height.
  • For a picture made only by a graph, Background must be Color. A see-through, empty layer reads as black.

That is the whole mechanism: paint a picture, read it once per copy, fit the number to a range, and wire it into the transform. The next chapter puts it to work on one thing from start to finish, a field of grass leaning in a drifting wind.

Something unclear?

Tell us what the layer's picture looked like, which texture the Texture Object held, and what the copies did instead. Screenshots of both graphs help.

Send Feedback