3d_antialiasing.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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, alpha antialiasing (also called
  44. *alpha to coverage*) can be enabled on specific materials in the
  45. StandardMaterial3D or ORMMaterial3D properties. This only has an effect when
  46. MSAA is used (with any level). Alpha to coverage has a moderate performance
  47. cost, but it's very effective at reducing aliasing on transparent materials
  48. without introducing any blurriness.
  49. MSAA can be enabled in the Project Settings by changing the value of the
  50. **Rendering > Anti Aliasing > Quality > MSAA 3D** setting. It's important to change
  51. 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
  78. value of the **Rendering > Anti Aliasing > Quality > Use Taa** setting.
  79. Comparison between no antialiasing (left) and TAA (right):
  80. .. image:: img/antialiasing_taa.webp
  81. .. _doc_3d_antialiasing_fxaa:
  82. Fast approximate antialiasing (FXAA)
  83. ------------------------------------
  84. *This is only available in the Clustered Forward and Forward Mobile backends,
  85. not the Compatibility backend.*
  86. Fast approximate antialiasing is a post-processing antialiasing solution. It is
  87. faster to run than any other antialiasing technique and also supports
  88. antialiasing transparency. However, since it lacks temporal information, it will
  89. not do much against specular aliasing.
  90. This technique is still sometimes used in mobile games. However, on desktop
  91. platforms, FXAA generally fell out of fashion in favor of temporal antialiasing,
  92. which is much more effective against specular aliasing. Nonetheless, exposing FXAA
  93. as an in-game option may still be worthwhile for players with low-end GPUs.
  94. FXAA introduces a moderate amount of blur when enabled (more than TAA when
  95. still, but less than TAA when the camera is moving).
  96. FXAA can be enabled in the Project Settings by changing the
  97. value of the **Rendering > Anti Aliasing > Quality > Screen Space AA** setting to
  98. **FXAA**.
  99. Comparison between no antialiasing (left) and FXAA (right):
  100. .. image:: img/antialiasing_fxaa.webp
  101. Supersample antialiasing (SSAA)
  102. -------------------------------
  103. *This is only available in the Clustered Forward and Forward Mobile backends,
  104. not the Compatibility backend.*
  105. Supersampling provides the highest quality of antialiasing possible, but it's
  106. also the most expensive. It works by shading every pixel in the scene multiple
  107. times. This allows SSAA to antialias edges, transparency *and* specular aliasing
  108. at the same time, without introducing potential ghosting artifacts.
  109. The downside of SSAA is its *extremely* high cost. This cost generally makes
  110. SSAA difficult to use for game purposes, but you may still find supersampling
  111. useful for :ref:`offline rendering <doc_creating_movies>`.
  112. Supersample antialiasing is performed by increasing the **Rendering > Scaling 3D
  113. > Scale** advanced project setting above ``1.0`` while ensuring
  114. **Rendering > Scaling 3D > Mode** is set to **Bilinear** (the default).
  115. Since the scale factor is defined per-axis, a scale factor of ``1.5`` will result
  116. in 2.25× SSAA while a scale factor of ``2.0`` will result in 4× SSAA.
  117. Comparison between no antialiasing (left) and various SSAA levels (right):
  118. .. image:: img/antialiasing_ssaa_2.25x.webp
  119. .. image:: img/antialiasing_ssaa_4x.webp
  120. .. warning::
  121. Supersampling also has high video RAM requirements, since it needs to render
  122. in the target resolution then *downscale* to the window size. For example,
  123. displaying a project in 3840×2160 (4K resolution) with 4× SSAA will require
  124. rendering the scene in 7680×4320 (8K resolution), which is 4 times more
  125. pixels.
  126. If you are using a high window size such as 4K, you may find that increasing
  127. the resolution scale past a certain value will cause a heavy slowdown (or
  128. even a crash) due to running out of VRAM.
  129. Screen-space roughness limiter
  130. ------------------------------
  131. *This is only available in the Clustered Forward and Forward Mobile backends,
  132. not the Compatibility backend.*
  133. This is not an edge antialiasing method, but it is a way of reducing specular
  134. aliasing in 3D.
  135. The screen-space roughness limiter works best on detailed geometry. While it has
  136. an effect on roughness map rendering itself, its impact is limited there.
  137. The screen-space roughness limiter is enabled by default; it doesn't require
  138. any manual setup. It has a small performance impact, so consider disabling it
  139. if your project isn't affected by specular aliasing much.
  140. Texture roughness limiter on import
  141. -----------------------------------
  142. Like the screen-space roughness limiter, this is not an edge antialiasing
  143. method, but it is a way of reducing specular aliasing in 3D.
  144. Roughness limiting on import works by specifying a normal map to use as a guide
  145. for limiting roughness. This is done by selecting the roughness map in the
  146. FileSystem dock, then going to the Import dock and setting **Roughness > Mode**
  147. to the color channel the roughness map is stored in (typically **Green**), then
  148. setting the path to the material's normal map. Remember to click **Reimport**
  149. at the bottom of the Import dock after setting the path to the normal map.
  150. Since this processing occurs purely on import, it has no performance cost
  151. whatsoever. However, its visual impact is limited. Limiting roughness on import
  152. only helps reduce specular aliasing within textures, not the aliasing that
  153. occurs on geometry edges on detailed meshes.
  154. Which antialiasing technique should I use?
  155. ------------------------------------------
  156. **There is no "one size fits all" antialiasing technique.** Since antialiasing is
  157. often demanding on the GPU or can introduce unwanted blurriness, you'll want to
  158. add a setting to allow players to disable antialiasing.
  159. For projects with a photorealistic art direction, TAA is generally the most
  160. suitable option. While TAA can introduce ghosting artifacts, there is no other
  161. technique that combats specular aliasing as well as TAA does. The screen-space
  162. roughness limiter helps a little, but is far less effective against specular
  163. aliasing overall.
  164. For projects with a low amount of reflective surfaces (such as a cartoon
  165. artstyle), MSAA can work well. MSAA is also a good option if avoiding blurriness
  166. and temporal artifacts is important, such as in competitive games.
  167. When targeting low-end platforms such as mobile or integrated graphics, FXAA is
  168. usually the only viable option. 2× MSAA may be usable in some circumstances,
  169. but higher MSAA levels are unlikely to run smoothly on mobile GPUs.
  170. Godot allows using multiple antialiasing techniques at the same time. This is
  171. usually unnecessary, but it can provide better visuals on high-end GPUs or for
  172. :ref:`non-real-time rendering <doc_creating_movies>`. For example, to make
  173. moving edges look better when TAA is enabled, you can also enable MSAA at the
  174. same time.