Skip to content

Commit 587948f

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

19 files changed

+380
-35
lines changed

about/list_of_features.rst

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,6 @@ Vulkan 1.0, with Vulkan 1.1 and 1.2 features optionally used.
156156
- Perspective, orthographic and frustum-offset cameras.
157157
- When using the Vulkan Clustered backend (default on desktop), a depth prepass
158158
is used to improve performance in complex scenes by reducing the cost of overdraw.
159-
- Support for rendering 3D at a lower resolution while keeping 2D rendering at
160-
the original scale. This can be used to improve performance on low-end systems
161-
or improve visuals on high-end systems.
162-
163-
- 3D rendering can be scaled with bilinear filtering or
164-
`AMD FidelityFX Super Resolution 1.0 <https://www.amd.com/en/technologies/fidelityfx-super-resolution>`__.
165159

166160
- `OpenGL support planned for a future Godot 4.x release <https://godotengine.org/article/about-godot4-vulkan-gles3-and-gles2>`__.
167161

@@ -331,12 +325,23 @@ Vulkan 1.0, with Vulkan 1.1 and 1.2 features optionally used.
331325

332326
**Anti-aliasing:**
333327

328+
- Temporal antialiasing (TAA).
329+
- Multi-sample antialiasing (MSAA), for both :ref:`doc_2d_antialiasing` and :ref:`doc_3d_antialiasing`.
334330
- Fast approximate antialiasing (FXAA).
335-
- Multi-sample antialiasing (MSAA).
336331
- 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.
332+
- Alpha antialiasing, MSAA alpha to coverage and alpha hashing on a per-material basis.
333+
334+
**Resolution scaling:**
335+
336+
- Support for rendering 3D at a lower resolution while keeping 2D rendering at
337+
the original scale. This can be used to improve performance on low-end systems
338+
or improve visuals on high-end systems.
339+
- Resolution scaling uses bilinear filtering or AMD FidelityFX Super Resolution
340+
1.0 (FSR).
341+
- Texture mipmap LOD bias is adjusted automatically to improve quality at lower
342+
resolution scales. It can also be modified with a manual offset.
338343

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

342347
3D tools

tutorials/2d/2d_antialiasing.rst

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

0 commit comments

Comments
 (0)