3d_antialiasing.rst 12 KB

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