3d_rendering_limitations.rst 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. .. _doc_3d_rendering_limitations:
  2. 3D rendering limitations
  3. ========================
  4. .. seealso::
  5. In addition to the limitations below, mobile platforms have even more
  6. limitations on 3D rendering compared to desktop platforms.
  7. See :ref:`doc_mobile_rendering_limitations` for more information.
  8. Introduction
  9. ------------
  10. Due to their focus on performance, real-time rendering engines have many
  11. limitations. Godot's renderer is no exception. To work effectively with those
  12. limitations, you need to understand them.
  13. Texture size limits
  14. -------------------
  15. On desktops and laptops, textures larger than 8192×8192 may not be supported on
  16. older devices. You can check your target GPU's limitations on
  17. `GPUinfo.org <https://www.gpuinfo.org/>`__.
  18. Mobile GPUs are typically limited to 4096×4096 textures. Also, some mobile GPUs
  19. don't support repeating non-power-of-two-sized textures. Therefore, if you want
  20. your texture to display correctly on all platforms, you should avoid using
  21. textures larger than 4096×4096 and use a power of two size if the texture needs
  22. to repeat.
  23. Color banding
  24. -------------
  25. When using the GLES3 or Vulkan renderers, Godot's 3D engine renders internally
  26. in HDR. However, the rendering output will be tonemapped to a low dynamic range
  27. so it can be displayed on the screen. This can result in visible banding,
  28. especially when using untextured materials. This can also be seen in 2D projects
  29. when using smooth gradient textures.
  30. There are two main ways to alleviate banding:
  31. - Enable **Use Debanding** in the Project Settings. This applies a
  32. fullscreen debanding shader as a post-processing effect and is very cheap.
  33. Fullscreen debanding is only supported when using the GLES3 or Vulkan renderers.
  34. It also requires HDR to be enabled in the Project Settings (which is the default).
  35. - Alternatively, bake some noise into your textures. This is mainly effective in 2D,
  36. e.g. for vignetting effects. In 3D, you can also use a
  37. `custom debanding shader <https://github.com/fractilegames/godot-gles2-debanding-material>`__
  38. to be applied on your *materials*. This technique works even if your project is
  39. rendered in LDR, which means it will work when using the GLES2 renderer.
  40. .. seealso::
  41. See `Banding in Games: A Noisy Rant <http://loopit.dk/banding_in_games.pdf>`__
  42. for more details about banding and ways to combat it.
  43. Depth buffer precision
  44. ----------------------
  45. To sort objects in 3D space, rendering engines rely on a *depth buffer* (also
  46. called *Z-buffer*). This buffer has a finite precision: 24-bit on desktop
  47. platforms, sometimes 16-bit on mobile platforms (for performance reasons). If
  48. two different objects end up on the same buffer value, then Z-fighting will
  49. occur. This will materialize as textures flickering back and forth as the camera
  50. moves or rotates.
  51. To make the depth buffer more precise over the rendered area, you should
  52. *increase* the Camera node's **Near** property. However, be careful: if you set
  53. it too high, players will be able to see through nearby geometry. You should
  54. also *decrease* the Camera node's **Far** property to the lowest permissible value
  55. for your use case, though keep in mind it won't impact precision as much as the
  56. **Near** property.
  57. If you only need high precision when the player can see far away, you could
  58. change it dynamically based on the game conditions. For instance, if the player
  59. enters an airplane, the **Near** property can be temporarily increased to avoid
  60. Z-fighting in the distance. It can then be decreased once the player leaves the
  61. airplane.
  62. Depending on the scene and viewing conditions, you may also be able to move the
  63. Z-fighting objects further apart without the difference being visible to the
  64. player.
  65. .. _doc_3d_rendering_limitations_transparency_sorting:
  66. Transparency sorting
  67. --------------------
  68. In Godot, transparent materials are drawn after opaque materials. Transparent
  69. objects are sorted back to front before being drawn based on the Spatial's
  70. position, not the vertex position in world space. Due to this, overlapping
  71. objects may often be sorted out of order. To fix improperly sorted objects, tweak
  72. the material's :ref:`Render Priority <class_Material_property_render_priority>`
  73. property. This will force specific materials to appear in front or behind of
  74. other transparent materials. Even then, this may not always be sufficient.
  75. Some rendering engines feature *order-independent transparency* techniques to
  76. alleviate this, but this is costly on the GPU. Godot currently doesn't provide
  77. this feature. There are still several ways to avoid this problem:
  78. - Only make materials transparent if you actually need it. If a material only
  79. has a small transparent part, consider splitting it into a separate material.
  80. This will allow the opaque part to cast shadows and may also improve
  81. performance.
  82. - If your texture mostly has fully opaque and fully transparent areas, you can
  83. use alpha testing instead of alpha blending. This transparency mode is faster
  84. to render and doesn't suffer from transparency issues. Enable
  85. **Parameters > Use Alpha Scissor** in SpatialMaterial, and adjust
  86. **Alpha Scissor Threshold** accordingly if needed. Note that MSAA will not
  87. anti-alias the texture's edges, but FXAA will.
  88. - If you need to render semi-transparent areas of the texture, alpha scissor
  89. isn't suitable. Instead, setting the SpatialMaterial's
  90. **Parameters > Depth Draw Mode** property to **Opaque Pre-Pass** can sometimes
  91. work (at a performance cost).
  92. - If you want a material to fade with distance, use the SpatialMaterial
  93. distance fade mode **Pixel Dither** or **Object Dither** instead of
  94. **PixelAlpha**. This will make the material opaque. This way, it can also
  95. cast shadows.
  96. Multi-sample antialiasing
  97. -------------------------
  98. Multi-sample antialiasing (MSAA) takes multiple *coverage* samples at the edges
  99. of polygons when rendering objects. It does not increase the number of *color*
  100. samples used to render a scene. Here's what this means in practice:
  101. - Edges of meshes will be smoothed out nicely (as well as supersampling would).
  102. - Transparent materials that use *alpha testing* (1-bit transparency) won't be smoothed out.
  103. - Specular aliasing ("sparkles" that appear on reflective surfaces) won't be reduced.
  104. There are several ways to work around this limitation depending on your performance budget:
  105. - To make specular aliasing less noticeable, open the Project Settings and enable
  106. **Rendering > Quality > Screen Space Filters > Screen Space Roughness Limiter**.
  107. This filter has a moderate cost on performance. It should be enabled only if
  108. you actually need it.
  109. - Enable FXAA in addition to (or instead of) MSAA. Since FXAA is a screen-space
  110. antialiasing method, it will smooth out anything. As a downside, it will also
  111. make the scene appear blurrier, especially at resolutions below 1440p.
  112. - Render the scene at a higher resolution, then display it in a ViewportTexture
  113. that matches the window size. Make sure to enable **Filter** on the
  114. ViewportTexture flags. This technique is called *supersampling* and is very
  115. slow. Its use is generally only recommended for offline rendering.