Particle systems are a widely used technique in computer graphics, and are used to mimic the behavior of a collection of objects; be it water molecules, birds, or cells. Simulations involving particle systems are very flexible and can represent a wide variety of behaviors; particles also lie at the foundation for more complex simulations. In my mind they are sort of a “Hello World” to physics based simulations, and for these reasons I decided it would be a good idea to implement my own to get familiar with the technique and facilitate my descent into the simulation rabbit hole.

There exists a wide variety of ways to create a particle systems in either 2D or 3D; I decided to implement mine on compute shaders in Touchdesigner. Shader languages like OpenGL leverage the parallel computing of GPUs, which allows for higher performance than a CPU based approach; aka, more computer power equals MORE PARTICLES.

In OpenGL, particles are represented by a structure, which is very similar to the idea of a class in that they both hold attributes. Particles posses certain attributes, and those attributes are manipulated according to whatever rules of the sim are implemented. For example, I decided to implement a simple system that would imitate air particles carried by an external force like wind. The particles in this scenario have the following attributes:

  • position
  • velocity
  • acceleration
  • color
  • size
  • life

Attributes allow us to control the behavior of particles in a variety of ways. For example, the position, velocity, and acceleration attributes allow us to control aspects of the particles movement. In the presence of external forces in our environment, we can simulate these forces by updating the particles acceleration accordingly. Spatial information is largely processed with the help of vector and matrix operations.

I also gave the particles a life attribute which starts at 1 when the particle is born, and decrements over time until it hits 0; at this point the particle dies a peaceful death and is reborn anew at a spawn point with its life attribute reset to 1. I use this life variable to influence the size and color of the particle, which provides visual feedback as to where the particles are in their life and the overall passage of time.

Here’s a short clip of this example followed by some renders of particles I felt were worth sharing.