Custom Particle System in VEX

comments 6
Free Tutorials

Dobromir of Inlifethrill Designs asked us how we’d go about recreating this. And as I’m quite untalented with Houdini’s particle system, I turned to VEX to create this custom particle system in which individual particles attract each other.

EDIT: As Theo pointed out in the comments I made quite a severe coding mistake when iterating over all points for doing the physics sim.

This line in Pointwrangle2 in the solver:

for(int i = 0; i < @ptnum; i++){

should read like this:

for(int i = 0; i < @numpt; i++){

I fixed that error in this file.
Thanks Theo for pointing that out!

In this tutorial we’re going over the math and physics behind our particle system as well as the implementation of such a system in VEX.

I’m aware this might not be the fastest method of creatig such a system, so if you’ve got a more straightforward approach, we’d be thrilled if you share it!

Download Project File (.hipnc)

Download Project File – Physically implausible setup but funny results (.hipnc)

Liked it? Take a second to support Moritz on Patreon!

6 Comments

  1. Hi, many thanks for this tutorial with the previous one on pcfind. I was just wondering, at some point for the setup of the gravitational forces, you’re running the for loop with @ptnum as max number, but you’re not using all the particle system (@numpt). Why ?

  2. Very interesting….A few weeks ago I also used newton law as inspiration in order to practice custom forces in DOPs. With the idea of simulating a galaxy and making bigger particles absorb the smaller ones.
    You can see the video here:
    https://vimeo.com/188376689

    But the original inspiration were the fabulous em-newton by mootzoid:
    https://vimeo.com/35051275

    I did limit the scope of the gravity with a pcfind, so the particle only considered the closest particles + the sun. But the mayor issue I had with my system was that the particles never gained momentum to separate themselves from the sun.
    I think theoretically 2 bodies with initial velocity should never collide, right?
    I basically solve this issue by “turning off” the gravity of the sun for a while. But I always thought there was something to polish in that formula.

    I’ve let it go, as I was mainly practicing custom forces. But the 2 body orbiting each other problem has been tempting me for a while….
    Basically I wonder how to improve the gravity force to simulate something closer to what mootzoid did. Maybe the system lacks consideration of angular momentum. (dropping ideas for a future tutorial) 😉
    https://en.wikipedia.org/wiki/Elliptic_orbit

  3. hey Mo, loving this setup, been playing with it a lot and messing with the forces. One thing not sure if you could help me with is later in the sim, if I have a few last particles sprayed about, wanted to gradually scale them down so I’d be left with nothing. I guess could keyframe down the sphere scale, but tried adding this into a wrangle In the solver at the end. It’s strange, that at frame 130, the scaling seems to happen once, but after that has no effect at gradually scaling the pscale to zero (or close to)

    can you see anything obvious my bit of vex is doing wrong? I set the wrangle to run over points –

    f@time = @Frame;
    float psca = f@pscale;
    if(f@time >= 130.0 && psca > 0){
    psca -= 0.01;
    f@pscale = psca;
    }

    many thanks

    Kieran

    • Hi Kieran,

      as the last wrangle in the solver sets the pscale using each particle’s mass, the effect of setting pscale in a downstream wrangle directly will be overwritten in the next simulation step. Maybe this is something more akin to what you’re trying to pull off (use this in a last pointwrangle in the solver):

      if(@Frame >= 130.0 && f@mass > 0 && f@mass < .1){ f@mass -= .001; f@mass = clamp(f@mass, 0.0, 100000000.0); }

      Cheers, Mo

  4. Nathaniel

    Hi Mo,

    This is a fantastic tutorial–I’m having a lot of fun with it. I found that giving the particles a bit of random rotational motion as an initial a (rather than the constant {0,0,0} gives some really fun results, too.

    This is the line that I used to give it the initial motion
    v@a = (0.0175*rand(@ptnum + chi(“nseed”)))*cross(v@P, {0,1,0});

    Thanks for the fantastic tutorial, and the physics lesson!

Leave a Reply