2d_antialiasing.rst 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. .. _doc_2d_antialiasing:
  2. 2D 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 3D rendering. This is covered on the
  9. :ref:`doc_3d_antialiasing` page.
  10. Introduction
  11. ------------
  12. Due to their limited resolution, scenes rendered in 2D can exhibit aliasing
  13. artifacts. These artifacts usually manifest in the form of a "staircase" effect on
  14. geometry edges, and are most noticeable when using nodes such as :ref:`class_Line2D`,
  15. :ref:`class_Polygon2D` or :ref:`class_TextureProgressBar`. :ref:`doc_custom_drawing_in_2d`
  16. can also have aliasing artifacts for methods that don't support antialiasing.
  17. In the example below, you can notice how
  18. edges have a blocky appearance:
  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, Godot supports several methods of enabling antialiasing on 2D rendering.
  24. Antialiasing property in Line2D and custom drawing
  25. --------------------------------------------------
  26. This is the recommended method, as it has a lower performance impact in most cases.
  27. Line2D has an **Antialiased** property which you can enable in the inspector.
  28. Also, several methods for :ref:`doc_custom_drawing_in_2d` support an optional
  29. ``antialiased`` parameter, which can be set to ``true`` when calling the
  30. function.
  31. These methods do not require MSAA to be enabled, which makes their *baseline*
  32. performance cost low. In other words, there is no permanent added cost if you're
  33. not drawing any antialiased geometry at some point.
  34. The downside of these antialiasing methods is that they work by generating
  35. additional geometry. If you're generating complex 2D geometry that's updated
  36. every frame, this may be a bottleneck. Also, Polygon2D, TextureProgressBar, and
  37. several custom drawing methods don't feature an antialiased property. For these
  38. nodes, you can use 2D multisample antialiasing instead.
  39. Multisample antialiasing (MSAA)
  40. -------------------------------
  41. *This is only available in the Forward+ and Mobile renderers, not the
  42. Compatibility renderer.*
  43. Before enabling MSAA in 2D, it's important to understand what MSAA will operate
  44. on. MSAA in 2D follows similar restrictions as in 3D. While it does not
  45. introduce any blurriness, its scope of application is limited. The main
  46. applications of 2D MSAA are:
  47. - Geometry edges, such as line and polygon drawing.
  48. - Sprite edges *only for pixels touching one of the texture's edges*. This works
  49. for both linear and nearest-neighbor filtering. Sprite edges created using
  50. transparency on the image are not affected by MSAA.
  51. The downside of MSAA is that it only operates on edges. This is because MSAA
  52. increases the number of *coverage* samples, but not the number of *color*
  53. samples. However, since the number of color samples did not increase, fragment
  54. shaders are still run for each pixel only once. As a result, MSAA will **not
  55. affect** the following kinds of aliasing in any way:
  56. - Aliasing *within* nearest-neighbor filtered textures (pixel art).
  57. - Aliasing caused by custom 2D shaders.
  58. - Specular aliasing when using Light2D.
  59. - Aliasing in font rendering.
  60. MSAA can be enabled in the Project Settings by changing the value of the
  61. :ref:`Rendering > Anti Aliasing > Quality > MSAA 2D<class_ProjectSettings_property_rendering/anti_aliasing/quality/msaa_2d>`
  62. setting. It's important to change the value of the **MSAA 2D** setting and not **MSAA 3D**, as these are entirely
  63. separate settings.
  64. Comparison between no antialiasing (left) and various MSAA levels (right). The
  65. top-left corner contains a Line2D node, the top-right corner contains 2
  66. TextureProgressBar nodes. The bottom contains 8 pixel art sprites, with 4 of
  67. them touching the edges (green background) and 4 of them not touching the edges
  68. (Godot logo):
  69. .. image:: img/antialiasing_msaa_2x.webp
  70. .. image:: img/antialiasing_msaa_4x.webp
  71. .. image:: img/antialiasing_msaa_8x.webp