Hey everyone — not even two days have passed, and another big batch of goodies has just dropped from Qt.
Honestly, Qt 6.13 exceeds all my fantasies and expectations. Now it's a full-fledged peer to major game engines (judging by its feature set and rendering capabilities).
Anyway, let's get down to business!
So, what exactly did they deliver?
ShaderGeometry, IndirectShaderGeometry, and ShaderInstancing — in short, I want to add that for Qt games, this is a game changer. Now, in more detail:
ShaderGeometry
Although I haven't used it in practice yet, this is full-fledged geometry out of thin air. Essentially, it's a compute shader that outputs a mesh for the classic vertex-fragment pipeline.
The point is that you can change the total vertex count on the fly, and then in the vertex shader connect them into triangles, voxels, or other primitives.
Here is a simple example (taken from the patch):
QML:
// A grid, also with no vertex buffer, using the same wave as the
// shapes. Unlike them it has a known extent, so it declares bounds and
// is frustum culled.
Model {
// It exists to hold the shapes up, so it goes when they do --
// otherwise a count of 0 leaves a sliver of terrain behind.
visible: settings.count > 0
geometry: ShaderGeometry {
vertexCount: window.terrainCells * window.terrainCells * 6
boundsMinimum: Qt.vector3d(-window.terrainSize / 2, -window.amplitude,
-window.terrainSize / 2)
boundsMaximum: Qt.vector3d(window.terrainSize / 2, window.amplitude,
window.terrainSize / 2)
}
materials: CustomMaterial {
vertexShader: "terrain.vert"
fragmentShader: "terrain.frag"
property int gridSize: window.terrainCells
property real terrainSize: window.terrainSize
property real amplitude: window.amplitude
property real time: window.time
}
}
terrain.vert
// A ShaderGeometry grid, two triangles per cell, with no vertex buffer behind
// it either. The wave is duplicated from shapes.vert rather than shared: a
// Quick3D shader has no #include, and a manual test should not need a storage
// buffer just to agree with itself.
VARYING float terrainHeight;
float waveHeight(vec2 p)
{
// Both rates must be whole numbers: time sweeps 0..2*pi and restarts, so
// a fractional rate leaves the wave mid-cycle and the loop visibly jumps.
return amplitude * (sin(p.x * 0.012 + time) * cos(p.y * 0.012 - time * 2.0));
}
vec3 cornerAt(ivec2 c)
{
vec2 xz = (vec2(c) / float(gridSize) - 0.5) * terrainSize;
return vec3(xz.x, waveHeight(xz), xz.y);
}
void MAIN()
{
int tri = VERTEX_INDEX / 3;
int corner = VERTEX_INDEX % 3;
ivec2 cell = ivec2((tri / 2) % gridSize, (tri / 2) / gridSize);
// All three corners, so the normal can be the face normal. Flat shading is
// deliberate here: it is what makes the individual triangles visible.
ivec2 o0, o1, o2;
if (tri % 2 == 0) {
o0 = ivec2(0, 0); o1 = ivec2(0, 1); o2 = ivec2(1, 0);
} else {
o0 = ivec2(1, 0); o1 = ivec2(0, 1); o2 = ivec2(1, 1);
}
vec3 p0 = cornerAt(cell + o0);
vec3 p1 = cornerAt(cell + o1);
vec3 p2 = cornerAt(cell + o2);
VERTEX = (corner == 0) ? p0 : ((corner == 1) ? p1 : p2);
NORMAL = normalize(cross(p1 - p0, p2 - p0));
terrainHeight = VERTEX.y / max(amplitude, 0.001);
}
terrain.frag
VARYING float terrainHeight;
void MAIN()
{
float t = clamp(terrainHeight * 0.5 + 0.5, 0.0, 1.0);
BASE_COLOR = vec4(mix(vec3(0.16, 0.20, 0.26), vec3(0.42, 0.46, 0.40), t), 1.0);
ROUGHNESS = 0.85;
}
IndirectShaderGeometry
And this is an even more advanced version for procedural geometry generation on the GPU. Here, the source (the vertex count) is no longer taken from the CPU, but directly from a ComputeShader — which, by the way, was also introduced in Qt 6.13, as I talked about earlier.
Essentially, the CPU isn't used here at all — 100% of the computations stay on the GPU pipeline — and that's awesome.
Here is an example from the documentation of roughly how it is used:
Model {
geometry: IndirectShaderGeometry { buffer: argsBuffer }
materials: CustomMaterial { vertexShader: "triangles.vert" }
ComputePass {
computeShader: "count.comp"
property ShaderStorageBuffer drawArgs: argsBuffer
commands: [ Dispatch { groupCountX: 1 } ]
}
}
ShaderInstancing
And finally, ShaderInstancing — it's not hard to guess that this is the same thing as QQuick3DInstancing, only with procedural population directly on the GPU, bypassing the CPU part. It is ideal for grass or other simple primitives — you can also use it together with ShaderGeometry (as shown in the video).
Honestly, this feels like a real Christmas present!
I am super happy with what is being implemented in Qt. And yes — the reality now is that you can't get anywhere without GPU acceleration. Even in UIs, this can easily come in handy.
Thanks everyone for reading — looking forward to your feedback ) even if it's just a "hi, how are you!"