New 3D particles features in Qt 6.3

Yes, I know, Qt 6.3 isn't out yet. But as the first beta was just released, it is a good time to start speaking about the new features. In this blog post, I will list my three favourite new features available in Qt Quick 3D particles module.

Custom Shapes

Shapes in Quick 3D particles module define areas where the particles are emitted from or where the particles are attracted to. Most common way to define the shape is using ParticleShape3D and selecting the shape type (Cube, Sphere, Cylinder). Alternatively, if you want to emit particles from an existing 3D model, there is ParticleModelShape3D just for that. These options are often enough, but they don't cover all the needs, so with Qt 6.3 we added a new ParticleCustomShape3D element. This element allows defining exact particle positions of the shape in a simple CBOR format:

[
"QQ3D_SHAPE", // string
version, // integer
[
posX, // float
posY, // float
posZ, // float
posX, // float
...
]
]

Here is an example application using custom shapes:

 

To create these shape files, we provide a simple command-line tool called shapegen, which takes in an image and depth, and creates defined amount of positions within those. Here is the help of shapegen tool:

C:\qt6_3-install\bin
λ shapegen.exe --help
Usage: shapegen.exe [options]
Tool to generate Qt Quick 3D Particles Custom Shapes

Options:
-?, -h, --help Displays help on commandline options.
--help-all Displays help including Qt specific
options.
-i, --image <file> Input image for the data.
-o, --output <file> Output CBOR file for the shape data.
-d, --depth <number> Depth (z scale) for the data.
-s, --scale <number> Scale used for the image data. Default
1.0
-a, --amount <number> Amount of position data to generate.
-p, --sorting-position <qvector3d> Position to use for sorting. Format "x,
y, z"
-l, --list-cbor Lists CBOR file content.

This tool is still rather simple, but so is the CBOR format so you can also look at the private shape helper class and generate your own custom shapes in any imaginable ways.

Lights Support

To emit 2D texture particles in the Quick 3D scene, you use the SpriteParticle3D elements. With the Qt 6.3, we have added lights support for these sprite particles by defining which lights the particle should be affected by:

SpotLight {
id: lightSpot
...
}

PointLight {
id: lightPoint
...
}

SpriteParticle3D {
id: spriteParticle
sprite: Texture {
source: "images/sphere.png"
}
lights: [lightSpot, lightPoint]
...
}

 

All the Quick3D light types are supported. With particles, the applied light amount is per-particle and not per-pixel resolution like with the Quick 3D models. This decision was made because particles are usually rather small and to have excellent performance by having the lighting calculated in the vertex shader side.

Here is an example application demonstrating particles with different lights:

 

You can take this lighting support into use to make particles blend better with the rest of the 3D scene. And as said, the lights implementation is rather performant so you can use them also on embedded hardware.

Dynamic Bursts

To emit particles in bursts, Quick 3D supports several burst() methods and declarative EmitBurst3D elements. The latter is evaluated (so burst particles generated) at the time the particle system starts. This is optimal for performance as it means burst particles don't need to be generated while the system is running, but it doesn't suit cases where the emitter moves, rotates etc. because bursts will be created with the initial emitter stage. For this reason we have added a new DynamicBurst3D element in Qt 6.3. It is used similarly to EmitBurst3D:

ParticleEmitter3D {
...
emitBursts: [
DynamicBurst3D {
time: 1000
amount: 100
},
DynamicBurst3D {
time: 2000
amount: 200
}
]
}

DynamicBurst3D elements are evaluated at the system runtime, meaning that the above example emits 100 particles at 1s and 200 particles at 2s, with the emitter properties during those exact times. DynamicBurst3D combined with TrailEmitter3D also allows triggering the bursts when the followed particle starts or ends.

Here is an example application demonstrating dynamic bursts with the trail emitter:

 

All the examples shown in the blog are available with the Qt 6.3 and there are also plenty of other new things and fixes in Qt 6.3. So please download the latest 6.3 release and try for yourself.


Blog Topics:

Comments