using_sdfgi.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. .. _doc_using_sdfgi:
  2. Signed distance field global illumination (SDFGI)
  3. =================================================
  4. Signed distance field global illumination (SDFGI) is a novel technique available
  5. in Godot 4.0. It provides semi-real-time global illumination that scales to any
  6. world size and works with procedurally generated levels.
  7. SDFGI supports dynamic lights, but *not* dynamic occluders or dynamic emissive surfaces.
  8. Therefore, SDFGI provides better real-time ability than
  9. :ref:`baked lightmaps <doc_using_lightmap_gi>`, but worse real-time ability than
  10. :ref:`VoxelGI <doc_using_voxel_gi>`.
  11. From a performance standpoint, SDFGI is one of the most demanding global illumination
  12. techniques in Godot. Like with VoxelGI, there are still many settings available to tweak
  13. its performance requirements at the cost of quality.
  14. .. important::
  15. SDFGI is only supported when using the Forward+ renderer, not the Mobile or
  16. Compatibility renderers.
  17. .. seealso::
  18. Not sure if SDFGI is suited to your needs?
  19. See :ref:`doc_introduction_to_global_illumination_comparison`
  20. for a comparison of GI techniques available in Godot 4.
  21. Visual comparison
  22. -----------------
  23. .. figure:: img/gi_none.webp
  24. :alt: SDFGI disabled.
  25. SDFGI disabled.
  26. .. figure:: img/gi_sdfgi.webp
  27. :alt: SDFGI enabled.
  28. SDFGI enabled.
  29. Setting up SDFGI
  30. ----------------
  31. In Godot, SDFGI is the global illumination technique with the fewest required
  32. steps to enable:
  33. 1. Make sure your MeshInstance nodes have their **Global Illumination > Mode**
  34. property set to **Static** in the inspector.
  35. - For imported 3D scenes, the bake mode can be configured in the Import dock
  36. after selecting the 3D scene file in the FileSystem dock.
  37. 2. Add a WorldEnvironment node and create an Environment resource for it.
  38. 3. Edit the Environment resource, scroll down to the **SDFGI** section and unfold it.
  39. 4. Enable **SDFGI > Enabled**. SDFGI will automatically follow the camera when it
  40. moves, so you do not need to configure extents (unlike VoxelGI).
  41. Environment SDFGI properties
  42. ----------------------------
  43. In the Environment resource, there are several properties available to adjust
  44. SDFGI appearance and quality:
  45. - **Use Occlusion:** If enabled, SDFGI will throw additional rays to find and
  46. reduce light leaks. This has a performance cost, so only enable this property
  47. if you actually need it.
  48. - **Read Sky Light:** If enabled, the environment lighting is represented in the
  49. global illumination. This should be enabled in outdoor scenes and disabled in
  50. fully indoor scenes.
  51. - **Bounce Feedback:** By default, indirect lighting only bounces once when
  52. using SDFGI. Setting this value above ``0.0`` will cause SDFGI to bounce more
  53. than once, which provides more realistic indirect lighting at a small
  54. performance cost. Sensible values are usually between ``0.3`` and ``1.0``
  55. depending on the scene. Note that in some scenes, values above ``0.5`` can
  56. cause infinite feedback loops to happen, causing the scene to become extremely
  57. bright in a few seconds' time.
  58. If your indirect lighting looks "splotchy", consider increasing this value above
  59. ``0.0`` to get more uniform-looking lighting. If your lighting ends up looking
  60. too bright as a result, decrease **Energy** to compensate.
  61. - **Cascades:** Higher values result in more detailed GI information
  62. (and/or greater maximum distance), but are significantly more expensive on the
  63. CPU and GPU. The performance cost of having more cascades especially increases
  64. when the camera moves fast, so consider decreasing this to ``4`` or lower
  65. if your camera moves fast.
  66. - **Min Cell Size:** The minimum SDFGI cell size to use for the nearest, most detailed
  67. cascade. Lower values result in more accurate indirect lighting and reflection
  68. at the cost of lower performance.
  69. Adjusting this setting also affects **Cascade 0 Distance** and **Max Distance** automatically.
  70. - **Cascade 0 Distance:** The distance at which the nearest, most detailed
  71. cascade ends. Greater values make the nearest cascade transition less noticeable,
  72. at the cost of reducing the level of detail in the nearest cascade.
  73. Adjusting this setting also affects **Min Cell Size** and **Max Distance** automatically.
  74. - **Max Distance:** Controls how far away the signed distance field will be computed
  75. (for the least detailed cascade). SDFGI will not have any effect past this distance.
  76. This value should always be set below the Camera's Far value, as there is no benefit
  77. in computing SDFGI past the viewing distance.
  78. Adjusting this setting also affects **Min Cell Size** and **Cascade 0 Distance** automatically.
  79. - **Y Scale:** Controls how far apart SDFGI probes are spread *vertically*.
  80. By default, vertical spread is the same as horizontal. However, since most
  81. game scenes aren't highly vertical, setting the Y Scale to
  82. ``75%`` or even ``50%`` can provide better quality and reduce light leaks
  83. without impacting performance.
  84. - **Energy:** The brightness multiplier for SDFGI's indirect lighting.
  85. - **Normal Bias:** The normal bias to use for SDFGI's probe ray bounces.
  86. Unlike **Probe Bias**, this only increases the value in relation to the
  87. mesh's normals. This makes the bias adjustment more nuanced and avoids
  88. increasing the bias too much for no reason. Increase this
  89. value if you notice striping artifacts in indirect lighting or reflections.
  90. - **Probe Bias:** The bias to use for SDFGI's probe ray bounces. Increase this
  91. value if you notice striping artifacts in indirect lighting or reflections.
  92. SDFGI interaction with lights and objects
  93. -----------------------------------------
  94. The amount of indirect energy emitted by a light is governed by its color,
  95. energy *and* indirect energy properties. To make a specific light emit more
  96. or less indirect energy without affecting the amount of direct light emitted
  97. by the light, adjust the **Indirect Energy** property in the Light3D inspector.
  98. To ensure correct visuals when using SDFGI, you must configure your meshes
  99. and lights' global illumination properties according to their *purpose* in the
  100. scene (static or dynamic).
  101. There are 3 global illumination modes available for meshes:
  102. - **Disabled:** The mesh won't be taken into account in SDFGI generation.
  103. The mesh will receive indirect lighting from the scene, but it will not
  104. contribute indirect lighting to the scene.
  105. - **Static (default):** The mesh will be taken into account in SDFGI generation.
  106. The mesh will both receive *and* contribute indirect lighting to the scene. If
  107. the mesh is changed in any way after SDFGI is generated, the camera must move
  108. away from the object then move back close to it for SDFGI to regenerate.
  109. Alternatively, SDFGI can be toggled off and back on. If neither is done,
  110. indirect lighting will look incorrect.
  111. - **Dynamic (not supported with SDFGI):** The mesh won't be taken into account in SDFGI generation.
  112. The mesh will receive indirect lighting from the scene, but it will not
  113. contribute indirect lighting to the scene.
  114. *This acts identical to the **Disabled** bake mode when using SDFGI.*
  115. Additionally, there are 3 bake modes available for lights
  116. (DirectionalLight3D, OmniLight3D and SpotLight3D):
  117. - **Disabled:** The light won't be taken into account for SDFGI baking.
  118. The light won't contribute indirect lighting to the scene.
  119. - **Static:** The light will be taken into account for SDFGI baking. The light
  120. will contribute indirect lighting to the scene. If the light is changed in any
  121. way after baking, indirect lighting will look incorrect until the camera moves
  122. away from the light and back (which causes SDFGI to be baked again). will look
  123. incorrect. If in doubt, use this mode for level lighting.
  124. - **Dynamic (default):** The light won't be taken into account for SDFGI baking,
  125. but it will still contribute indirect lighting to the scene in real-time.
  126. This option is slower compared to **Static**. Only use the **Dynamic** global
  127. illumination mode on lights that will change significantly during gameplay.
  128. .. note::
  129. The amount of indirect energy emitted by a light depends on its color,
  130. energy *and* indirect energy properties. To make a specific light emit more
  131. or less indirect energy without affecting the amount of direct light emitted
  132. by the light, adjust the **Indirect Energy** property in the Light3D inspector.
  133. .. seealso::
  134. See :ref:`doc_introduction_to_global_illumination_gi_mode_recommendations`
  135. for general usage recommendations.
  136. Adjusting SDFGI performance and quality
  137. ---------------------------------------
  138. Since SDFGI is relatively demanding, it will perform best on systems with recent
  139. dedicated GPUs. On older dedicated GPUs and integrated graphics,
  140. tweaking the settings is necessary to achieve reasonable performance.
  141. In the Project Settings' **Rendering > Global Illumination** section,
  142. SDFGI quality can also be adjusted in several ways:
  143. - **Sdfgi > Probe Ray Count:** Higher values result in better quality,
  144. at the cost of higher GPU usage. If this value is set too low,
  145. this can cause surfaces to have visible "splotches" of indirect lighting on
  146. them due to the number of rays thrown being very low.
  147. - **Sdfgi > Frames To Converge:** Higher values result in better quality, but GI will take
  148. more time to fully converge. The effect of this setting is especially noticeable when first
  149. loading a scene, or when lights with a bake mode other than **Disabled** are moving fast.
  150. If this value is set too low, this can cause surfaces to have visible "splotches"
  151. of indirect lighting on them due to the number of rays thrown being very low.
  152. If your scene's lighting doesn't have fast-moving lights that contribute to GI,
  153. consider setting this to ``30`` to improve quality without impacting performance.
  154. - **Sdfgi > Frames To Update Light:** Lower values result in moving lights being
  155. reflected faster, at the cost of higher GPU usage. If your scene's lighting
  156. doesn't have fast-moving lights that contribute to GI, consider setting this
  157. to ``16`` to improve performance.
  158. - **Gi > Use Half Resolution:** If enabled, both SDFGI and VoxelGI will have
  159. their GI buffer rendering at halved resolution. For instance, when rendering
  160. in 3840×2160, the GI buffer will be computed at a 1920×1080 resolution.
  161. Enabling this option saves a lot of GPU time, but it can introduce visible
  162. aliasing around thin details.
  163. SDFGI rendering performance also depends on the number of cascades and
  164. the cell size chosen in the Environment resource (see above).
  165. SDFGI caveats
  166. -------------
  167. SDFGI has some downsides due to its cascaded nature. When the camera moves,
  168. cascade shifts may be visible in indirect lighting. This can be alleviated
  169. by adjusting the cascade size, but also by adding fog (which will make distant
  170. cascade shifts less noticeable).
  171. Additionally, performance will suffer if the camera moves too fast.
  172. This can be fixed in two ways:
  173. - Ensuring the camera doesn't move too fast in any given situation.
  174. - Temporarily disabling SDFGI in the Environment resource if the camera needs
  175. to be moved at a high speed, then enabling SDFGI once the camera speed slows down.
  176. When SDFGI is enabled, it will also take some time for global illumination
  177. to be fully converged (25 frames by default). This can create a noticeable transition
  178. effect while GI is still converging. To hide this, you can use a ColorRect node
  179. that spans the whole viewport and fade it out when switching scenes using an
  180. AnimationPlayer node.
  181. The signed distance field is only updated when the camera moves in and out of a
  182. cascade. This means that if geometry is modified in the distance, the global
  183. illumination appearance will be correct once the camera gets closer. However, if
  184. a nearby object with a bake mode set to **Static** or **Dynamic** is moved (such
  185. as a door), the global illumination will appear incorrect until the camera moves
  186. away from the object.
  187. SDFGI's sharp reflections are only visible on opaque materials. Transparent
  188. materials will only use rough reflections, even if the material's roughness is
  189. lower than 0.2.