QtQuick.Particles 2.0

Some people may remember the old Qt.labs.particles module. It was left in labs because we thought we could create a better particle system later, and didn't want to tie ourselves into that first attempt (but of course, we had to have a particle system somewhere; it's a modern essential!). With the graphical power of scenegraph, the shader fairies are now creating that better system. As it's in the unreleased and unstable Qt5 though, it's still only labs quality - but that doesn't stop me from sharing it on labs :) . Check out the image of Plasma Patrol below to get a feel for some of its capabilities (and checkout qt5.git to see it in action).

A game made out of particle effects

The basics of the new particle system is that we've split out a bunch of the components for increased flexibility. The previous particle system just had "Particles", but the new one splits up the elements into Emitters (items that emit logical particles into the system from their current position), Painters (which visualize the logical particles in some way) and Affectors (which can screw with the logical particles to do anything else). This means that you can anchor an emitter to the end of each rocket ship and use a single painter to render all the exhausts, and a single affector to add a bit of breeze to them all (this would be before they get into space). You can also use this to render particles with your own custom shaders (instead of using our supplied ones) with the stock emitters, or have the particles switch visualization on-the-fly (perhaps the occasional one wants to use a full QML delegate instead of just an image). This is especially helpful considering all the stochastic parameter variation that the particle system can do, as many of the properties can have a defined variation in aggregate over the vast number of particles being emitted. There are some nice combinations in there too, like the stochastic sprite particles that allow you to not only specify that each particle is rendered as an animation, but they can also randomly (or on command) switch to other animations along predefined paths.

With all these functions, it should be easy to imagine how some cool effects can be done: a ship flying through an asteroid field and breaking those it hits, a flame setting all balls that pass through it aflame (which then light up other balls), fireworks that explode with different colors, an image that forms out of thousands of particles fading in with their own timeline, a candle swaying in the breeze... Perhaps it's not so easy to imagine how you'd do all this with the new particle system, but for that case we have examples that show you how. All you need is to build Qt5 and try it out (building Qt5 is still a bit of a shifting target though, especially on windows, so please ask any questions about that on our IRC channel, not in the comments ).

I've been augmenting the QML games with it already. The samegame particles are now ten times better (and approximately more numerous). It also used in a new space invaders game, in qt-qml-demo-playground on gitorious, where the particles add a bit of flair to the projectiles swarming the screen.

A game with a couple of particle effects.

So there you have it, new particle system coming in QtQuick 2 (and since it's heavily scenegraph based, it will not be backported to QtQuick 1). If you're using Qt5 already, then you can start using it now to add some aesthetic punch to your applications. There's a host of examples in examples/declarative/particles, plus the aforementioned games, to both get you started and show off what the system is capable of already. As it's still in an early stage of development, I welcome feedback from any such brave souls who give it a try. Hopefully, QtQuick 2 can come with a great particle system available for all.

Edit: Here's a video of a few of the particle system examples.


Blog Topics:

Comments