Parametric Particles

Computer graphics has always been a major area of interest – and I would like to say expertise – for me.

Within graphics, particles and particle systems have played a big role since the days of the first video games.

It is not uncommon for games these days to often have thousands, if not tens or hundreds of thousands of particles on the screen at the same time. In fact, games without particles are a rare exception.

There are many topics that can be discussed when talking about particles, and I am sure I will cover many of them in the future.

Today I want to introduce the concept of parametric particles.

This is no grand effect, or even overly difficult, but it is a technique that every graphics programmer should be aware of. Even when not using it directly, I have found it useful when thinking about particle simulation.

Further, it provides a stepping stone for simple particle simulation on the GPU, which is a topic I want to cover in the near future.

A simple particle

Lets start with an example of a very simple particle.

Note that I am leaving out all sorts of features that almost any kind of particle system will have; for example birth and death times of particles, transparency values, size and orientation.

By itself, there is nothing wrong with this particle implementation. It does exactly what it is supposed to.

The key point I want to discuss is the way we integrate the particle’s velocity in its update method. In essence we use piece-wise integration to change the particle’s position a little bit each update, taking into account the time that has elapsed since the last frame.

Piece-wise vs parametric integration

Note that if we were given the starting parameters of a particle, we can trivially predict where the particle will be with perfect accuracy at any point in the future.

This is the case because the particle moves linearly. Linear functions are easy to evaluate so that we do not need to simulate all the individual time steps to get the correct position.

We can use this fact to integrate the particle’s velocity in a parametric fashion (based on the elapsed time) instead of doing so piece-wise every frame.

Refactored, our particle above becomes:

Again note that this is heavily simplified. In reality, we would probably make the particle know its time of birth and calculate its life time (timeAlive) in the draw method.

This particle will behave the same as the one above.

The question is: Why should we favour this – or in fact the other – approach?

Apart from the second implementation being less code – which in practice will not actually make a big difference – the obvious difference is that we do not have to update and draw the second particle every frame.

With the bottleneck of modern computers being memory – instead of computing power – in games with many particles this alone can already make a difference.

Additionally, we can now make our particles entirely immutable, treating them more like a description of a graphical detail, than an object with a mutable state.

This makes it possible to simulate particles even in a scenario where we do not have easy write-access, like on the GPU.

More than just linear – parametric equations

I just mentioned that we could refactor our particle as shown because it moves linearly.

That is somewhat inaccurate.

To be more precise, we can use the same technique for any particle – or any other object – which only has values that can be expressed using parametric equations.

This means all values that can be calculated for any point in time, based on an immutable set of starting parameters, and the time itself. The time is the parameter of the parametric equation.

Linear functions like the one above are one possible parametric equation. Others are the constant function, and polynomials.

For example, we could use parabolas (rank 2 polynomials) to have our particles be affected by a constant force like gravity.

When using more complicated parametric equations we can also see another advantage of the technique; piece-wise approximation and integration over non linear functions tend to accumulate small errors and cause drift.

An example of this would be a planet orbiting a star slowly spiralling away, even though its initial velocity should cause it to remain in orbit.

If a parametric equation is used, this would be avoided.

Limitations

Unfortunately, this more exact definition of what functions can be also shows the limitations of the technique.

If we have any forces or other factors that we cannot predict working on the particle, parametric representation becomes very difficult or impossible.

Such forces and factors include collisions with level geometry or forces caused by players and other agents.

Further, even parametric influences can be practically infeasible if they cannot be integrated easily. An example would be a changing multi-dimensional vector field representing wind or currents.

Conclusion

I hope that this post succeeds in giving an overview of parametric representations, specifically when it comes to particles.

While I do not intend this to convince anyone that this method is superior, I believe that it can be advantageous to keep the approach in mind, and possibly apply it when appropriate.

As mentioned, one such application could be GPU particles, which I will cover in the future.

Enjoy the pixels!

Leave a Reply