Using the ParticleBlinkScript Node

The ParticleBlinkScript node is similar to the BlinkScript node, but instead of working on images, it works on a particle system. It is a particle node which lets you write a Blink kernel to modify the particles, allowing custom behavior that can’t be achieved with Nuke’s built in particle nodes.

To use the ParticleBlinkScript node, connect it to a particle system in the same way as any other particle node.

Note:  For a full breakdown of the ParticleBlinkScript node Properties, see ParticleBlinkScript in the Reference Guide.

A simple example of a ParticleBlinkScript node graph

In the ParticleBlinkScript Properties tab, in the script section, write a Blink kernel to modify the particle attributes. Declare each attribute you want to read or write as an Image. The node binds each Image you declare in your kernel to the particle attribute of the same name.

For example, if you want to modify particle positions, declare an Image called p_position. All particle image names must start with the prefix p_.

Note:  The prefix is removed before matching with an attribute name. The reason for the prefix is that there are other types of special image which can be declared (see below).

Blink Kernel Example

Nuke has a ParticleDrag op which multiplies the velocity of each particle by a drag coefficient. The following is an example Blink kernel which does the same.

kernel ParticleDragKernel : ImageComputationKernel<ePixelWise>

{

// Declare images for the particle attributes we're interested in

Image<eRead> p_startTime;

Image<eReadWrite> p_velocity;

param:

// Declare parameters

float _drag; // This will be a knob for the drag factor

float _dt; // The time step for the kernel

float _endTime; // The particle system time at the end of the step

void define() {

defineParam(_drag, "pa_drag", 1.0f);

defineParam(_dt, "_dt", 1.0f);

defineParam(_endTime, "_endTime", 1.0f);

}

void process() {

// Work out the time step for this particle

float dt = max(0.0f, min(_dt, float(_endTime - p_startTime())));

// As this is a drag force, it's more accurate to give it exponential decay over dt. For other forces, we may just want to multiply by dt.

float t = pow(1.0f-_drag, dt);

p_velocity() *= t;

}

};

An Image is declared for the particle velocity attribute, p_velocity. In this case, the Image is going to be read and written so it must be declared as eReadWrite. In this kernel, the Image has a width of 1, and a height of the number of particles in the particle system.

Note:  Often it is only necessary for an attribute to be read, in which case it can be declared as eRead.

There is a single parameter, pa_drag, and the velocity is multiplied by the drag in the process() method. Nuke calls the process method once for every particle.

Note:  The prefix pa_ added to the drag parameter name is not essential, but is good practice as it prevents name clashes when ParticleBlinkScript creates knobs for the kernel parameters.

For more information, see Nuke's Help menu under Documentation > Guide to Writing Blink Kernels or navigate to: https://learn.foundry.com/nuke/developers/15.1/BlinkKernels/

Warning:  ParticleBlinkScript is very flexible, as there are no restrictions on the code you can write within a kernel. As a result, code compiled from the Kernel Source can cause Nuke to crash, so please use caution!