Particle tips BreakOnProblematicParticle

From PopcornFX
Jump to: navigation, search

For PK-Fx Editor version : 1.5.3 and above
Main page: Particle tutorials


Sometimes, due to some expressions in scripts producing out of the ordinary numbers (like infinite numbers), some particles may have invalid properties (like infinite positions or colors).


Such particles are pretty hard to track by hand. If their position was still correct, you could, before v1.5.3, pick them by hand after pausing the simulation, and inspect their values.
However, particles with infinite positions were impossible to debug, and had to be tracked in code by developers.
Since Popcorn SDK 1.5.3, the PK-Editor now has the ability to 'pause on problematic particle'.


We'll start with a very simple rig without any evolvers, where particles are spawned randomly on a square:


Tips BreakOnProbl 01.png



Let's change that script to randomly produce some infinite values:

Tips BreakOnProbl 04b.png


We changed the color computation from float4(2, 1.5, 2, 1) to float4(2, 1.5, 4 / (1 + sign(rand(-0.01, 1))), 1)


This snippet does the following:

rand(-0.01, 1)

rand() has an uniform distribution : 1 time out of 101, the random value will be negative. (there is 1 part in the negative zone (-0.01), for 1 / 0.01 = 100 parts in the positive zone, therefore a total of 101 parts)

sign(rand(-0.01, 1))

sign() returns -1 if the input is negative, +1 if it is positive.
Therefore, 1 time out of 101, the value will be equal to -1.0, the rest of the time, it will be equal to 1.0.

1 + sign(rand(-0.01, 1))

1 time out of 101, the value will be equal to 0.0, the rest of the time, it will be equal to 2.0

4 / (1 + sign(rand(-0.01, 1)))

1 time out of 101, the value will be equal to 4 / 0.0 = +infinity, the rest of the time, it will be equal to 4 / 2.0 = 2.0, which was our original 'blue' channel in the original float4(2, 1.5, 2, 1) color.


Therefore, roughly once every 100 emitted particles, we'll have a 'buggy' particle with an infinite blue channel, producing an erroneous color.

Save the script, and in the 'TraceReport' window, click on the 'Pause if a problematic particle is found' button:

Tips BreakOnProbl 02.png


When this mode is activated, the particle editor will scan all the particles every single frame, and immediately pause the simulation as soon as it finds a particle which has a field containing an infinite or NaN number.
It will also select all the problematic particles found so you can inspect their values in the TraceReport panel:

Tips BreakOnProbl 03.png Tips BreakOnProbl 04.png



You can cycle through all the selected particles either by entering their ID in the first input-box, or by clicking the 'Go to next selected particle' button:

Tips BreakOnProbl 05.png



You can also make the editor automatically center the view on the currently selected particle, as they might not always be very visible:

Tips BreakOnProbl 06.png

Tips BreakOnProbl 08.png



And last, you can manually trigger a search for problematic particles whenever you want by clicking on the 'Select all problematic particles' button:

Tips BreakOnProbl 07.png