About Flocking

LightWave’s flocking system is based on 3D computer models of coordinated animal motion, things like flocks of birds, herds of animals or schools of fish. It can be used with LightWave’s instancing system or HyperVoxels.

The flocking algorithm itself is based on just three principles in order to create this seemingly complex motion. These are Separation, which keeps your flock from getting overcrowded; Alignment, which keeps the flock all heading in roughly the same direction; and Cohesion, which is effectively the opposite of separation and keeps your flock bunched together.

Flocking can be seen in OpenGL and VPR. Instances and HyperVoxels controlled by Flocking can be motion blurred and use Depth of Field like other instances. Hypervoxels, like other volumetrics need the camera to be moving to be compatible with Photoreal Motion Blur (PRMB).

Flocking doesn’t currently work with negative frames.

When using Flocking with network rendering (LWSN, for instance) you must bake your Flocking results.

Using Flocking

In order to set up Flocking in LightWave you will need a flock and at least one director. This director can be a goal or something to avoid, meaning you can either lead or chase your flock. An effector can be as simple as a null object though you can attach a director to geometry - for instance, the leader of the pack or the nasty predator chasing the herd.

The director needs to move to excite the flock into movement of their own. Although an unmoving goal will draw the flock to it, it’s not very interesting behaviorally. It should also be stated that the behavior of the flock is completely deterministic, there is no fractal randomness here. A flock animated on one machine will work in exactly the same way on another, and more importantly will render the same too.

Setting up a Simple Flock

  1. We’ll start with an empty scene of 200 frames to which you add Flocking from the Windows menu, or the FX Tools tab.

  2. In the Flock Master window add a Generator . The defaults won’t give us a very interesting result, so change the following values:

    Count X : 10.0 Count Y : 10.0 Count Z : 10.0 Size X : 4.0 Size Y : 4.0 Size Z : 4.0

    This will give us a flock of 1,000 agents ready to fly.
  3. Add a Director - Goal to your scene and move it off in the distance. For this example ours is moved about 20 m in the Z. If you hit Calculate All Motions now and then Play on your timeline your agents will all head off to the goal, avoiding bumping into each other, but otherwise not interesting until they reach the goal, at which point they overshoot and try to reach it again, and again.
  4. So we’ll give them something to avoid. Add a Director - Deflect and change its Deflect Core and Strength to 5.0 and 3.0 respectively. Position it about halfway between your flock’s starting point and the goal. Hit Calculate All Motions again and you should get something like the image below:

To get the pretty colored trails for your flock, increase the Show Trails number. It represents the number of frames before and after the current one that will be shown.

Make sure you hit the Calculate All Motions button each time you make changes to your flock or directors before you press Play on the timeline again.

Overview of Controls

Flocking is composed of several custom objects all controlled through a central Master Window as we saw in the first simple example. You can always control your flock and directors through the Object Properties > Geometry > Custom Object window and your settings will be duplicated in the Master Window. For simplicity, this documentation will only describe the presentation of the settings through the Master Window interface.

This window has three main sections. Across the top we have two dropdown menus and the Calculate All Motions button. Down the left we have a familiar listview of all the flocking elements in the scene. On the right, the settings for each individual element broken down into tabs.

Menus

Items List

The listview on the left contains the following fields:

Generator/Director Cache Settings

Starting with the Cache tab since that is unique for all flock elements, this tab controls caching for the scene to make it less processor-intensive.

Director Properties


Directors are the Flocking elements that direct flocks. There are several choices to make when picking the type you want:

Goal and Avoid directors have the following options:

Deflect directors add a further option:

Path directors add one additional option to Goal and Avoid directors:

Arrive directors add two different additional options to Goal and Avoid directors:

Plane directors have no options.

Path Example

The Motion Path option for a Director gives you a lot of direct control over your flock, with a little bit of chaos as some fall out of the path you give them. It creates a very natural-looking path-following animation. Here’s a quick guide how it works:

  1. Set your scene to 600 frames and change your viewport to Top. Zoom out so you can see the whole width of the grid. Create a Null.
  2. Give it a motion path over 300 frames. To simplify our starting example make sure the path doesn’t get too close to itself over its course.
  1. In the Flocking Master window choose Add New... > From Scene Items > Director - Path .
  2. Set the new path’s resolution. You want it to follow the null’s motion path quite closely. Here we have set 24 steps.
  1. Now Clone the Path null twice and change the two clones animation paths. The fact that the frames used for the paths is the same does not affect how the paths work in Flocking.
  2. Add a Generator in the Flocking window. By default it comes in at the origin, which is great for our first path.
  1. Hit Calculate All Motions in the Flocking window and you should see that your scene isn’t long enough for the flock to get to the ends of both paths, but the fact they separate into two groups is nice.
  2. We have added a couple of Arrive directors to the end of the right path and a Goal to the end of the left path and made our flock massively larger. More paths could be added to further subdivide the flock and the goals are radius-limited to only capture flocks that fly nearby.

Generator Properties

There is a main section common to all Generator types that lists several important things.

There are four tabs for Generator Properties as follows:



Flocking Nodally

LightWave has nodes for more complex Flocking.

Example: Chasing a Flock

This example shows both predator/prey behavior in Flocking and nodal control for flocks. We’ll start with a new 600-frame scene and the new Predator-Prey entry on the Flocking Add New... menu.

  1. The default entries need some tweaking to get a more predator and prey-like setup. There are never as many predators as there are prey, so we’ll move the Generator away from the Origin and reduce our attackers to only X: 2, Y: 1, Z: 2. Likewise we’ll increase our prey flock to X: 10, Y: 1, Z: 10. You’ll need to increase the box size to X: 5, Y: 1, Z: 5 too. Lastly, we’ll change the Range on the Avoid Director to 8.0 to give the flock a chance to get away.


  1. We’ll add a hilly terrain with a subdvided, subpatched 100m 2 plane. Go into Object Properties and use a Displacement map to displace the terrain as you see fit. We used a simple Turbulence procedural set to 15 x 15 m and raised some 8.5 m.


  1. You need to tell Flocking that this terrain is your ground for the flock and their pursuers and you do that by adding a RayCaster to the terrain in Object Properties > Custom Object .


  1. Now, you need to tell Flocking to tell both your predator and prey to use the ground. Make sure Use Nodes is checked and go into the Node Editor from the Flocking Master window. Add a RayCastNode from the Additional group and take its Intersect output into the New Position input on the Agent Control destination node. Remember to do this for both generators.

  1. Hit Calculate All Motions in the Flocking window and watch your flock flee over the hills. Interestingly, once they reach the boundary of the terrain they “beam up” since the RayCastNode has no ground to put them on.

Using Objects as Goals or Avoids

Going into Object Properties on scene objects you can set any as Flocking items by visiting the Geometry tab and choosing Flock Director or Flock Generator. If you choose a Goal Director, Flocking will automatically deduce that you wish to use the polygons of your object as a goal, but you need to manually select Avoid Mesh if you wish for an object to become something to be avoided in your scene.