sizeGradient bug where the factor is used as outright value rather than as a multiplier on initialSize

This is my first post so I would like to say hi and that I love what you guys have done with babylonjs. I am a big fan of it.

I would like to raise a bug related to sizeGradient.

According to the documentation:

To add a size gradient just call the following code

particleSystem.addSizeGradient(0, 0.5);

The first parameter defines the gradient (0 means at the particle birth and 1 means at particle death). The second parameter is the factor to apply to particle initial size.

In reality the value of the sizeGradient is used as the size rather than a multiplier/factor on the initial size.

Below is a repro:

In the playgroud, the sizeGradient’s factor is set to 1 from birth to death which should have no influence on the size. But try and comment out the line On line 58, 59 and one would see that is not the case.

We can see that in particleSystem.ts

/src/Particles/particleSystem.ts (sorry can’t post a github link because a new user has link limitations)

line 1341 to 1353

        // Size
        if (!this._sizeGradients || this._sizeGradients.length === 0) {
            particle.size = Scalar.RandomRange(this.minSize, this.maxSize);
        } else {
            particle._currentSizeGradient = this._sizeGradients[0];
            particle._currentSize1 = particle._currentSizeGradient.getFactor();
            particle.size = particle._currentSize1;

            if (this._sizeGradients.length > 1) {
                particle._currentSize2 = this._sizeGradients[1].getFactor();
            } else {
                particle._currentSize2 = particle._currentSize1;

if _sizeGradient is defiend, it does not randomise particle based on minSize and maxSize at birth.

Similarly in line 364, it does not take into account the minSize or maxSize.

Please let me know if my understanding is correct and if you would like me to propose a bug fix.

Thank you!


This seems to be either an error in documentation or a bug in the system.

At the beginning I was tending to the latter (bug in the system), but seeing this line - Babylon.js/particleSystem.ts at master · BabylonJS/Babylon.js · GitHub

It seems like the description of what the “factors” are doing is incorrect. I will wait for someone wiser in the secrets of particle-system to comment, but I think this is more of a wrong selection of variable name and documentation.

But, as always, I might be wrong (Edit - I wasn’t, see down :wink: )

1 Like

Yes @RaananW is right, the sizeGradient does not apply a multiplicator to the original size but IS the original size.

Do you want to send a PR to fix the doc?

@RaananW @Deltakosh Thanks for the response I have created a PR.


Merged, thank you very much!