Skip to content

Commit 8c0164f

Browse files
committed
Add documentation pages on 2D and 3D antialiasing
1 parent 2197055 commit 8c0164f

19 files changed

+383
-29
lines changed

about/list_of_features.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,14 @@ Vulkan 1.0, with Vulkan 1.1 and 1.2 features optionally used.
331331

332332
**Anti-aliasing:**
333333

334+
- Temporal antialiasing (TAA).
335+
- Multi-sample antialiasing (MSAA), for both :ref:`doc_2d_antialiasing` and :ref:`doc_3d_antialiasing`.
334336
- Fast approximate antialiasing (FXAA).
335-
- Multi-sample antialiasing (MSAA).
336337
- Super-sample antialiasing (SSAA) using bilinear 3D scaling and a 3D resolution scale above 1.0.
337-
- Alpha antialiasing, alpha to coverage and alpha hashing on a per-material basis.
338+
- AMD FidelityFX Super Resolution 1.0 as a sharper alternative to bilinear 3D scaling.
339+
- Alpha antialiasing, MSAA alpha to coverage and alpha hashing on a per-material basis.
338340

339-
Most of these effects can be adjusted for better performance or to further
341+
Most effects listed above can be adjusted for better performance or to further
340342
improve quality. This can be helpful when using Godot for offline rendering.
341343

342344
3D tools

tutorials/2d/2d_antialiasing.rst

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
.. _doc_2d_antialiasing:
2+
3+
2D antialiasing
4+
===============
5+
6+
.. Images on this page were generated using the project below
7+
.. (except for `antialiasing_none_scaled.png`):
8+
.. https://github.com/Calinou/godot-antialiasing-comparison
9+
10+
.. seealso::
11+
12+
Godot also supports antialiasing in 3D rendering. This is covered on the
13+
:ref:`doc_3d_antialiasing` page.
14+
15+
Introduction
16+
------------
17+
18+
Due to their limited resolution, scenes rendered in 2D can exhibit aliasing
19+
artifacts. These artifacts usually manifest in the form of a "staircase" effect on
20+
geometry edges, and are most noticeable when using nodes such as :ref:`class_Line2D`,
21+
:ref:`class_Polygon2D` or :ref:`class_TextureProgressBar`. :ref:`doc_custom_drawing_in_2d`
22+
can also have aliasing artifacts for methods that don't support antialiasing.
23+
24+
In the example below, you can notice how
25+
edges have a blocky appearance:
26+
27+
.. figure:: img/antialiasing_none_scaled.png
28+
:alt: Image is scaled by 2× with nearest-neighbor filtering to make aliasing more noticeable.
29+
:align: center
30+
31+
Image is scaled by 2× with nearest-neighbor filtering to make aliasing more noticeable.
32+
33+
To combat this, Godot supports several methods of enabling antialiasing on 2D rendering.
34+
35+
Antialiasing property in Line2D and custom drawing
36+
--------------------------------------------------
37+
38+
This is the recommended method, as it has a lower performance impact in most cases.
39+
40+
Line2D has an **Antialiased** property which you can enable in the inspector.
41+
Also, several methods for :ref:`doc_custom_drawing_in_2d` support an optional
42+
``antialiased`` parameter, which can be set to ``true`` when calling the
43+
function.
44+
45+
These methods do not require MSAA to be enabled, which makes their *baseline*
46+
performance cost low. In other words, there is no permanent added cost if you're
47+
not drawing any antialiased geometry at some point.
48+
49+
The downside of these antialiasing methods is that they work by generating
50+
additional geometry. If you're generating complex 2D geometry that's updated
51+
every frame, this may be a bottleneck. Also, Polygon2D, TextureProgressBar, and
52+
several custom drawing methods don't feature an antialiased property. For these
53+
nodes, you can use 2D multisample antialiasing instead.
54+
55+
Multisample antialiasing (MSAA)
56+
-------------------------------
57+
58+
Before enabling MSAA in 2D, it's important to understand what MSAA will operate
59+
on. MSAA in 2D follows similar restrictions as in 3D. While it does not
60+
introduce any blurriness, its scope of application is limited. The main
61+
applications of 2D MSAA are:
62+
63+
- Geometry edges, such as line and polygon drawing.
64+
- Sprite edges *only for pixels touching one of the texture's edges*. This works
65+
for both linear and nearest-neighbor filtering. Sprite edges created using
66+
transparency on the image are not affected by MSAA.
67+
68+
The downside of MSAA is that it only operates on edges. This is because MSAA
69+
increases the number of *coverage* samples, but not the number of *color*
70+
samples. Using multiple coverage samples allows the coverage value to be an
71+
intermediate value between 0.0 and 1.0, rather than being limited to 0.0 *or*
72+
1.0. The coverage value is used to determine the contribution of the pixel to
73+
the scene, with 0.0 meaning "no contribution at all" and 1.0 meaning "fully
74+
opaque pixel".
75+
76+
However, since the number of color samples did not increase, fragment shaders
77+
are still run for each pixel only once. As a result,
78+
MSAA will **not affect** the following kinds of aliasing in any way:
79+
80+
- Aliasing *within* nearest-neighbor filtered textures (pixel art).
81+
- Aliasing caused by custom 2D shaders.
82+
- Specular aliasing when using Light2D.
83+
- Aliasing in font rendering.
84+
85+
MSAA can be enabled in the Project Settings by changing the value of the
86+
**Rendering > Anti Aliasing > Quality > MSAA 2D** setting. It's important to change
87+
the value of the **MSAA 2D** setting and not **MSAA 3D**, as these are entirely
88+
separate settings.
89+
90+
Comparison between no antialiasing (left) and various MSAA levels (right). The
91+
top-left corner contains a Line2D node, the top-right corner contains 2
92+
TextureProgressBar nodes. The bottom contains 8 pixel art sprites, with 4 of
93+
them touching the edges (green background) and 4 of them not touching the edges
94+
(Godot logo):
95+
96+
.. image:: img/antialiasing_msaa_2x.png
97+
98+
.. image:: img/antialiasing_msaa_4x.png
99+
100+
.. image:: img/antialiasing_msaa_8x.png

