# Particle System Performance

**URL:** <https://discourse.processing.org/t/particle-system-performance/8493>\
**Category:** Project Guidance\
**Created:** [February 17, 2019, 6:59pm UTC](https://discourse.processing.org/t/particle-system-performance/8493 "2019-02-17T18:59:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wqt](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/wqt/32/3546_2.png) [@wqt](https://discourse.processing.org/u/wqt)\
**Post date:** [February 17, 2019, 6:59pm UTC](https://discourse.processing.org/t/particle-system-performance/8493/1 "2019-02-17T18:59:50Z")

</div>

Hello everyone!  
I am looking for advice on a project : I am simulating a few thousands of microorganisms (microalgae). I need to simulate the physics for each of them, applying three forces : fluid friction which limits velocity; collision, or rather repulsion based on distance; and a random force to deviate trajectories a bit and make it look like brownian movements.  
I took a look at a few basic Particle System examples, I adapted the ParticleSystemPShape example in Topics/Create Shapes, but the frameRate drops with the number of particles I am generating. Even when I am not updating the physics, simply calling `shape(shapegroup)` on the shape of type GROUP that contains all the child shapes, I get a low framerate…  
I also took a look at the PixelFlow library by Thomas Diewald, but all the Particle System examples show plain ellipse shapes (in need textured quads), and besides I tried diving into the source code and reference but it is couldn’t quite figure how and if I could adapt it to suit my needs.

So my question would be : _does anyone know of an efficient way to update and display multiple quad shapes?_  
I have been coding fragment shaders lately, and I guess shaders would probably be a good way to make all this more efficient.  
If anyone has tips, example projects, that would be very helpful!

Thank you 🙂

---

<div class="post-metadata">

**Author:** ![DragonBits](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@DragonBits](https://discourse.processing.org/u/DragonBits)\
**Post date:** [March 4, 2019, 2:20am UTC](https://discourse.processing.org/t/particle-system-performance/8493/2 "2019-03-04T02:20:32Z")

</div>

I’m not sure what you mean by quad shapes. Can you clarify? I’ve worked in 3-d programs with quads and tesselations and such, but it sounds like you want a 2-d simulation and I’m not sure how that might apply.

Have you taken a look at Fisica?

[http://www.ricardmarxer.com/fisica/](http://www.ricardmarxer.com/fisica/)

I’m not sure it will be up to your needs, but I’ve done simulations with up to 2040 objects. It throws an “assertion error” at 2048 objects. It’s been a few years since I tried, but I haven’t been able to find my way around that limit. There have been a few minor updates to Fisica, but the system doesn’t seem to be in active development. Take a look at the examples to see if it might be of use.

More references:  
[http://www.ricardmarxer.com/fisica/reference/index.html](http://www.ricardmarxer.com/fisica/reference/index.html)

[http://mycours.es/fisica/](http://mycours.es/fisica/)

---

<div class="post-metadata">

**Author:** ![wqt](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/wqt/32/3546_2.png) [@wqt](https://discourse.processing.org/u/wqt)\
**Post date:** [March 6, 2019, 2:31pm UTC](https://discourse.processing.org/t/particle-system-performance/8493/3 "2019-03-06T14:31:47Z")

</div>

> [@DragonBits](#):
>
> I’m not sure what you mean by quad shapes

I mean PShape instances of type QUAD, with a PNG texture, 4 vertices. Similar to the _Demos/Performance/DynamicParticlesRetained_ example. Like this :

```auto
PShape part = createShape();
part.beginShape(QUAD);
part.noStroke();
part.texture("image.png");
part.normal(0, 0, 1);
part.vertex(-partSize/2, -partSize/2, 0, 0);
part.vertex(+partSize/2, -partSize/2, sprite.width, 0);
part.vertex(+partSize/2, +partSize/2, sprite.width, sprite.height);
part.vertex(-partSize/2, +partSize/2, 0, sprite.height);
part.endShape();  

```

> [@DragonBits](#):
>
> It throws an “assertion error” at 2048 objects

Thank you for suggesting Fisica, unfortunately 2048 particles is not enough for my project…

I ended up doing this the basic way, still doing all the physics computation in the CPU, I got about 8000 at 25fps… So I am still looking for a shader way to optimise all this and get more particles, but for now I get by 🙂

---

<div class="post-metadata">

**Author:** ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)\
**Post date:** [March 6, 2019, 3:16pm UTC](https://discourse.processing.org/t/particle-system-performance/8493/4 "2019-03-06T15:16:54Z")

</div>

Hi @wqt,

Have you considered using [JCuda](http://www.jcuda.org/) for GPU computing ?

An old [thread](https://forum.processing.org/one/topic/jcuda-in-processing-drawing-example.html) showing a use case within Processing.
