Index

Particles

Trial includes a high performance particle simulation system that performs almost all of the work on the GPU, allowing you to create particles with hundreds of thousands of particles (if needed).

NOTE: This section refers to particles used for visual effects. For particles as used in physics simulations (Verlet, etc) see Mass Aggregate Physics.

images/particles.png

NOTE: This system requires OpenGL 4.2 or later. Most of the engine is built around OpenGL 3.3, but that would proclude using Compute Shaders, which are required for this approach. In order to use these particle systems, make sure to construct your context with :version '(4 2). If you want to run particles on OpenGL 3.3 see the section below.

In order to create a particle system, simply create a gpu-particle-emitter and enter it into a scene. You can then use emit to burst particles on demand, or set the particle-rate to create a continuous stream of particles.

NOTE: In order for the system to work correctly you need a standard renderer derived renderer in your scene such as the pbr-render-pass. The particles aren't actually shaded by the renderer, but they require the environment information that the pass also takes care of providing.

Particles have a variety of attributes that can be set either with the :particle-options initarg on the construction of the emitter, or using accessors:

Besides the per-particle properties, the emitter itself also has a number of useful properties:

Due to the high flexibility afforded by the emitter, you can probably re-use the same emitter to spawn particles in multiple places. To do so, simply use the emit function, which also allows you to conveniently place the emitter.

Force Fields

One of the factors that makes particles so fast is that they typically don't interact with the environment. However, it can still be useful to be able to make the particles be affected by various forces, whether to simulate gravity, wind, or other interactions.

To do so you can set the particle-force-fields on the emitter. This can either be a shader-storage-buffer backing a particle-force-fields structure, in which case the force fields can be shared between multiple emitters, or simply a list of force field descriptions to update the existing buffer. Each field should be a plist with the following attributes:

Collisions

If you would like your particles to bounce off of geometry, you can use a depth-colliding-particle-emitter and connect it to the render pass like so:

(connect my-standard-render-pass my-emitter-instance scene)

Note that the bounce is determined directly from the depth buffer and not from real geometry, and as such anything that isn't visible from the camera's point of view will not cause the particles to bounce as expected.

Alpha blending

By default the emitter uses additive blending, which is a lot cheaper to simulate, as particles can be rendered in any order. If you require standard alpha blending for your particles, then you should use the sorted-particle-emitter instead, which runs a bitonic sort after simulation to ensure that all particles are drawn back to front.

Multiple Textures

The default emitter only allows using a single texture per particle. Sometimes it can be useful to vary the texture a little between particles. To do so you can use the multi-texture-particle-emitter, whose texture must be a texture-2d-array. You can then use this particle option to configure the sprite selection:

CPU Simulation

On systems with restricted GPU capabilities (GL 3.3) or for particle systems with a very small number of particles it can be more useful to simulate on the CPU instead of the GPU. In this case you can use the cpu-particle-emitter. The interface of the emitter is the same as for the gpu-particle-emitter, though it has one crucial difference: particles in both quad render modes can be spawned at different places and still work fine. This means that you can spawn particles from different locations and directions with the same emitter without the simulation going awry.