introduction_to_global_illumination.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. .. _doc_introduction_to_global_illumination:
  2. Introduction to global illumination
  3. ===================================
  4. What is global illumination?
  5. ----------------------------
  6. *Global illumination* is a catch-all term used to describe a system of lighting
  7. that uses both direct light (light that comes directly from a light source) and
  8. indirect light (light that bounces from a surface). In a 3D rendering engine,
  9. global illumination is one of the most important elements to achieving
  10. realistic lighting. Global illumination aims to mimic how light behaves
  11. in real life, such as light bouncing on surfaces and light being emitted
  12. from emissive materials.
  13. In the example below, the entire scene is illuminated by an emissive material
  14. (the white square at the top). The white wall and ceiling on the back is tinted
  15. red and green close to the walls, as the light bouncing on the colored walls is
  16. being reflected back onto the rest of the scene.
  17. .. image:: img/global_illumination_example.webp
  18. Global illumination is composed of several key concepts:
  19. Indirect diffuse lighting
  20. ^^^^^^^^^^^^^^^^^^^^^^^^^
  21. This is the lighting that does not change depending on the camera's angle.
  22. There are two main sources of indirect diffuse lighting:
  23. - Light *bouncing* on surfaces. This bounced lighting is multiplied with the
  24. material's albedo color. The bounced lighting can then be reflected by other
  25. surfaces, with decreasing impact due to light attenuation. In real life,
  26. light bounces an infinite number of times. However, for performance
  27. reasons, this can't be simulated in a game engine. Instead, the number of
  28. bounces is typically limited to 1 or 2 (or up to 16 when baking lightmaps). A
  29. greater number of bounces will lead to more realistic light falloff in shaded
  30. areas, at the cost of lower performance or greater bake times.
  31. - Emissive materials can also emit light that can be bounced on surfaces.
  32. This acts as a form of *area lighting*. Instead of having an infinitely
  33. small point emit light using an OmniLight3D or SpotLight3D node,
  34. an area of a determined size will emit light using its own surface.
  35. Direct diffuse lighting is already handled by the light nodes themselves, which
  36. means that global illumination algorithms only try to represent indirect
  37. lighting.
  38. Different global illumination techniques offer varying levels of accuracy
  39. to represent indirect diffuse lighting. See the comparison table at the bottom
  40. of this page for more information.
  41. To provide more accurate ambient occlusion for small objects, screen-space ambient occlusion
  42. (SSAO) can be enabled in the :ref:`environment <doc_environment_and_post_processing>`
  43. settings. SSAO has a significant performance cost, so make sure to disable
  44. it when targeting low-end hardware.
  45. .. note::
  46. Indirect diffuse lighting may be a source of color banding in scenes with no
  47. detailed textures. This results in light gradients not being smooth, but
  48. having a visible "stepping" effect instead. See the
  49. :ref:`doc_3d_rendering_limitations_color_banding` section in the 3D rendering
  50. limitations documentation for ways to reduce this effect.
  51. Specular lighting
  52. ^^^^^^^^^^^^^^^^^
  53. Specular lighting is also referred to as *reflections*.
  54. This is the lighting that changes in intensity depending on the camera's angle.
  55. This specular lighting can be *direct* or *indirect*.
  56. Most global illumination techniques offer a way to render specular lighting.
  57. However, the degree of accuracy at which specular lighting is rendered varies
  58. greatly from technique to technique. See the comparison table at the bottom
  59. of this page for more information.
  60. To provide more accurate reflections for small objects, screen-space reflections (SSR)
  61. can be enabled in the :ref:`environment <doc_environment_and_post_processing>` settings.
  62. SSR has a significant performance cost (even more so than SSAO), so make sure to disable
  63. it when targeting low-end hardware.
  64. .. _doc_introduction_to_global_illumination_comparison:
  65. Which global illumination technique should I use?
  66. -------------------------------------------------
  67. When determining a global illumination (GI) technique to use,
  68. there are several criteria to keep in mind:
  69. - **Performance.** Real-time GI techniques are usually more expensive
  70. compared to semi-real-time or baked techniques. Note that most of the cost in
  71. GI rendering is spent on the GPU, rather than the CPU.
  72. - **Visuals.** On top of not performing the best, real-time GI techniques
  73. generally don't provide the best visual output. This is especially the case in
  74. a mostly static scene where the dynamic nature of real-time GI is not easily
  75. noticeable. If maximizing visual quality is your goal, baked techniques will
  76. often look better and will result in fewer light leaks.
  77. - **Real-time ability.** Some GI techniques are fully real-time,
  78. whereas others are only semi-real-time or aren't real-time at all.
  79. Semi-real-time techniques have restrictions that fully real-time techniques don't.
  80. For instance, dynamic objects may not contribute emissive lighting to the scene.
  81. Non-real-time techniques do not support *any* form of dynamic GI,
  82. so it must be faked using other techniques if needed (such as placing positional lights
  83. near emissive surfaces).
  84. Real-time ability also affects the GI technique's viability in procedurally
  85. generated levels.
  86. - **User work needed.** Some GI techniques are fully automatic, whereas others
  87. require careful planning and manual work on the user's side. Depending on your
  88. time budget, some GI techniques may be preferable to others.
  89. Here's a comparison of all the global illumination techniques available in Godot:
  90. Performance
  91. ^^^^^^^^^^^
  92. In order of performance from fastest to slowest:
  93. - **ReflectionProbe:**
  94. - ReflectionProbes with their update mode set to **Always** are much more
  95. expensive than probes with their update mode set to **Once** (the default).
  96. Suited for integrated graphics when using the **Once** update mode.
  97. *Available when using the Forward Mobile backend. Will be available in the Compatibility backend in later releases.*
  98. - **LightmapGI:**
  99. - Lights can be baked with indirect lighting only, or fully baked on a
  100. per-light basis to further improve performance. Hybrid setups can be used
  101. (such as having a real-time directional light and fully baked positional lights).
  102. Directional information can be enabled before baking to improve visuals at
  103. a small performance cost (and at the cost of larger file sizes).
  104. Suited for integrated graphics.
  105. *Available when using the Forward Mobile backend. Will be available in the Compatibility backend in later releases.*
  106. - **VoxelGI:**
  107. - The bake's number of subdivisions can be adjusted to balance between performance and quality.
  108. The VoxelGI rendering quality can be adjusted in the Project Settings.
  109. The rendering can optionally be performed at half resolution
  110. (and then linearly scaled) to improve performance significantly.
  111. **Not available** *when using the Forward Mobile or Compatibility backends.*
  112. - **Screen-space indirect lighting (SSIL):**
  113. - The SSIL quality and number of blur passes can be adjusted in the Project Settings.
  114. By default, SSIL rendering is performed at half resolution (and then linearly scaled)
  115. to ensure a reasonable performance level.
  116. **Not available** *when using the Forward Mobile or Compatibility backends.*
  117. - **SDFGI:**
  118. - The number of cascades can be adjusted to balance performance and quality.
  119. The number of rays thrown per frame can be adjusted in the Project Settings.
  120. The rendering can optionally be performed at half resolution
  121. (and then linearly scaled) to improve performance significantly.
  122. **Not available** *when using the Forward Mobile or Compatibility backends.*
  123. Visuals
  124. ^^^^^^^
  125. For comparison, here's a 3D scene with no global illumination options used:
  126. .. figure:: img/gi_none.webp
  127. :alt: A 3D scene without any form of global illumination (only constant environment lighting). The box and sphere near the camera are both dynamic objects.
  128. A 3D scene without any form of global illumination (only constant environment lighting). The box and sphere near the camera are both dynamic objects.
  129. Here's how Godot's various global illumination techniques compare:
  130. - **VoxelGI:** |average| Good reflections and indirect lighting, but beware of leaks.
  131. - Due to its voxel-based nature, VoxelGI will exhibit light leaks if walls and floors are too thin.
  132. It's recommended to make sure all solid surfaces are at least as thick as one voxel.
  133. Streaking artifacts may also be visible on sloped surfaces. In this case,
  134. tweaking the bias properties or rotating the VoxelGI node can help combat
  135. this.
  136. .. figure:: img/gi_voxel_gi.webp
  137. :alt: VoxelGI in action.
  138. VoxelGI in action.
  139. - **SDFGI:** |average| Good reflections and indirect lighting, but beware of leaks and visible cascade shifts.
  140. - GI level of detail varies depending on the distance
  141. between the camera and surface.
  142. Leaks can be reduced significantly by enabling the **Use Occlusion**
  143. property. This has a small performance cost, but it often results in fewer
  144. leaks compared to VoxelGI.
  145. Cascade shifts may be visible when the camera moves fast. This can be made
  146. less noticeable by adjusting the cascade sizes or using fog.
  147. .. figure:: img/gi_sdfgi.webp
  148. :alt: SDFGI in action.
  149. SDFGI in action.
  150. - **Screen-space indirect lighting (SSIL):** |average| Good *secondary* source of indirect lighting, but no reflections.
  151. - SSIL is designed to be used as a complement to another GI technique such as
  152. VoxelGI, SDFGI or LightmapGI. SSIL works best for small-scale details, as it
  153. cannot provide accurate indirect lighting for large structures on its own.
  154. SSIL can provide real-time indirect lighting in situations where other GI
  155. techniques fail to capture small-scale details or dynamic objects. Its
  156. screen-space nature will result in some artifacts, especially when objects
  157. enter and leave the screen. SSIL works using the last frame's color (before
  158. post-processing) which means that emissive decals and custom shaders are
  159. included (as long as they're present on screen).
  160. .. figure:: img/gi_ssil_only.webp
  161. :alt: SSIL in action (without any other GI technique). Notice the emissive lighting around the yellow box.
  162. SSIL in action (without any other GI technique). Notice the emissive lighting around the yellow box.
  163. - **LightmapGI:** |good| Excellent indirect lighting, decent reflections (optional).
  164. - This is the only technique where the number of light bounces
  165. can be pushed above 2 (up to 16). When directional information
  166. is enabled, spherical harmonics (SH) are used
  167. to provide blurry reflections.
  168. .. figure:: img/gi_lightmap_gi_indirect_only.webp
  169. :alt: LightmapGI in action. Only indirect lighting is baked here, but direct light can also be baked.
  170. LightmapGI in action. Only indirect lighting is baked here, but direct light can also be baked.
  171. - **ReflectionProbe:** |average| Good reflections, but poor indirect lighting.
  172. - Indirect lighting can be disabled, set to a constant color spread throughout
  173. the probe, or automatically read from the probe's environment (and applied
  174. as a cubemap). This essentially acts as local ambient lighting. Reflections
  175. and indirect lighting are blended with other nearby probes.
  176. .. figure:: img/gi_none_reflection_probe.webp
  177. :alt: ReflectionProbe in action (without any other GI technique). Notice the reflective sphere.
  178. ReflectionProbe in action (without any other GI technique). Notice the reflective sphere.
  179. Real-time ability
  180. ^^^^^^^^^^^^^^^^^
  181. - **VoxelGI:** |good| Fully real-time.
  182. - Indirect lighting and reflections are fully real-time. Dynamic objects can
  183. receive GI *and* contribute to it with their emissive surfaces. Custom
  184. shaders can also emit their own light, which will be emitted accurately.
  185. Viable for procedurally generated levels *if they are generated in advance*
  186. (and not during gameplay). Baking requires several seconds or more to complete,
  187. but it can be done from both the editor and an exported project.
  188. - **SDFGI:** |average| Semi-real-time.
  189. - Cascades are generated in real-time, making SDFGI
  190. viable for procedurally generated levels (including when structures are generated
  191. during gameplay).
  192. Dynamic objects can *receive* GI, but not *contribute* to it. Emissive lighting
  193. will only update when an object enters a cascade, so it may still work for
  194. slow-moving objects.
  195. - **Screen-space indirect lighting (SSIL):** |good| Fully real-time.
  196. - SSIL works with both static and dynamic lights. It also works with both
  197. static and dynamic occluders (including emissive materials).
  198. - **LightmapGI:** |bad| Baked, and therefore not real-time.
  199. - Both indirect lighting and SH reflections are baked and can't be changed at
  200. run-time. Real-time GI must be
  201. :ref:`simulated via other means <doc_faking_global_illumination>`,
  202. such as real-time positional lights. Dynamic objects receive indirect lighting
  203. via light probes, which can be placed automatically or manually by the user
  204. (LightmapProbe node). Not viable for procedurally generated levels,
  205. as baking lightmaps is only possible from the editor.
  206. - **ReflectionProbe:** |average| Optionally real-time.
  207. - By default, reflections update when the probe is moved.
  208. They update as often as possible if the update mode
  209. is set to **Always** (which is expensive).
  210. - Indirect lighting must be configured manually by the user, but can be changed
  211. at run-time without causing an expensive computation to happen behind the scenes.
  212. This makes ReflectionProbes viable for procedurally generated levels.
  213. User work needed
  214. ^^^^^^^^^^^^^^^^
  215. - **VoxelGI:** One or more VoxelGI nodes need to be created and baked.
  216. - Adjusting extents correctly is required to get good results. Additionally
  217. rotating the node and baking again can help combat leaks or streaking
  218. artifacts in certain situations. Bake times are fast – usually below
  219. 10 seconds for a scene of medium complexity.
  220. - **SDFGI:** Very little.
  221. - SDFGI is fully automatic; it only needs to be enabled in the Environment resource.
  222. The only manual work required is to set MeshInstances' bake mode property correctly.
  223. No node needs to be created, and no baking is required.
  224. - **Screen-space indirect lighting (SSIL):** Very little.
  225. - SSIL is fully automatic; it only needs to be enabled in the Environment resource.
  226. No node needs to be created, and no baking is required.
  227. - **LightmapGI:** Requires UV2 setup and baking.
  228. - Static meshes must be reimported with UV2 and lightmap generation enabled.
  229. On a dedicated GPU, bake times are relatively fast thanks to the GPU-based
  230. lightmap baking – usually below 1 minute for a scene of medium complexity.
  231. - **ReflectionProbe:** Placed manually by the user.
  232. .. |good| image:: img/score_good.webp
  233. .. |average| image:: img/score_average.webp
  234. .. |bad| image:: img/score_bad.webp
  235. Summary
  236. ^^^^^^^
  237. If you are unsure about which GI technique to use:
  238. - For desktop games, it's a good idea to start with :ref:`SDFGI <doc_using_sdfgi>`
  239. first as it requires the least amount of setup. Move to other GI techniques
  240. later if needed. To improve performance on low-end GPUs and integrated
  241. graphics, consider adding an option to disable SDFGI or :ref:`VoxelGI
  242. <doc_using_voxel_gi>` in your game's settings. SDFGI can be disabled in the
  243. Environment resource, and VoxelGI can be disabled by hiding the VoxelGI
  244. node(s). To further improve visuals on high-end setups, add an option to
  245. enable SSIL in your game's settings.
  246. - For mobile games, :ref:`LightmapGI <doc_using_lightmap_gi>` and
  247. :ref:`ReflectionProbes <doc_reflection_probes>` are the only supported options.
  248. See also :ref:`doc_introduction_to_global_illumination_alternatives`.
  249. .. seealso::
  250. You can compare global illumination techniques in action using the
  251. `Global Illumination demo project <https://github.com/godotengine/godot-demo-projects/tree/master/3d/global_illumination>`__.
  252. .. _doc_introduction_to_global_illumination_gi_mode_recommendations:
  253. Which global illumination mode should I use on meshes and lights?
  254. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  255. Regardless of which global illumination technique you use, there is no
  256. universally "better" global illumination mode. Still, here are some
  257. recommendations for meshes:
  258. - For static level geometry, use the **Static** global illumination mode *(default)*.
  259. - For small dynamic geometry and players/enemies, use the **Disabled** global
  260. illumination mode. Small dynamic geometry will not be able to contribute a significant
  261. amount of indirect lighting, due to the geometry being smaller than a voxel.
  262. If you need indirect lighting for small dynamic objects, it can be simulated
  263. using an OmniLight3D or SpotLight3D node parented to the object.
  264. - For *large* dynamic level geometry (such as a moving train), use the
  265. **Dynamic** global illumination mode. Note that this only has an effect with
  266. VoxelGI, as SDFGI and LightmapGI do not support global illumination with
  267. dynamic objects.
  268. Here are some recommendations for light bake modes:
  269. - For static level lighting, use the **Static** bake mode.
  270. The **Static** mode is also suitable for dynamic lights that don't change
  271. much during gameplay, such as a flickering torch.
  272. - For short-lived dynamic effects (such as a weapon), use the **Disabled**
  273. bake mode to improve performance.
  274. - For long-lived dynamic effects (such as a rotating alarm light), use the
  275. **Dynamic** bake mode to improve quality *(default)*. Note that this only has
  276. an effect with VoxelGI and SDFGI, as LightmapGI does not support global
  277. illumination with dynamic lights.
  278. .. _doc_introduction_to_global_illumination_alternatives:
  279. Alternatives to GI techniques
  280. -----------------------------
  281. If none of the GI techniques mentioned above fits, it's still possible to
  282. :ref:`simulate GI by placing additional lights manually <doc_faking_global_illumination>`.
  283. This requires more manual work, but it can offer good performance *and* good
  284. visuals if done right. This approach is still used in many modern games to this
  285. day.
  286. When targeting low-end hardware in situations where using LightmapGI is not
  287. viable (such as procedurally generated levels), relying on environment lighting
  288. alone or a constant ambient light factor may be a necessity. This may result in
  289. flatter visuals, but adjusting the ambient light color and sky contribution
  290. still makes it possible to achieve acceptable results in most cases.