tutorials/2d/custom_drawing_in_2d.rst

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -450,15 +450,13 @@ Antialiased drawing
450450
^^^^^^^^^^^^^^^^^^^
451451

452452
Godot offers method parameters in :ref:`draw_line<class_CanvasItem_method_draw_line>`
453-
to enable antialiasing, but it doesn't work reliably in all situations
454-
(for instance, on mobile/web platforms, or when HDR is enabled).
455-
There is also no ``antialiased`` parameter available in
456-
:ref:`draw_polygon<class_CanvasItem_method_draw_polygon>`.
457-
458-
As a workaround, install and use the
459-
`Antialiased Line2D add-on <https://github.com/godot-extended-libraries/godot-antialiased-line2d>`__
460-
(which also supports antialiased Polygon2D drawing). Note that this add-on relies
461-
on high-level nodes, rather than low-level ``_draw()`` functions.
453+
to enable antialiasing, but not all custom drawing methods offer this ``antialiased``
454+
parameter.
455+
456+
For custom drawing methods that don't provide an ``antialiased`` parameter,
457+
you can enable 2D MSAA instead, which affects rendering in the entire viewport.
458+
This provides high-quality antialiasing, but a higher performance cost and only
459+
on specific elements. See :ref:`doc_2d_antialiasing` for more information.
462460

463461
Tools
464462
-----
21.3 KB
Loading
22.5 KB
Loading
23.8 KB
Loading
2.89 KB
Loading

tutorials/2d/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
2d_meshes
1515
custom_drawing_in_2d
1616
2d_sprite_animation
17+
2d_antialiasing

