So in the docs GPU particles are mentioned , and webgl2 only and to use BABYLON.GPUParticleSystem.IsSupported
i guess then you use either constructor : BABYLON.GPUParticleSystem or BABYLON.ParticleSystem
but what about when we use your awesome tools to tweak particles systems in a scene at runtime and then save to json
Very strange the docs dont mention this method of loading i found online : ParticleHelper.ParseFromFileAsync
why am i using this :
In the docs you just have ParticleHelper.CreateAsync and keep speaking about ParticleSystemSets, that requires some forced file system hierarchy and weird naming convention , talking about type , which is actually the file name and unrelated to any property in the json, its rather convoluted - when i tried it on my exported particle json , it didnt work
BUT the unmentioned ParseFromFileAsync does work , easy peasy
So now onto the question of the post … how do i know if this function returns CPU or GPU particles?
i would have loved to see an example in the docs using a json file exported from the inspector. The code example would have the conditional for webgl2 and would create CPU or GPU particles and loading the json for configuration.
For those in the know its like 4 or 5 lines of code i imagine… for the rest of us its a guessing game.
I can help with the question about which system is created but I’m not sure what doc changes might be needed… So ParseFromFileAsync and ParseFromSnippetAsync have a boolean parameter called gpu which determines which type of particle system is created.
For example you can could pass the property GPUParticleSystem.IsSupported for this parameter to create a GPUParticleSystem when it’s supported and otherwise create a ParticleSystem as a fallback. The particle systems aren’t always the same thou so you might have to tweak them after loading or make sure to create one in a way that works the same for both types of systems.
For example on this PG if you set the PG to use WebGL then it will create a ParticleSystem and if you set the PG to use WebGL2 then it will create a GPUParticleSystem instead.
Weirdy the systems does not behave the same… when I passed in true for gpu particles i saw nothing on screen , they were inside the hul of the model , basically the lifetime max was the issue. i had to drastically increase it , then i noticed the count was at maximum 10000 , changing the emission rate does nothing, it was on 100 , i changed it to 2, and the count remained 10000 .
maybe only a fault from the inspector , i will still test it with code later. but something is not right here?
There are some limitations with the GPU particle systems (see the doc) and sometimes they behave differently than the CPU particle system (see GPUParticleSystem EmitRate Zero Bug for your problem with the emission rate), so sometimes you can’t simply switch from one to the other, you may need to adjust some parameters in the process.
ok thanks I see , but since the rate cant be changed this means actually i cant update the effect after the json loads , so ideally i need two different json files , one set up for GPU and another for CPU , then let the IsSupported boolean also affect which file i load and not just the argument for what system to create.
That limitation can sometimes be worked around to create similar systems from the same saved system by simply setting activeParticleCount or capacity appropriately.
For the system in the above PG for example, based on emit rate and lifetime properties, the ParticleSystem only needs/uses 10 particles so I set the GPUParticleSystem to use only that amount as well. That’s why if you try the playground in both WebGL and WebGL2 modes it should look about the same.
With your system it might not be so easy to make it behave similarly for both types but if you get stuck and post a PG we can try to help with it.
(Yawn and I need to remember to finish waking up before I reply so I don’t need to make so many edits LOL )