Origin shifting and particle systems

Hi guys,

I’m developing a large world game that relies on origin shifting to avoid the floating point precision problem. However, my game involves the movement of ships which have a particle trail to simulate a boat’s wake. When I shift the origin, the particle emitters shift but the GPU particles don’t.

Is there anyway to force the particle system to reposition each particle relative to the emitter when the origin is shifted?

Here’s a PG:
https://www.babylonjs-playground.com/#PU4WYI#75

Unfortunately (and for perf reason) the particles when using GPUParticleSystem are not accessible by the CPU. So in your case I’m afraid you will have to rely on CPU particles and you will have to use a custom update function:
https://doc.babylonjs.com/how_to/customise#custom-functions

Why could we not just add an offset uniform for the whole GPU Particle system?

uniform vec3 globalOffset;

#ifdef POINTEMITTER
position = globalOffset;
#elif defined(BOXEMITTER)
position = (minEmitBox + (maxEmitBox - minEmitBox) * randoms2)+globalOffset;
#elif defined(HEMISPHERICEMITTER)
position = globalOffset + (radius - (radius * radiusRange * randoms2.z)) * vec3(randX, abs(randY), randZ);
#elif defined(SPHEREEMITTER)
position = globalOffset + (radius - (radius * radiusRange * randoms2.z)) * vec3(randX, randY, randZ);
#elif defined(CYLINDEREMITTER)
position = vec3(xPos, yPos, zPos)+globalOffset;

Well this is AN EXCELLENT idea! :smiley:
@Luan_Ngo: would that be good for you? I can add it if that works for you

I could add it as well, its fairly ezpz! Let me know what’s good cause we can make this happen. I even have time to do a PR today surprisingly…

please do!

Yes, that’s a great idea! Thanks for being so supportive, guys.

I got halfway done and realized I do not have any way to validate if it worked or not… I have never done my own build from my branch and am kinda intimidated to try.

Might be best if you do it Delta, pretty much just needs what already posted just in the right spots.

Also in the example:
https://www.babylonjs-playground.com/#PU4WYI#4

the emitter can move its position why would this not accommodate what @luan_Ngo is trying to do? Maybe I am missing something.

Hi Pryme, thanks for working on this.

I currently have the emitter moving with the ships (emulating a boat’s wake), but I sometimes have to shift the emitters and the particles so that my camera origin is kept at 0,0.

I changed your example (see line 50). Here, the emitter’s location shifted. And I’m hoping to have a feature that would shift the particles as well.

https://www.babylonjs-playground.com/#PU4WYI#76

Thanks again for your help.

https://www.babylonjs-playground.com/#PU4WYI#77

offset is defined on line 183 of the shader. Ideally it would be a uniform.

Issue created:

I will work on it this week!

Thanks for this guys!

https://doc.babylonjs.com/babylon101/particles#world-offset

2 Likes