Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtquick3d-aa.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2023 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4
/*!
5
6
\title Anti-Aliasing Best Practices
7
\page quick3d-asset-conditioning-anti-aliasing
8
9
Qt Quick 3D has multiple ways to combat aliasing (the jagged edges) while
10
rendering 3D models. Each technique offers its own benefits and limitations.
11
Multiple techniques can be combined, but with additional performance cost.
12
13
\section1 Aliasing in General
14
15
Aliasing occurs when there is more \e information present in the original than
16
we can represent in the pixels on screen. Anti-aliasing techniques fall into
17
three categories:
18
19
\list
20
21
\li Techniques that find additional information for a single pixel and
22
represent them all at the same time.
23
24
\li Image effects that attempt to find where things look bad and sweep the
25
problems under the carpet.
26
27
\li Techniques employed by artists that attempt to workaround the limitations.
28
29
\endlist
30
31
Although anti-aliasing is a useful tool in rendering graphics, it could affect
32
performance of your application if not used wisely. The following sections
33
describe a few different anti-aliasing techniques to choose from. Understanding
34
which technique best targets your problems will help balance visual quality
35
with sufficient rendering speed.
36
37
\section2 Geometry Aliasing
38
39
By default, all geometry is rendered one on-screen pixel at a time. As you can
40
see on the left in the image below, this leaves harsh edges that may be easily
41
noticeable in high-contrast cases, most noticeably here with black-and-white.
42
43
\image AA-GeometryAliasing.png {Comparison of five antialiasing
44
techniques on rotated squares, circles, and text}
45
\caption Effective techniques for reducing aliasing for geometry
46
47
The most correct fix for this is to use \l{multisample-aa}{Multisample
48
Anti-Aliasing}, as it gathers more geometric detail only as needed. Using
49
\l{temporal-aa}{Temporal Anti-Aliasing} or \l{progressive-aa}{Progressive
50
Anti-Aliasing} can also mitigate the issue in a correct manner.
51
52
Finally, in certain cases you can use a \l{silhouette-opacity-maps}{silhouette
53
opacity map} to smooth the edges of the geometry.
54
55
\target texture-aliasing
56
\section2 Texture Aliasing
57
58
When a texture is sub-sampled, fewer pixels than in the original are displayed,
59
resulting in undesirable artifacts based on which pixels are chosen. This
60
effect is worsened when the model is moving, as different pixels are chosen at
61
different times. In the image below, notice how the line between E3 and F3 is
62
missing, strongly present between G3 and H3, then gone for the next 5 columns,
63
and so on.
64
65
\image AA-TextureAliasing.png {Comparison of four antialiasing
66
techniques on receding grid texture}
67
\caption Effective techniques for reducing aliasing for textures
68
69
The simplest (and arguably the best) fix for this problem is to use
70
\l{mipmaps}{mipmapping in the image texture} itself. Alternative fixes include
71
using either \l{temporal-aa}{Temporal AA} or \l{progressive-aa}{Progressive AA}
72
to gather more information from the texture.
73
74
Using \l{multisample-aa}{Multisample Anti-Aliasing} will not fix this problem.
75
76
\target reflection-aliasing
77
\section2 Reflection Aliasing
78
79
Similar to \l{texture-aliasing}{Texture Aliasing}, a material reflecting the environment will sub-sample the image.
80
In some cases, as seen on the left in the image below, it becomes obvious when fine details are being
81
skipped.
82
83
\image AA-ReflectionAliasing.png
84
{Comparison of four techniques for reducing reflection aliasing}
85
\caption Effective techniques for reducing aliasing for reflections
86
87
The most correct solution in this case is using \l{temporal-aa}{Temporal AA} or
88
\l{progressive-aa}{Progressive AA} to find the extra information.
89
90
A simple alternative solution that may be acceptable is to make the material less glossy, more
91
rough. In this case lower-resolution mipmaps of the environment are automatically used, blending
92
the sharp details together.
93
94
\section1 Anti-Aliasing Techniques in Qt Quick 3D
95
96
\note Check out the \l{Qt Quick 3D - Antialiasing Example}{Antialiasing
97
Example} and the \l{Qt Quick 3D - Scene Effects Example}{Scene Effects Example}
98
to exercise some of these features live. Keep in mind however that modern
99
windowing systems are often configured to perform \l{High DPI}{High DPI
100
scaling} with a high resolution screen connected. This means that the content
101
of any window shown on screen is rendered at a higher resolution and is then
102
scaled down by the system compositor or some other component of the platform.
103
That is in effect a form of \l{supersample-aa}{Supersample Anti-aliasing}.
104
Enabling antialiasing techniques in Qt Quick 3D may then show smaller, or
105
sometimes hard-to-see improvements, because aliasing is already eliminated to a
106
degree by the windowing system's automatic scaling. However, when deploying the
107
same application on another system, it could well be that that particular
108
system uses a platform or a screen where there is no such scaling, and so
109
aliasing and jagged edges are more visible out of the box. Developers are
110
advised to consider the potential presence, or lack of high DPI scaling in
111
their target environments, and experiment with and tune antialiasing settings
112
with this in mind.
113
114
Below is an example rendering of the
115
\l{https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/Sponza}{Sponza}
116
scene with some antialiasing methods enabled. The screenshots were taken
117
without any system scaling applied to the window (no high DPI scaling), so the
118
effects of the various methods are more pronounced.
119
120
\table
121
\header
122
\li AA used
123
\li Result
124
\row
125
\li No AA
126
\li \image aa_disabled.jpg {Architectural scene with no antialiasing
127
showing jagged edges}
128
\row
129
\li Supersample AA, high (1.5x)
130
\li \image aa_ssaa_high.jpg {Architectural scene with supersample
131
antialiasing at 1.5x}
132
\row
133
\li Multisample AA, high (4x)
134
\li \image aa_msaa_high.jpg {Architectural scene with multisample
135
antialiasing at 4x}
136
\row
137
\li FXAA
138
\li \image aa_fxaa.jpg
139
{Architectural scene with fast approximate antialiasing}
140
\row
141
\li Temporal AA, default strength (0.3)
142
\li \image aa_temporal_default.jpg
143
{Architectural scene with temporal antialiasing}
144
\endtable
145
146
\target multisample-aa
147
\section2 Multisample Anti-Aliasing
148
149
Multisample AA (MSAA) operates either on the color buffer of the \l View3D item
150
(this is the default), or, if a \l{View3D::renderMode}{renderMode} other than
151
\c Offscreen is used, on the entire Qt Quick window (\l QQuickWindow, \l QQuickView,
152
\l Window, \l ApplicationWindow).
153
154
The edges of geometry are super-sampled, resulting in smoother silhouettes.
155
This technique has no effect on the materials inside geometry, however.
156
157
\list
158
159
\li \b{Pros}: Good results on geometry silhouettes, where aliasing is often
160
most noticeable. Works with fast animation without an issue. Many recent GPUs
161
support 2x or 4x MSAA without any performance issue.
162
163
\li \b{Cons}: Can be expensive to use, especially on older mobile and embedded
164
hardware. Does not help with texture or reflection issues.
165
166
\endlist
167
168
When the View3D is using the default \l{View3D::renderMode}{renderMode} of \c
169
Offscreen, the View3D itself is in full control of multisample antialiasing.
170
Applications can configure this via the
171
\l{SceneEnvironment::antialiasingMode}{antialiasingMode} and
172
\l{SceneEnvironment::antialiasingQuality}{antialiasingQuality} properties of
173
the environment (\l SceneEnvironment or \l ExtendedSceneEnvironment) associated
174
with the \l View3D.
175
176
The following example requests the commonly used 4x MSAA, because
177
antialiasingQuality defaults to \c{SceneEnvironment.High}.
178
179
\qml
180
View3D {
181
environment: SceneEnvironment {
182
antialiasingMode: SceneEnvironment.MSAA
183
}
184
}
185
\endqml
186
187
MSAA is not implemented by Qt itself, but is rather performed by the underlying
188
3D API. Hence performance and quality may vary between different hardware and
189
their 3D API implementations.
190
191
\target temporal-aa
192
\section2 Temporal Anti-Aliasing
193
194
Temporal AA operates on the color buffer of the \l View3D. The camera is
195
jiggled \e {very slightly} between frames, and the result of each new frame is
196
blended with the previous frame.
197
198
\list
199
200
\li \b{Pros}: Due to the jiggling camera it finds real details that were
201
otherwise lost. Low impact on performance.
202
203
\li \b{Cons}: Fast-moving objects cause one-frame ghosting.
204
205
\endlist
206
207
Temporal AA has no effect when combined with Multisample AA. It can however be
208
combined with Progressive AA.
209
210
To control temporal anti-aliasing, use the environment's
211
\l{SceneEnvironment::temporalAAEnabled}{temporalAAEnabled} and
212
\l{SceneEnvironment::temporalAAStrength}{temporalAAStrength} properties.
213
214
\qml
215
View3D {
216
environment: SceneEnvironment {
217
temporalAAEnabled: true
218
}
219
}
220
\endqml
221
222
\target progressive-aa
223
\section2 Progressive Anti-Aliasing
224
225
Progressive AA operates on the color buffer of the \l View3D. When all the
226
content in the scene rendered by the View3D has stopped moving, the camera is
227
jiggled \e {very slightly} between frames, and the result of each new frame is
228
blended with the previous frames. The more frames you accumulate, better
229
looking the result.
230
231
\list
232
233
\li \b{Pros}: Provides detailed static images with no performance cost.
234
235
\li \b{Cons}: Does not take effect if any visual changes are occurring. 8x PAA
236
takes one eighth of a second to finish rendering (at 60fps), which may be
237
noticeable.
238
239
\endlist
240
241
\qml
242
View3D {
243
environment: SceneEnvironment {
244
antialiasingMode: SceneEnvironment.ProgressiveAA
245
}
246
}
247
\endqml
248
249
Use \l{SceneEnvironment::antialiasingQuality}{antialiasingQuality} to control
250
how many frames are blended together (2, 4, or 8).
251
252
\target supersample-aa
253
\section2 Supersample Anti-Aliasing
254
255
Supersample AA operates on the color buffer of a \l View3D. This involves
256
creating a color buffer (texture) larger then its normal size, and then
257
downsampling it. This means an increased resource usage and at large sizes the
258
scaling operation can be costly.
259
260
\list
261
262
\li \b{Pros}: Provides full-scene anti-aliasing with no limitations on animation.
263
264
\li \b{Cons}: Can severely degrade performance when your scene is already
265
limited by the fill-rate of the graphics system, especially an older mobile and
266
embedded hardware.
267
268
\endlist
269
270
\qml
271
View3D {
272
environment: SceneEnvironment {
273
antialiasingMode: SceneEnvironment.SSAA
274
}
275
}
276
\endqml
277
278
Use \l{SceneEnvironment::antialiasingQuality}{antialiasingQuality} to control
279
the size multiplier (1.2, 1.5 or 2.0).
280
281
\target mipmaps
282
\section2 Mipmaps
283
284
Mipmapping stores the texture along with its pre-calculated lower resolution
285
versions. Whenever the texture is being displayed at a smaller size, the
286
rendering system automatically uses these low-resolution images (which combine
287
many details into fewer pixels).
288
289
\list
290
291
\li \b{Pros}: Low performance impact. Greatly improves image quality for
292
textures.
293
294
\li \b{Cons}: Requires potentially costly generation of the mipmap chain, or,
295
with some image container formats, pre-generating the mipmap images in the
296
image asset itself. Uses 33% more graphics memory than the same image without
297
mipmaps.
298
299
\endlist
300
301
To have Qt generate mipmaps for a \l Texture and enable using the mipmap chain
302
when performing texture sampling in the graphics shaders, set the
303
\l{Texture::mipFilter}{mipFilter} and
304
\l{Texture::generateMipmaps}{generateMipmaps} properties.
305
306
\qml
307
Texture {
308
source: "image.png"
309
mipFilter: Texture.Linear
310
generateMipmaps: true
311
}
312
\endqml
313
314
\target specular-aa
315
\section2 Specular Anti-Aliasing
316
317
Artifacts from the specular lighting contribution may be reduced by enabling
318
Specular Anti-aliasing. These artifacts typically show up as bright dots,
319
perhaps with a flickering appearance.
320
321
\table
322
\header
323
\li Specular AA disabled
324
\li Specular AA enabled
325
\row
326
\li \image specular_aa_off.jpg
327
{Architectural scene showing specular highlights without
328
antialiasing}
329
\li \image specular_aa_on.jpg
330
{Architectural scene showing smoothed specular highlights with
331
antialiasing}
332
\endtable
333
334
\qml
335
View3D {
336
environment: SceneEnvironment {
337
specularAAEnabled: true
338
}
339
}
340
\endqml
341
342
\note Materials with a very smooth appearance may change their appearance as if
343
they had a \l{PrincipledMaterial::roughness}{more rough} surface when enabling
344
specular AA. This is a result of the underlying lighting calculations.
345
346
\target fx-aa
347
\section2 Fast Approximate Anti-Aliasing
348
349
\l ExtendedSceneEnvironment offers another method of anti-aliasing in form of a
350
post-processing effect. To enable FXAA, set
351
\l{ExtendedSceneEnvironment::fxaaEnabled}{fxaaEnabled} to true.
352
353
\qml
354
import QtQuick3D.Helpers
355
356
View3D {
357
environment: ExtendedSceneEnvironment {
358
fxaaEnabled: true
359
}
360
}
361
\endqml
362
363
\section1 Artist-Employed Cheats
364
365
\target silhouette-opacity-maps
366
\section2 Silhouette Opacity Maps
367
368
When your model has a consistent silhouette, you can apply an opacity map that makes the outer edge
369
of the geometry transparent. Using a gradient for the opacity will let the edge of the object
370
smoothly disappear. However, even if your opacity map transitions directly from fully-opaque
371
to fully-transparent over the space of one pixel, the result will still provide anti-aliased edges
372
as seen in the example above. This is because image maps, including opacity maps, use bilinear
373
interpolation.
374
375
\list
376
\li
377
\b{Pros}: Can show softer transitions than normal AA. Can be applied per model instead of
378
per-layer.
379
\li
380
\b{Cons}: Cannot be used if the silhouette of the object will ever change. Multiple overlapping
381
models that employ transparency consume fill rate performance, which is often at a premium.
382
\endlist
383
384
\target modifying-materials
385
\section2 Modifying Materials or Geometry
386
387
As demonstrated in the image for \l{reflection-aliasing}{Reflection Aliasing} above, sometimes the
388
simplest fix for problems is to change the artwork. If you are getting distracting specular glints
389
on the corner of your model, ask yourself: \e {Can I make the material softer? Can I modify the
390
geometry to smooth or change the reflection angle? Can I edit the environment map to reduce
391
sharp transitions?}
392
393
*/
qtquick3d
src
quick3d
doc
src
qtquick3d-aa.qdoc
Generated on
for Qt by
1.16.1