2
0

3d_antialiasing.rst 10 KB

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