Introducing Qt Quick 3D Particles
April 16, 2021 by Kaj Grönholm | Comments
As you may have already seen or heard, Qt Quick 3D introduces support for 3D particles in Qt 6.1. Similarly to instanced rendering , also 3D particles module is a technology preview in Qt 6.1 and will be fully supported in Qt 6.2. In this blog post we'll go through things every developer & designer should know about the new 3D particles, so please continue reading. With the visual elements such as particles, it is always beneficial to actually see what you can do with them. The video below goes through some demos from our Testbed application, included as part of the Qt 6.1 examples.
Usage
If you are familiar with the Qt Quick particles module, you should feel comfortable also with the 3D particles. As a start, instead of "import QtQuick.Particles", you will use "import QtQuick3D.Particles3D" in the beginning of your QML files. Here is a QML code for a simple particle system with a single logical particle, an emitter and an affector:
ParticleSystem3D {
SpriteParticle3D {
id: starParticle
sprite: Texture {
source: "images/star.png"
}
maxAmount: 200
color: "#ffff00"
particleScale: 20.0
fadeOutDuration: 500
billboard: true
}
ParticleEmitter3D {
particle: starParticle
velocity: VectorDirection3D {
direction: Qt.vector3d(100, 200, 0)
directionVariation: Qt.vector3d(20, 20, 20)
}
particleScaleVariation: 0.4
emitRate: 50
lifeSpan: 4000
}
Gravity3D {
magnitude: 100
}
}
When you run the example above, you will see something like this:
Or, if you replace the SpriteParticle3D with a ModelParticle3D to get 3D particles and add some color & rotation variation, the output would look like this:
So let's go through some aspects of our simple example:
-
ParticleSystem3D is the root of the particle system. It handles the system timing and groups all the other related elements like particles, emitters, and affectors together. Compared to Qt Quick ParticleSystem , one neat feature of the ParticleSystem3D is that you can freely animate the time, which allows for example to synchronize particles with other animations. Another feature which especially designers enjoy, is that particles system can be randomized with a specific seed to get identical pixel-perfect particles effect on every run.
-
Two different logical particle types are supported: SpriteParticle3D for 2D texture particles and ModelParticle3D for 3D model particles. Model particles actually use instanced rendering to allow rendering thousands of particles, with full Quick 3D materials and lights support. Logical particle will define the common appearance of the particles. One important property is maxAmount , which is used for allocating the data for particles. Qt Quick particles don't have this feature, but instead they automatically grow the data based on emitRate, lifeSpan and bursts. Requiring it to be defined allows us to optimize the memory usage and to modify the emitRate and lifeSpan without reallocations
-
ParticleEmitter3D handles the actual emitting of the particles. There are many properties to define what the individual particles will look like and how they are emitted. Many of the properties have Variation counterparts, for adding disparity among the particles. To emit particles from another particles, you can use TrailEmitter3D.
-
There are currently 4 different affectors for controlling how the particles animate during their lifetime, and more will be likely added in the future. Here we use the Gravity3D affector, with a magnitude to drag the particles down.
To learn more, please check the Particles3D API documentation and documentation of the Testbed example
Performance Notes
As with all Qt modules, performance has been one of the key aspects of the new 3D particles module. After all, we want the particles to be usable on a variety of hardware, on desktops, mobile and embedded devices. That said, it is not just about rendering the maximum amount of particle elements on the screen. Easy to use API, extensibilty to different use-cases, rendering quality, integration with the other UI elements etc. are also important for us.
Currently, the rendering runs on GPU, while the particle system logic runs on CPU. We are using a so-called stateless particle system, which allows moving also system logic on GPU, if that seems beneficial. The intial measurements indicate that we are quite well balanced between CPU & GPU. Our stateless system also allows for better tooling integration in the future, as particles can be animated on a timeline (as an example of this, see the Testbed "Qt Cube Burst"). And as already mentioned, the model particles utilize instanced rendering to boost the performance. That means OpenGL ES 2.0 unfortunately isn't enough, at least OpenGL ES 3.0, Vulkan etc. modern backend is required so that we can make the rendering performant.
To get a more concrete view on the actual performance, the video below shows the particles Testbed application running on 4 different Android devices. These devices and their chipsets & GPUs could be considered to be lower-end / mid-range, confirming that the particles can perform well also on more affordable hardware.
What about Qt Quick (2D) particles?
The 2D Qt Quick particles module is still fully supported in Qt 6, so no need to worry about that. Laszlo Agocs has ported the particles module to QRhi so it works on all the Qt 6 supported rendering backends (OpenGL, Vulkan, Metal, and D3D11). Myself and other community members have also made different cleanups, bug fixes and optimizations. So actually Qt Quick particles on Qt 6 are better than ever, just continue using them with your 2D Qt Quick particle UIs.
What's next?
If you are reading this, and haven't yet downloaded the latest Qt 6.1 release, please do it now. You can run the particles Testbed example to get an idea what it currently offers and look into the source code. Then you can experiment with the 3D particles yourself, create wild effects with your own designs. And the most important request: Please provide us feedback with Jira tickets , so we can improve the 3D particles module to suit your needs in the future Qt releases. Thanks!
Blog Topics:
Comments
Subscribe to our newsletter
Subscribe Newsletter
Try Qt 6.8 Now!
Download the latest release here: www.qt.io/download.
Qt 6.8 release focuses on technology trends like spatial computing & XR, complex data visualization in 2D & 3D, and ARM-based development for desktop.
We're Hiring
Check out all our open positions here and follow us on Instagram to see what it's like to be #QtPeople.