Skip to main content
Houdini tips

Houdini quick tip: Control particle birth rate with a point attribute

By November 6, 20182 Comments

You can control a POP Source’s birth rate using an emission attribute, but it only works with primitive attributes, not points. Bit of a pain. Often I just want to birth from a single point – but I want to leave the door open to adding more sources later, so using the POP Location node is a bit limiting.

Turns out the POP Source node is actually not too tricky to understand – unlock it and dive in. You’ll find a Solver SOP: dive in there, and you’ll see how particles are birthed. Awww.

The wrangle you need to tit about with is here:

It’s called attribwrangle1, and it’s just above the “random_points” null.

Here’s its existing code:

#include <voptype.h>
 #include <voplib.h>

int npts = ch("npts");
 int seed = ch("seed");
 float frame = ch("frame");
 int firstpointcount = ch("firstpointcount");
 int firstprimcount = ch("firstprimcount");

for(int i = 0; i < npts; ++i)
 {
  float r = rand(vop_floattovec((float)i, frame, (float)seed));
  int sourcept = (int)(r * firstpointcount);
  sourcept = clamp(sourcept, 0, firstpointcount-1);
  int newpt = addpoint(geoself(), sourcept);
  setpointattrib(geoself(), "sourceptnum", newpt, sourcept);
 }

 for(int i = 0; i < firstprimcount; ++i)
   removeprim(geoself(), i, 0);
 for(int i = 0; i < firstpointcount; ++i)
   removepoint(geoself(), i);

It works by taking the total number of points that are supposed to be birthed this frame and spreading it randomly across the source points. But we want to go through all the source points, read the @birth attrib, and birth that many particles on the point. So replace the bold bit with this new code:

for(int sourcept = 0; sourcept < firstpointcount; ++sourcept)
{ 
 for (int j = 0; j < point(geoself(), "birth", sourcept); j++) {
 int newpt = addpoint(geoself(), sourcept);
 setpointattrib(geoself(), "sourceptnum", newpt, sourcept);
 }
}

To test it:

  • Set the emission type to “Points”
  • Ensure there’s a point attribute called i@birth on the points being fed into the POPNet
  • Now, every frame, each point will birth @birth number of particles. Ta-da. You can drive the @birth attribute any way you like – even just using noise makes for some sexy effects.

Note that the Constant and Impulse birthrates are now ignored. For tidyness, you ought to do some more tidying up to the node, and perhaps create a new HDA – but this’ll do for now.

A super-quick test (and hey, gotta love the new Attribute Noise SOP – saves having to build a VOP net every time):

That attribute wrangle above the popnet just says

i@birth = int(10.0 * @Cd.r);

Animating the birth rate on a per-point basis is now super easy. And yep – you can do something similar-ish using primitive / surface emission attributes, but this gives you a whole world of different looks, and, for me at least, much easier control. I love point-based emission. Fireworks, here I come

2 Comments

Leave a Reply