ParticleBlinkScript Attributes and Parameters

The following particle attributes are available within a ParticleBlinkScript kernel:

float3 p_position

The current position of the particles.

float3 p_initialPosition

The starting position of the particles.

float3 p_lastPosition

The previous position of the particles.

float3 p_velocity

The velocity of the particles.

float4 p_color

The color of the particles.

float3 p_size

The size of the particles.

float4 p_orientation

The orientation of the particles.

float3 p_rotationAxis

The rotation axis of the particles.

float p_rotationAngle

The rotation angle of the particles.

float p_rotationVelocity

The rotation velocity of the particles.

float p_mass

The mass of the particles.

float p_life

The lifespan of the particles.

float p_startTime

The start time of the particles.

All the particle attribute arrays are the size of the number of particles in the system, so you can pass as many as you want to a kernel and it will iterate over all of them simultaneously. This allows you to write kernels which can, for example, change particle color depending on velocity and position, or write new forces.

Creating Knobs in ParticleBlinkScript

Parameters can also be declared in a kernel. When using the BlinkScript node, parameter knobs are automatically created. The ParticleBlinkScript node works differently. The disadvantage of automatically creating the knobs is that you can’t choose what type of knob to create for a given parameter and you can’t set ranges for sliders or tooltips. A float3 attribute could require a Color_knob, or a XYZ_knob. Automatically generating the knobs also means that you have no control over the layout in the control panel.

ParticleBlinkScript instead uses User Knobs and binds them by matching their names to the parameters. If your kernel has a float4 parameter called pa_color, then an RGBA color User Knob called pa_color must also be created which will bind to the float4 parameter.

The ParticleBlinkScript method may take a little more time but is far more controllable.

Note:  If you don’t create a User Knob for a parameter, it is set to the default value. The Create Knobs button creates knobs for any parameters which don’t already have one. These can be removed, replaced and edited as much as needed.

Magic Attributes

In the kernel, it may be useful to have some extra information, such as the current frame. ParticleBlinkScript provides this if the attributes are defined with certain magic names. These are:

float _frame

The current frame Nuke is rendering.

float _systemTime

The current time of the particle system.

float _dt

The time delta for this frame.

float _startTime

The beginning of the time-step.

float _endTime

The end of the time-step.

All of these start with an underscore _ to distinguish them from p_ kernel attributes. The most common ones to use are _startTime, _endTime and _dt.

These attributes can be used together to get various information, for example:

_systemTime-p_startTime()

The age of a particle.

(_systemTime-p_startTime())/life()

The age of a particle as a proportion of its life.

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

The correct time delta for applying forces.

Note:  For more information on writing kernels for the ParticleBlinkScript node, refer to the Nuke Developer guide.

Image Inputs

As well as particle inputs, image inputs can be provided to a ParticleBlinkScript node which can be connected to nodes producing images. These must be declared with a name starting with image_, and with eAccessRandom, otherwise they are iterated in the iteration space of the particles.

For example, declaring an image called image_texture creates a new input called texture.

Example ParticleBlinkScript node with extra image input

The extra image inputs can be used to pass more data to the kernel, such as flow maps or height maps, and can be used for various purposes such as coloring particles by their position in the scene.