- Home /
Particle based fluid simulation optimizations help
Hi, I am implementing a 2D particle based fluid simulation, got it mostly working but the performance was horrible. This was expected as I was making a quick prototype.
The first prototype used a gameObject for each particle which a circle collider and to find the neighboring particles I used Physics2D.OverlapCircleAll. Using the physics engine like this was VERY slow. I could only get around 80-100 particles before the framerate crashed under 10fps.
Then after doing some research to optimize it, I used a spatial hash to keep track of the particles and find the neighboring ones. Then to render it I used unitys ParticleSystem.
I still have issues. I then ran timers for each of the methods and it yielded this
No Particles: 552
ApplyExternalForce :0
ApplyViscosity :1
AdvanceParticles :0
UpdateNeighbors :13
DoubleDensity :6
WorldCollide :0
ParticleRender :0
UpdateVelocity:0
with a total of 20ms for the all the calculations. BUT the frame time shown in the stats window at the same time had a time of 361 ms. And even turning the rendering off for the particle system has no real effect. Even commenting out the code that applies the particles to the particle system has no effect. The system stays relatively stable but around the 500 particle mark there are massive decreases very quickly going from 40-50 fps to 2-5 fps in less than a second.
The particle renderer used the default shader and sprite, only gameobjects in the scene is the particle manager and the main camera.
This is a big improvement but the algorithm I implemented was for mobile devices and ran over 3000 particles on a single thread.
Can anyone tell me why there is such a slow down here or any advise on the matter?
Regards
Your answer
Follow this Question
Related Questions
Non-convex mesh collider vs box collider perfomance 0 Answers
Performance issue with code 0 Answers
Working On A Sudo Fluid System 1 Answer
Spacedust - Change specific particles 1 Answer
How do I get my game to run faster? 4 Answers