3d_rendering_limitations.rst 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. .. _doc_3d_rendering_limitations:
  2. 3D rendering limitations
  3. ========================
  4. Introduction
  5. ------------
  6. Due to their focus on performance, real-time rendering engines have many
  7. limitations. Godot's renderer is no exception. To work effectively with those
  8. limitations, you need to understand them.
  9. Texture size limits
  10. -------------------
  11. On desktops and laptops, textures larger than 8192×8192 may not be supported on
  12. older devices. You can check your target GPU's limitations on
  13. `GPUinfo.org <https://www.gpuinfo.org/>`__.
  14. Mobile GPUs are typically limited to 4096×4096 textures. Also, some mobile GPUs
  15. don't support repeating non-power-of-two-sized textures. Therefore, if you want
  16. your texture to display correctly on all platforms, you should avoid using
  17. textures larger than 4096×4096 and use a power of two size if the texture needs
  18. to repeat.
  19. To limit the size of a specific texture that may be too large to render, you can
  20. set the **Process > Size Limit** import option to a value greater than ``0``.
  21. This will reduce the texture's dimensions on import (preserving aspect ratio)
  22. without affecting the source file.
  23. .. _doc_3d_rendering_limitations_color_banding:
  24. Color banding
  25. -------------
  26. When using the Forward+ or Mobile rendering methods, Godot's 3D engine
  27. renders internally in HDR. However, the rendering output will be tonemapped to a
  28. low dynamic range so it can be displayed on the screen. This can result in
  29. visible banding, especially when using untextured materials. For performance
  30. reasons, color precision is also lower when using the Mobile rendering method
  31. compared to Forward+.
  32. When using the Compatibility rendering method, HDR is not used and the color
  33. precision is the lowest of all rendering methods. This also applies to 2D
  34. rendering, where banding may be visible when using smooth gradient textures.
  35. There are two main ways to alleviate banding:
  36. - If using the Forward+ or Forward Mobile rendering methods, enable
  37. :ref:`Use Debanding<class_ProjectSettings_property_rendering/anti_aliasing/quality/use_debanding>`
  38. in **Project Settings > Rendering > Anti Aliasing**. This applies a fullscreen debanding
  39. shader as a post-processing effect and is very cheap.
  40. - Alternatively, bake some noise into your textures. This is mainly effective in
  41. 2D, e.g. for vignetting effects. In 3D, you can also use a `custom debanding
  42. shader <https://github.com/fractilegames/godot-gles2-debanding-material>`__ to
  43. be applied on your *materials*. This technique works even if your project is
  44. rendered with low color precision, which means it will work when using the
  45. Mobile and Compatibility rendering methods.
  46. .. figure:: img/3d_rendering_limitations_banding.webp
  47. :align: center
  48. :alt: Color banding comparison (contrast increased for more visibility)
  49. Color banding comparison (contrast increased for more visibility)
  50. .. seealso::
  51. See `Banding in Games: A Noisy Rant (PDF) <https://loopit.dk/banding_in_games.pdf>`__
  52. for more details about banding and ways to combat it.
  53. Depth buffer precision
  54. ----------------------
  55. To sort objects in 3D space, rendering engines rely on a *depth buffer* (also
  56. called *Z-buffer*). This buffer has a finite precision: 24-bit on desktop
  57. platforms, sometimes 16-bit on mobile platforms (for performance reasons). If
  58. two different objects end up on the same buffer value, then Z-fighting will
  59. occur. This will materialize as textures flickering back and forth as the camera
  60. moves or rotates.
  61. To make the depth buffer more precise over the rendered area, you should
  62. *increase* the Camera node's **Near** property. However, be careful: if you set
  63. it too high, players will be able to see through nearby geometry. You should
  64. also *decrease* the Camera node's **Far** property to the lowest permissible value
  65. for your use case, though keep in mind it won't impact precision as much as the
  66. **Near** property.
  67. If you only need high precision when the player can see far away, you could
  68. change it dynamically based on the game conditions. For instance, if the player
  69. enters an airplane, the **Near** property can be temporarily increased to avoid
  70. Z-fighting in the distance. It can then be decreased once the player leaves the
  71. airplane.
  72. Depending on the scene and viewing conditions, you may also be able to move the
  73. Z-fighting objects further apart without the difference being visible to the
  74. player.
  75. .. figure:: img/3d_rendering_limitations_z_fighting.webp
  76. :align: center
  77. :alt: Z-fighting comparison (before and after tweaking the scene by offsetting the Label3D away from the floor)
  78. Z-fighting comparison (before and after tweaking the scene by offsetting the Label3D away from the floor)
  79. .. _doc_3d_rendering_limitations_transparency_sorting:
  80. Transparency sorting
  81. --------------------
  82. In Godot, transparent materials are drawn after opaque materials. Transparent
  83. objects are sorted back to front before being drawn based on the Node3D's
  84. position, not the vertex position in world space. Due to this, overlapping
  85. objects may often be sorted out of order. To fix improperly sorted objects,
  86. tweak the material's
  87. :ref:`Render Priority <class_Material_property_render_priority>`
  88. property or the node's
  89. :ref:`Sorting Offset <class_VisualInstance3D_property_sorting_offset>`.
  90. Render Priority will force specific materials to appear in front of or behind
  91. other transparent materials, while Sorting Offset will move the object
  92. forward or backward for the purpose of sorting. Even then, these may not
  93. always be sufficient.
  94. Some rendering engines feature *order-independent transparency* techniques to
  95. alleviate this, but this is costly on the GPU. Godot currently doesn't provide
  96. this feature. There are still several ways to avoid this problem:
  97. - Only make materials transparent if you actually need it. If a material only
  98. has a small transparent part, consider splitting it into a separate material.
  99. This will allow the opaque part to cast shadows and will also improve performance.
  100. - If your texture mostly has fully opaque and fully transparent areas, you can
  101. use alpha testing instead of alpha blending. This transparency mode is faster
  102. to render and doesn't suffer from transparency issues. Enable **Transparency >
  103. Transparency** to **Alpha Scissor** in StandardMaterial3D, and adjust
  104. **Transparency > Alpha Scissor Threshold** accordingly if needed. Note that
  105. MSAA will not antialias the texture's edges unless alpha antialiasing is
  106. enabled in the material's properties. However, FXAA, TAA and supersampling
  107. will be able to antialias the texture's edges regardless of whether alpha
  108. antialiasing is enabled on the material.
  109. - If you need to render semi-transparent areas of the texture, alpha scissor
  110. isn't suitable. Instead, setting the StandardMaterial3D's
  111. **Transparency > Transparency** property to **Depth Pre-Pass** can sometimes
  112. work (at a performance cost). You can also try the **Alpha Hash** mode.
  113. - If you want a material to fade with distance, use the StandardMaterial3D
  114. distance fade mode **Pixel Dither** or **Object Dither** instead of
  115. **Pixel Alpha**. This will make the material opaque, which also speeds up rendering.
  116. .. figure:: img/3d_rendering_limitations_transparency_sorting.webp
  117. :align: center
  118. :alt: Transparency sorting comparison (alpha-blended materials on the left, alpha scissor materials on the right)
  119. Transparency sorting comparison (alpha-blended materials on the left, alpha scissor materials on the right)