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