|
| 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