3d_antialiasing.rst 12 KB

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