Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
9Qt Quick 3D has multiple ways to combat aliasing (the jagged edges) while
10rendering 3D models. Each technique offers its own benefits and limitations.
11Multiple techniques can be combined, but with additional performance cost.
12
13\section1 Aliasing in General
14
15Aliasing occurs when there is more \e information present in the original than
16we can represent in the pixels on screen. Anti-aliasing techniques fall into
17three categories:
18
19\list
20
21\li Techniques that find additional information for a single pixel and
22represent them all at the same time.
23
24\li Image effects that attempt to find where things look bad and sweep the
25problems under the carpet.
26
27\li Techniques employed by artists that attempt to workaround the limitations.
28
29\endlist
30
31Although anti-aliasing is a useful tool in rendering graphics, it could affect
32performance of your application if not used wisely. The following sections
33describe a few different anti-aliasing techniques to choose from. Understanding
34which technique best targets your problems will help balance visual quality
35with sufficient rendering speed.
36
37\section2 Geometry Aliasing
38
39By default, all geometry is rendered one on-screen pixel at a time. As you can
40see on the left in the image below, this leaves harsh edges that may be easily
41noticeable 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
46The most correct fix for this is to use \l{multisample-aa}{Multisample
47Anti-Aliasing}, as it gathers more geometric detail only as needed. Using
48\l{temporal-aa}{Temporal Anti-Aliasing} or \l{progressive-aa}{Progressive
49Anti-Aliasing} can also mitigate the issue in a correct manner.
50
51Finally, in certain cases you can use a \l{silhouette-opacity-maps}{silhouette
52opacity map} to smooth the edges of the geometry.
53
54\target texture-aliasing
55\section2 Texture Aliasing
56
57When a texture is sub-sampled, fewer pixels than in the original are displayed,
58resulting in undesirable artifacts based on which pixels are chosen. This
59effect is worsened when the model is moving, as different pixels are chosen at
60different times. In the image below, notice how the line between E3 and F3 is
61missing, strongly present between G3 and H3, then gone for the next 5 columns,
62and so on.
63
64\image AA-TextureAliasing.png
65\caption Effective techniques for reducing aliasing for textures
66
67The simplest (and arguably the best) fix for this problem is to use
68\l{mipmaps}{mipmapping in the image texture} itself. Alternative fixes include
69using either \l{temporal-aa}{Temporal AA} or \l{progressive-aa}{Progressive AA}
70to gather more information from the texture.
71
72Using \l{multisample-aa}{Multisample Anti-Aliasing} will not fix this problem.
73
74\target reflection-aliasing
75\section2 Reflection Aliasing
76
77Similar to \l{texture-aliasing}{Texture Aliasing}, a material reflecting the environment will sub-sample the image.
78In some cases, as seen on the left in the image below, it becomes obvious when fine details are being
79skipped.
80
81\image AA-ReflectionAliasing.png
82\caption Effective techniques for reducing aliasing for reflections
83
84The 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
87A simple alternative solution that may be acceptable is to make the material less glossy, more
88rough. In this case lower-resolution mipmaps of the environment are automatically used, blending
89the 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
94Example} and the \l{Qt Quick 3D - Scene Effects Example}{Scene Effects Example}
95to exercise some of these features live. Keep in mind however that modern
96windowing systems are often configured to perform \l{High DPI}{High DPI
97scaling} with a high resolution screen connected. This means that the content
98of any window shown on screen is rendered at a higher resolution and is then
99scaled down by the system compositor or some other component of the platform.
100That is in effect a form of \l{supersample-aa}{Supersample Anti-aliasing}.
101Enabling anti-aliasing techniques in Qt Quick 3D may then show smaller, or
102sometimes hard-to-see improvements, because aliasing is already eliminated to a
103degree by the windowing system's automatic scaling. However, when deploying the
104same application on another system, it could well be that that particular
105system uses a platform or a screen where there is no such scaling, and so
106aliasing and jagged edges are more visible out of the box. Developers are
107advised to consider the potential presence, or lack of high DPI scaling in
108their target environments, and experiment with and tune antialiasing settings
109with this in mind.
110
111Below is an example rendering of the
112\l{https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/Sponza}{Sponza}
113scene with some anti-aliasing methods enabled. The screenshots were taken
114without any system scaling applied to the window (no high DPI scaling), so the
115effects 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
141Multisample 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
146The edges of geometry are super-sampled, resulting in smoother silhouettes.
147This 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
152most noticeable. Works with fast animation without an issue. Many recent GPUs
153support 2x or 4x MSAA without any performance issue.
154
155\li \b{Cons}: Can be expensive to use, especially on older mobile and embedded
156hardware. Does not help with texture or reflection issues.
157
158\endlist
159
160When the View3D is using the default \l{View3D::renderMode}{renderMode} of \c
161Offscreen, the View3D itself is in full control of multisample antialiasing.
162Applications can configure this via the
163\l{SceneEnvironment::antialiasingMode}{antialiasingMode} and
164\l{SceneEnvironment::antialiasingQuality}{antialiasingQuality} properties of
165the environment (\l SceneEnvironment or \l ExtendedSceneEnvironment) associated
166with the \l View3D.
167
168The following example requests the commonly used 4x MSAA, because
169antialiasingQuality defaults to \c{SceneEnvironment.High}.
170
171\qml
172 View3D {
173 environment: SceneEnvironment {
174 antialiasingMode: SceneEnvironment.MSAA
175 }
176 }
177\endqml
178
179MSAA is not implemented by Qt itself, but is rather performed by the underlying
1803D API. Hence performance and quality may vary between different hardware and
181their 3D API implementations.
182
183\target temporal-aa
184\section2 Temporal Anti-Aliasing
185
186Temporal AA operates on the color buffer of the \l View3D. The camera is
187jiggled \e {very slightly} between frames, and the result of each new frame is
188blended with the previous frame.
189
190\list
191
192\li \b{Pros}: Due to the jiggling camera it finds real details that were
193otherwise lost. Low impact on performance.
194
195\li \b{Cons}: Fast-moving objects cause one-frame ghosting.
196
197\endlist
198
199Temporal AA has no effect when combined with Multisample AA. It can however be
200combined with Progressive AA.
201
202To 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
217Progressive AA operates on the color buffer of the \l View3D. When all the
218content in the scene rendered by the View3D has stopped moving, the camera is
219jiggled \e {very slightly} between frames, and the result of each new frame is
220blended with the previous frames. The more frames you accumulate, better
221looking 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
228takes one eighth of a second to finish rendering (at 60fps), which may be
229noticeable.
230
231\endlist
232
233\qml
234 View3D {
235 environment: SceneEnvironment {
236 antialiasingMode: SceneEnvironment.ProgressiveAA
237 }
238 }
239\endqml
240
241Use \l{SceneEnvironment::antialiasingQuality}{antialiasingQuality} to control
242how many frames are blended together (2, 4, or 8).
243
244\target supersample-aa
245\section2 Supersample Anti-Aliasing
246
247Supersample AA operates on the color buffer of a \l View3D. This involves
248creating a color buffer (texture) larger then its normal size, and then
249downsampling it. This means an increased resource usage and at large sizes the
250scaling 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
257limited by the fill-rate of the graphics system, especially an older mobile and
258embedded hardware.
259
260\endlist
261
262\qml
263 View3D {
264 environment: SceneEnvironment {
265 antialiasingMode: SceneEnvironment.SSAA
266 }
267 }
268\endqml
269
270Use \l{SceneEnvironment::antialiasingQuality}{antialiasingQuality} to control
271the size multiplier (1.2, 1.5 or 2.0).
272
273\target mipmaps
274\section2 Mipmaps
275
276Mipmapping stores the texture along with its pre-calculated lower resolution
277versions. Whenever the texture is being displayed at a smaller size, the
278rendering system automatically uses these low-resolution images (which combine
279many details into fewer pixels).
280
281\list
282
283\li \b{Pros}: Low performance impact. Greatly improves image quality for
284textures.
285
286\li \b{Cons}: Requires potentially costly generation of the mipmap chain, or,
287with some image container formats, pre-generating the mipmap images in the
288image asset itself. Uses 33% more graphics memory than the same image without
289mipmaps.
290
291\endlist
292
293To have Qt generate mipmaps for a \l Texture and enable using the mipmap chain
294when 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
309Artifacts from the specular lighting contribution may be reduced by enabling
310Specular Anti-aliasing. These artifacts typically show up as bright dots,
311perhaps 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
331they had a \l{PrincipledMaterial::roughness}{more rough} surface when enabling
332specular 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
338post-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
356When your model has a consistent silhouette, you can apply an opacity map that makes the outer edge
357of the geometry transparent. Using a gradient for the opacity will let the edge of the object
358smoothly disappear. However, even if your opacity map transitions directly from fully-opaque
359to fully-transparent over the space of one pixel, the result will still provide anti-aliased edges
360as seen in the example above. This is because image maps, including opacity maps, use bilinear
361interpolation.
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
375As demonstrated in the image for \l{reflection-aliasing}{Reflection Aliasing} above, sometimes the
376simplest fix for problems is to change the artwork. If you are getting distracting specular glints
377on the corner of your model, ask yourself: \e {Can I make the material softer? Can I modify the
378geometry to smooth or change the reflection angle? Can I edit the environment map to reduce
379sharp transitions?}
380
381*/