visibility_ranges.rst 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. .. _doc_visibility_ranges:
  2. Visibility ranges (HLOD)
  3. ========================
  4. Along with :ref:`doc_mesh_lod` and :ref:`doc_occlusion_culling`,
  5. visibility ranges are another tool to improve performance in large,
  6. complex 3D scenes.
  7. On this page, you'll learn:
  8. - What visibility ranges can do and which scenarios they are useful in.
  9. - How to set up visibility ranges (manual LOD) in Godot.
  10. - How to tune visibility ranges for best performance and quality.
  11. .. seealso::
  12. If you only need meshes to become less detailed over distance but don't have
  13. manually authored LOD meshes, consider relying on automatic
  14. :ref:`doc_mesh_lod` instead.
  15. Note that automatic mesh LOD and visibility ranges can be used at the same
  16. time, even on the same mesh.
  17. How it works
  18. ------------
  19. Visibility ranges can be used with any node that inherits from GeometryInstance3D.
  20. This means they can be used not only with MeshInstance3D and MultiMeshInstance3D
  21. for artist-controlled :abbr:`HLOD (Hierarchical Level of Detail)`, but also
  22. GPUParticles3D, CPUParticles3D, Label3D, Sprite3D, AnimatedSprite3D and CSGShape3D.
  23. Since visibility ranges are configured on a per-node basis, this makes it possible
  24. to use different node types as part of a :abbr:`LOD (Level of Detail)` system.
  25. For example, you could display a MeshInstance3D representing a tree when up close,
  26. and replace it with a Sprite3D impostor in the distance to improve performance.
  27. The benefit of :abbr:`HLOD (Hierarchical Level of Detail)` over a traditional
  28. :abbr:`LOD (Level of Detail)` system is its hierarchical nature. A single larger
  29. mesh can replace several smaller meshes, so that the number of draw calls can be
  30. reduced at a distance, but culling opportunities can be preserved when up close.
  31. For example, you can have a group of houses that uses individual MeshInstance3D
  32. nodes (one for each house) when up close, but turns into a single MeshInstance3D
  33. that represents a less detailed group of houses (or use a MultiMeshInstance3D).
  34. Lastly, visibility ranges can also be used to fade certain objects entirely when
  35. the camera gets too close or too far. This can be used for gameplay purposes,
  36. but also to reduce visual clutter. For example, Label3D nodes can be faded using
  37. visibility ranges when they're too far away to be readable or relevant to the
  38. player.
  39. Setting up visibility range
  40. ---------------------------
  41. This is a quick-start guide for configuring a basic LOD system. After following
  42. this guide, this LOD system will display a SphereMesh when up close and a
  43. BoxMesh when the camera is far away enough. A small hysteresis margin is also
  44. configured via the **Begin Margin** and **End Margin** properties. This prevents
  45. LODs from popping back and forth too quickly when the camera is moving at the
  46. "edge" of the LOD transition.
  47. The visibility range properties can be found in the **Visibility Range** section
  48. of the GeometryInstance3D inspector after selecting the MeshInstance3D Node.
  49. - Add a Node3D node that will be used to group the two MeshInstance3D nodes
  50. together.
  51. - Add a first MeshInstance3D node as a child of the Node3D. Assign a new
  52. SphereMesh to its Mesh property.
  53. - Set the first MeshInstance3D's visibility range **End** to ``10.0`` and **End
  54. Margin** to ``1.0``.
  55. - Add a second MeshInstance3D node as a child of the Node3D. Assign a new
  56. BoxMesh to its Mesh property.
  57. - Set the second MeshInstance3D's visibility range **Begin** to ``10.0`` and
  58. **Begin Margin** to ``1.0``.
  59. - Move the camera away and back towards the object. Notice how the object will
  60. transition from a sphere to a box as the camera moves away.
  61. Visibility range properties
  62. ---------------------------
  63. In the inspector of any node that inherits from GeometryInstance3D, you can adjust
  64. the following properties in the GeometryInstance3D's **Visibility Range** section:
  65. - **Begin:** The instance will be hidden when the camera is closer to the
  66. instance's *origin* than this value (in 3D units).
  67. - **Begin Margin:** The hysteresis or alpha fade transition distance to use for
  68. the close-up transition (in 3D units). The behavior of this property depends
  69. on **Fade Mode**.
  70. - **End:** The instance will be hidden when the camera is further away from the
  71. instance's *origin* than this value (in 3D units).
  72. - **End Margin:** The hysteresis or alpha fade transition distance to use for
  73. the far-away transition (in 3D units). The behavior of this property depends
  74. on **Fade Mode**.
  75. - **Fade Mode:** Controls how the transition between LOD levels should be performed.
  76. See below for details.
  77. Fade mode
  78. ^^^^^^^^^
  79. .. note::
  80. The fade mode chosen only has a visible impact if either
  81. **Visibility Range > Begin Margin** or **Visibility Range > End Margin** is
  82. greater than ``0.0``.
  83. In the inspector's **Visibility Range** section, there are 3 fade modes to
  84. choose from:
  85. - **Disabled:** Uses hysteresis to switch between LOD levels instantly. This
  86. prevents situations where LOD levels are switched back and forth quickly when
  87. the player moves forward and then backward at the LOD transition point. The
  88. hystereis distance is determined by **Visibility Range > Begin Margin** and
  89. **Visibility Range > End Margin**. This mode provides the best performance as
  90. it doesn't force rendering to become transparent during the fade transition.
  91. - **Self:** Uses alpha blending to smoothly fade between LOD levels. The fade
  92. transition distance is determined by **Visibility Range > Begin Margin** and
  93. **Visibility Range > End Margin**. This mode forces transparent rendering on
  94. the object during its fade transition, so it has a performance impact.
  95. - **Dependencies:** This is intended for hierarchical LOD systems, and acts the
  96. same as **Self** if visibility ranges are used to perform non-hierarchical
  97. LOD.
  98. Configuration tips
  99. ------------------
  100. Use simpler materials at a distance to improve performance
  101. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  102. One way to further improve performance is to use simpler materials for distant
  103. LOD meshes. While using LOD meshes will reduce the number of vertices that need
  104. to be rendered, the per-pixel shading load for materials remains identical.
  105. However, per-pixel shading load is regularly a bottleneck on the GPU in complex
  106. 3D scenes. One way to reduce this shading load on the GPU is to use simpler
  107. materials when they don't make much of a visual difference.
  108. Performance gains when doing so should be carefully measured, as
  109. increasing the number of *unique* materials in a scene has a performance cost on
  110. its own. Still, using simpler materials for distant LOD meshes can still result
  111. in a net performance gain as a result of the fewer per-pixel calculations
  112. required.
  113. For example, on the materials used by distant LOD meshes, you can disable
  114. expensive material features such as:
  115. - Normal Map (especially on mobile platforms)
  116. - Rim
  117. - Clearcoat
  118. - Anisotropy
  119. - Height
  120. - Subsurface Scattering
  121. - Back Lighting
  122. - Refraction
  123. - Proximity Fade
  124. Use dithering for LOD transitions
  125. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  126. Godot currently only supports alpha-based fading for visibility ranges. You can
  127. however use dithering instead by using several different materials for different
  128. LOD levels.
  129. There are two advantages to using dithering over alpha blending for LOD transitions:
  130. - Higher performance, as dithering transparency is faster to render compared to
  131. alpha blending.
  132. - No visual glitches due to
  133. :ref:`transparency sorting issues <doc_3d_rendering_limitations_transparency_sorting>`
  134. during LOD transitions.
  135. The downside of dithering is that a "noisy" pattern is visible during LOD fade
  136. transitions. This may not be as noticeable at higher viewport resolutions or
  137. when temporal antialiasing is enabled.
  138. Also, as distance fade in BaseMaterial3D only supports fading up close *or*
  139. fading when far away, this setup is best used with only two LODs as part of the
  140. setup.
  141. - Ensure **Begin Margin** and **End Margin** is set to ``0.0`` on both
  142. MeshInstance3D nodes, as hysteresis or alpha fade are not desired here.
  143. - On both MeshInstance3D nodes, *decrease* **Begin** by the desired fade transition
  144. distance and *increase* **End** by the same distance. This is required for the
  145. dithering transition to actually be visible.
  146. - On the MeshInstance3D that is displayed up close, edit its material in the inspector.
  147. Set its **Distance Fade** mode to **Object Dither**. Set **Min Distance** to
  148. the same value as the visibility range **End**. Set **Max Distance** to the
  149. same value *minus* the fade transition distance.
  150. - On the MeshInstance3D that is displayed far away, edit its material in the inspector.
  151. Set its **Distance Fade** mode to **Object Dither**. Set **Min Distance** to
  152. the same value as the visibility range **Begin**. Set **Max Distance** to the
  153. same value *plus* the fade transition distance.