3d_antialiasing.rst 18 KB

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