tutorials/3d/3d_antialiasing.rst

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
.. _doc_3d_antialiasing:
2+
3+
3D antialiasing
4+
===============
5+
6+
.. Images on this page were generated using the project below
7+
.. (except for `antialiasing_none_scaled.png`):
8+
.. https://github.com/Calinou/godot-antialiasing-comparison
9+
10+
.. seealso::
11+
12+
Godot also supports antialiasing in 2D rendering. This is covered on the
13+
:ref:`doc_2d_antialiasing` page.
14+
15+
Introduction
16+
------------
17+
18+
Due to their limited resolution, scenes rendered in 3D can exhibit aliasing
19+
artifacts. These artifacts manifest in the form of a "staircase" effect on
20+
geometry edges, but also with reflective surfaces flickering in and out
21+
(specular aliasing).
22+
23+
In the example below, you can notice how
24+
edges have a blocky appearance. The vegetation is also flickering in and out,
25+
and thin lines on top of the box have almost disappeared:
26+
27+
.. figure:: img/antialiasing_none_scaled.png
28+
:alt: Image is scaled by 2× with nearest-neighbor filtering to make aliasing more noticeable.
29+
:align: center
30+
31+
Image is scaled by 2× with nearest-neighbor filtering to make aliasing more noticeable.
32+
33+
To combat this, various antialiasing techniques can be used in Godot. These are
34+
detailed below.
35+
36+
Multisample antialiasing (MSAA)
37+
-------------------------------
38+
39+
This technique is the "historical" way of dealing with aliasing. MSAA is very
40+
effective on geometry edges (especially at higher levels). MSAA does not
41+
introduce any blurriness whatsoever.
42+
43+
MSAA in available in 3 levels: 2×, 4×, 8×. Higher levels are more effective at
44+
antialiasing edges, but are significantly more demanding. In games with modern
45+
visuals, sticking to 2× or 4× MSAA is highly recommended as 8× MSAA is usually
46+
too demanding.
47+
48+
The downside of MSAA is that it only operates on edges. This is because MSAA
49+
increases the number of *coverage* samples, but not the number of *color*
50+
samples. Using multiple coverage samples allows the coverage value to be an
51+
intermediate value between 0 and 1, rather than being limited to 0.0 *or* 1.0.
52+
The coverage value is used to determine the contribution of the pixel to the
53+
scene, with 0.0 meaning "no contribution at all" and 1.0 meaning "fully opaque
54+
pixel".
55+
56+
However, since the number of color samples did not increase, fragment shaders
57+
are still run for each pixel only once. Therefore, MSAA does not reduce
58+
transparency aliasing for materials using the **Alpha Scissor** transparency
59+
mode (1-bit transparency). MSAA is also ineffective on specular aliasing.
60+
61+
To mitigate aliasing on alpha scissor materials, alpha antialiasing (also called
62+
*alpha to coverage*) can be enabled on specific materials in the
63+
StandardMaterial3D or ORMMaterial3D properties. This only has an effect when
64+
MSAA is used (with any level). Alpha to coverage has a moderate performance
65+
cost, but it's very effective at reducing aliasing on transparent materials
66+
without introducing any blurriness.
67+
68+
MSAA can be enabled in the Project Settings by changing the value of the
69+
**Rendering > Anti Aliasing > Quality > MSAA 3D** setting. It's important to change
70+
the value of the **MSAA 3D** setting and not **MSAA 2D**, as these are entirely
71+
separate settings.
72+
73+
Comparison between no antialiasing (left) and various MSAA levels (right).
74+
Note that alpha antialiasing is not used here:
75+
76+
.. image:: img/antialiasing_msaa_2x.png
77+
78+
.. image:: img/antialiasing_msaa_4x.png
79+
80+
.. image:: img/antialiasing_msaa_8x.png
81+
82+
Temporal antialiasing (TAA)
83+
---------------------------
84+
85+
*This is only available in the Clustered Forward backend, not the Forward Mobile
86+
or Compatibility backends.*
87+
88+
Temporal antialiasing works by *converging* the result of previously rendered
89+
frames into a single, high-quality frame. This is a continuous process that
90+
works by jittering the position of all vertices in the scene every frame. This
91+
jittering is done to allow for antialiasing to work when the camera isn't
92+
moving, and is generally unnoticeable.
93+
94+
This technique is commonly used in modern games, as it provides the most
95+
effective form of antialiasing against specular aliasing and other
96+
shader-induced artifacts. TAA also provides full support for transparency
97+
antialiasing.
98+
99+
TAA introduces a small amount of blur when enabled in still scenes, but this
100+
blurring effect becomes more pronounced when the camera is moving. Another
101+
downside of TAA is that it can exhibit *ghosting* artifacts behind moving
102+
objects. Rendering at a higher framerate will allow TAA to converge faster,
103+
therefore making those ghosting artifacts less visible.
104+
105+
Temporal antialiasing can be enabled in the Project Settings by changing the
106+
value of the **Rendering > Anti Aliasing > Quality > Use Taa** setting.
107+
108+
Comparison between no antialiasing (left) and TAA (right):
109+
110+
.. image:: img/antialiasing_taa.png
111+
112+
Fast approximate antialiasing (FXAA)
113+
------------------------------------
114+
115+
*This is only available in the Clustered Forward and Forward Mobile backends,
116+
not the Compatibility backend.*
117+
118+
Fast approximate antialiasing is a post-processing antialiasing solution. It is
119+
faster to run than any other antialiasing technique and also supports
120+
antialiasing transparency. However, since it lacks temporal information, it will
121+
not do much against specular aliasing.
122+
123+
This technique is still sometimes used in mobile games. However, on desktop
124+
platforms, FXAA generally fell out of fashion in favor of temporal antialiasing,
125+
which is much more effective against specular aliasing. Nonetheless, exposing FXAA
126+
as an in-game option may still be worthwhile for players with low-end GPUs.
127+
128+
FXAA introduces a moderate amount of blur when enabled (more than TAA when
129+
still, but less than TAA when the camera is moving).
130+
131+
FXAA can be enabled in the Project Settings by changing the
132+
value of the **Rendering > Anti Aliasing > Quality > Screen Space AA** setting to
133+
**FXAA**.
134+
135+
Comparison between no antialiasing (left) and FXAA (right):
136+
137+
.. image:: img/antialiasing_fxaa.png
138+
139+
Supersample antialiasing (SSAA)
140+
-------------------------------
141+
142+
*This is only available in the Clustered Forward and Forward Mobile backends,
143+
not the Compatibility backend.*
144+
145+
Supersampling provides the highest quality of antialiasing possible, but it's
146+
also the most expensive. It works by shading every pixel in the scene multiple
147+
times. This allows SSAA to antialias edges, transparency *and* specular aliasing
148+
at the same time, without introducing potential ghosting artifacts.
149+
150+
The downside of SSAA is its *extremely* high cost. This cost generally makes
151+
SSAA difficult to use for game purposes, but you may still find supersampling
152+
useful for :ref:`offline rendering <doc_creating_movies>`.
153+
154+
Supersample antialiasing is performed by increasing the **Rendering > Scaling 3D
155+
> Scale** advanced project setting above ``1.0`` while ensuring
156+
**Rendering > Scaling 3D > Mode** is set to **Bilinear** (the default).
157+
Since the scale factor is defined per-axis, a scale factor of ``1.5`` will result
158+
in 2.25× SSAA while a scale factor of ``2.0`` will result in 4× SSAA.
159+
160+
Comparison between no antialiasing (left) and various SSAA levels (right):
161+
162+
.. image:: img/antialiasing_ssaa_2.25x.png
163+
164+
.. image:: img/antialiasing_ssaa_4x.png
165+
166+
.. warning::
167+
168+
Supersampling also has high video RAM requirements, since it needs to render
169+
in the target resolution then *downscale* to the window size. For example,
170+
displaying a project in 3840×2160 (4K resolution) with 4× SSAA will require
171+
rendering the scene in 7680×4320 (8K resolution), which is 4 times more
172+
pixels.
173+
174+
If you are using a high window size such as 4K, you may find that increasing
175+
the resolution scale past a certain value will cause a heavy slowdown (or
176+
even a crash) due to running out of VRAM.
177+
178+
Screen-space roughness limiter
179+
------------------------------
180+
181+
*This is only available in the Clustered Forward and Forward Mobile backends,
182+
not the Compatibility backend.*
183+
184+
This is not an edge antialiasing method, but it is a way of reducing specular
185+
aliasing in 3D.
186+
187+
The screen-space roughness limiter works best on detailed geometry. While it has
188+
an effect on roughness map rendering itself, its impact is limited there.
189+
190+
The screen-space roughness limiter is enabled by default; it doesn't require
191+
any manual setup. It has a small performance impact, so consider disabling it
192+
if your project isn't affected by specular aliasing much.
193+
194+
Texture roughness limiter on import
195+
-----------------------------------
196+
197+
Like the screen-space roughness limiter, this is not an edge antialiasing
198+
method, but it is a way of reducing specular aliasing in 3D.
199+
200+
Roughness limiting on import works by specifying a normal map to use as a guide
201+
for limiting roughness. This is done by selecting the roughness map in the
202+
FileSystem dock, then going to the Import dock and setting **Roughness > Mode**
203+
to the color channel the roughness map is stored in (typically **Green**), then
204+
setting the path to the material's normal map. Remember to click **Reimport**
205+
at the bottom of the Import dock after setting the path to the normal map.
206+
207+
Since this processing occurs purely on import, it has no performance cost
208+
whatsoever. However, its visual impact is limited. Limiting roughness on import
209+
only helps reduce specular aliasing within textures, not the aliasing that
210+
occurs on geometry edges on detailed meshes.
211+
212+
Which antialiasing technique should I use?
213+
------------------------------------------
214+
215+
**There is no "one size fits all" antialiasing technique.** Since antialiasing is
216+
often demanding on the GPU or can introduce unwanted blurriness, you'll want to
217+
add a setting to allow players to disable antialiasing.
218+
219+
For projects with a photorealistic art direction, TAA is generally the most
220+
suitable option. While TAA can introduce ghosting artifacts, there is no other
221+
technique that combats specular aliasing as well as TAA does. The screen-space
222+
roughness limiter helps a little, but is far less effective against specular
223+
aliasing overall.
224+
225+
For projects with a low amount of reflective surfaces (such as a cartoon
226+
artstyle), MSAA can work well. MSAA is also a good option if avoiding blurriness
227+
and temporal artifacts is important, such as in competitive games.
228+
229+
When targeting low-end platforms such as mobile or integrated graphics, FXAA is
230+
usually the only viable option. 2× MSAA may be usable in some circumstances,
231+
but higher MSAA levels are unlikely to run smoothly on mobile GPUs.
232+
233+
Godot allows using multiple antialiasing techniques at the same time. This is
234+
usually unnecessary, but it can provide better visuals on high-end GPUs or for
235+
:ref:`non-real-time rendering <doc_creating_movies>`. For example, to make
236+
moving edges look better when TAA is enabled, you can also enable MSAA at the
237+
same time.

0 commit comments

Comments
 (0)