introduction_to_global_illumination.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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 in all renderers.*
  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 in all renderers. However, baking lightmaps requires hardware
  106. with RenderingDevice support.*
  107. - **VoxelGI:**
  108. - The bake's number of subdivisions can be adjusted to balance between performance and quality.
  109. The VoxelGI rendering quality can be adjusted in the Project Settings.
  110. The rendering can optionally be performed at half resolution
  111. (and then linearly scaled) to improve performance significantly.
  112. **Not available** *when using the Mobile or Compatibility renderers.*
  113. - **Screen-space indirect lighting (SSIL):**
  114. - The SSIL quality and number of blur passes can be adjusted in the Project Settings.
  115. By default, SSIL rendering is performed at half resolution (and then linearly scaled)
  116. to ensure a reasonable performance level.
  117. **Not available** *when using the Mobile or Compatibility renderers.*
  118. - **SDFGI:**
  119. - The number of cascades can be adjusted to balance performance and quality.
  120. The number of rays thrown per frame can be adjusted in the Project Settings.
  121. The rendering can optionally be performed at half resolution
  122. (and then linearly scaled) to improve performance significantly.
  123. **Not available** *when using the Mobile or Compatibility renderers.*
  124. Visuals
  125. ^^^^^^^
  126. For comparison, here's a 3D scene with no global illumination options used:
  127. .. figure:: img/gi_none.webp
  128. :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.
  129. A 3D scene without any form of global illumination (only constant environment lighting). The box and sphere near the camera are both dynamic objects.
  130. Here's how Godot's various global illumination techniques compare:
  131. - **VoxelGI:** |average| Good reflections and indirect lighting, but beware of leaks.
  132. - Due to its voxel-based nature, VoxelGI will exhibit light leaks if walls and floors are too thin.
  133. It's recommended to make sure all solid surfaces are at least as thick as one voxel.
  134. Streaking artifacts may also be visible on sloped surfaces. In this case,
  135. tweaking the bias properties or rotating the VoxelGI node can help combat
  136. this.
  137. .. figure:: img/gi_voxel_gi.webp
  138. :alt: VoxelGI in action.
  139. VoxelGI in action.
  140. - **SDFGI:** |average| Good reflections and indirect lighting, but beware of leaks and visible cascade shifts.
  141. - GI level of detail varies depending on the distance
  142. between the camera and surface.
  143. Leaks can be reduced significantly by enabling the **Use Occlusion**
  144. property. This has a small performance cost, but it often results in fewer
  145. leaks compared to VoxelGI.
  146. Cascade shifts may be visible when the camera moves fast. This can be made
  147. less noticeable by adjusting the cascade sizes or using fog.
  148. .. figure:: img/gi_sdfgi.webp
  149. :alt: SDFGI in action.
  150. SDFGI in action.
  151. - **Screen-space indirect lighting (SSIL):** |average| Good *secondary* source of indirect lighting, but no reflections.
  152. - SSIL is designed to be used as a complement to another GI technique such as
  153. VoxelGI, SDFGI or LightmapGI. SSIL works best for small-scale details, as it
  154. cannot provide accurate indirect lighting for large structures on its own.
  155. SSIL can provide real-time indirect lighting in situations where other GI
  156. techniques fail to capture small-scale details or dynamic objects. Its
  157. screen-space nature will result in some artifacts, especially when objects
  158. enter and leave the screen. SSIL works using the last frame's color (before
  159. post-processing) which means that emissive decals and custom shaders are
  160. included (as long as they're present on screen).
  161. .. figure:: img/gi_ssil_only.webp
  162. :alt: SSIL in action (without any other GI technique). Notice the emissive lighting around the yellow box.
  163. SSIL in action (without any other GI technique). Notice the emissive lighting around the yellow box.
  164. - **LightmapGI:** |good| Excellent indirect lighting, decent reflections (optional).
  165. - This is the only technique where the number of light bounces
  166. can be pushed above 2 (up to 16). When directional information
  167. is enabled, spherical harmonics (SH) are used
  168. to provide blurry reflections.
  169. .. figure:: img/gi_lightmap_gi_indirect_only.webp
  170. :alt: LightmapGI in action. Only indirect lighting is baked here, but direct light can also be baked.
  171. LightmapGI in action. Only indirect lighting is baked here, but direct light can also be baked.
  172. - **ReflectionProbe:** |average| Good reflections, but poor indirect lighting.
  173. - Indirect lighting can be disabled, set to a constant color spread throughout
  174. the probe, or automatically read from the probe's environment (and applied
  175. as a cubemap). This essentially acts as local ambient lighting. Reflections
  176. and indirect lighting are blended with other nearby probes.
  177. .. figure:: img/gi_none_reflection_probe.webp
  178. :alt: ReflectionProbe in action (without any other GI technique). Notice the reflective sphere.
  179. ReflectionProbe in action (without any other GI technique). Notice the reflective sphere.
  180. Real-time ability
  181. ^^^^^^^^^^^^^^^^^
  182. - **VoxelGI:** |good| Fully real-time.
  183. - Indirect lighting and reflections are fully real-time. Dynamic objects can
  184. receive GI *and* contribute to it with their emissive surfaces. Custom
  185. shaders can also emit their own light, which will be emitted accurately.
  186. Viable for procedurally generated levels *if they are generated in advance*
  187. (and not during gameplay). Baking requires several seconds or more to complete,
  188. but it can be done from both the editor and an exported project.
  189. - **SDFGI:** |average| Semi-real-time.
  190. - Cascades are generated in real-time, making SDFGI
  191. viable for procedurally generated levels (including when structures are generated
  192. during gameplay).
  193. Dynamic objects can *receive* GI, but not *contribute* to it. Emissive lighting
  194. will only update when an object enters a cascade, so it may still work for
  195. slow-moving objects.
  196. - **Screen-space indirect lighting (SSIL):** |good| Fully real-time.
  197. - SSIL works with both static and dynamic lights. It also works with both
  198. static and dynamic occluders (including emissive materials).
  199. - **LightmapGI:** |bad| Baked, and therefore not real-time.
  200. - Both indirect lighting and SH reflections are baked and can't be changed at
  201. runtime. Real-time GI must be
  202. :ref:`simulated via other means <doc_faking_global_illumination>`,
  203. such as real-time positional lights. Dynamic objects receive indirect lighting
  204. via light probes, which can be placed automatically or manually by the user
  205. (LightmapProbe node). Not viable for procedurally generated levels,
  206. as baking lightmaps is only possible from the editor.
  207. - **ReflectionProbe:** |average| Optionally real-time.
  208. - By default, reflections update when the probe is moved.
  209. They update as often as possible if the update mode
  210. is set to **Always** (which is expensive).
  211. - Indirect lighting must be configured manually by the user, but can be changed
  212. at runtime without causing an expensive computation to happen behind the scenes.
  213. This makes ReflectionProbes viable for procedurally generated levels.
  214. User work needed
  215. ^^^^^^^^^^^^^^^^
  216. - **VoxelGI:** One or more VoxelGI nodes need to be created and baked.
  217. - Adjusting extents correctly is required to get good results. Additionally
  218. rotating the node and baking again can help combat leaks or streaking
  219. artifacts in certain situations. Bake times are fast – usually below
  220. 10 seconds for a scene of medium complexity.
  221. - **SDFGI:** Very little.
  222. - SDFGI is fully automatic; it only needs to be enabled in the Environment resource.
  223. The only manual work required is to set MeshInstances' bake mode property correctly.
  224. No node needs to be created, and no baking is required.
  225. - **Screen-space indirect lighting (SSIL):** Very little.
  226. - SSIL is fully automatic; it only needs to be enabled in the Environment resource.
  227. No node needs to be created, and no baking is required.
  228. - **LightmapGI:** Requires UV2 setup and baking.
  229. - Static meshes must be reimported with UV2 and lightmap generation enabled.
  230. On a dedicated GPU, bake times are relatively fast thanks to the GPU-based
  231. lightmap baking – usually below 1 minute for a scene of medium complexity.
  232. - **ReflectionProbe:** Placed manually by the user.
  233. .. |good| image:: img/score_good.webp
  234. .. |average| image:: img/score_average.webp
  235. .. |bad| image:: img/score_bad.webp
  236. Summary
  237. ^^^^^^^
  238. If you are unsure about which GI technique to use:
  239. - For desktop games, it's a good idea to start with :ref:`SDFGI <doc_using_sdfgi>`
  240. first as it requires the least amount of setup. Move to other GI techniques
  241. later if needed. To improve performance on low-end GPUs and integrated
  242. graphics, consider adding an option to disable SDFGI or :ref:`VoxelGI
  243. <doc_using_voxel_gi>` in your game's settings. SDFGI can be disabled in the
  244. Environment resource, and VoxelGI can be disabled by hiding the VoxelGI
  245. node(s). To further improve visuals on high-end setups, add an option to
  246. enable SSIL in your game's settings.
  247. - For mobile games, :ref:`LightmapGI <doc_using_lightmap_gi>` and
  248. :ref:`ReflectionProbes <doc_reflection_probes>` are the only supported options.
  249. See also :ref:`doc_introduction_to_global_illumination_alternatives`.
  250. .. seealso::
  251. You can compare global illumination techniques in action using the
  252. `Global Illumination demo project <https://github.com/godotengine/godot-demo-projects/tree/master/3d/global_illumination>`__.
  253. .. _doc_introduction_to_global_illumination_gi_mode_recommendations:
  254. Which global illumination mode should I use on meshes and lights?
  255. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  256. Regardless of which global illumination technique you use, there is no
  257. universally "better" global illumination mode. Still, here are some
  258. recommendations for meshes:
  259. - For static level geometry, use the **Static** global illumination mode *(default)*.
  260. - For small dynamic geometry and players/enemies, use the **Disabled** global
  261. illumination mode. Small dynamic geometry will not be able to contribute a significant
  262. amount of indirect lighting, due to the geometry being smaller than a voxel.
  263. If you need indirect lighting for small dynamic objects, it can be simulated
  264. using an OmniLight3D or SpotLight3D node parented to the object.
  265. - For *large* dynamic level geometry (such as a moving train), use the
  266. **Dynamic** global illumination mode. Note that this only has an effect with
  267. VoxelGI, as SDFGI and LightmapGI do not support global illumination with
  268. dynamic objects.
  269. Here are some recommendations for light bake modes:
  270. - For static level lighting, use the **Static** bake mode.
  271. The **Static** mode is also suitable for dynamic lights that don't change
  272. much during gameplay, such as a flickering torch.
  273. - For short-lived dynamic effects (such as a weapon), use the **Disabled**
  274. bake mode to improve performance.
  275. - For long-lived dynamic effects (such as a rotating alarm light), use the
  276. **Dynamic** bake mode to improve quality *(default)*. Note that this only has
  277. an effect with VoxelGI and SDFGI, as LightmapGI does not support global
  278. illumination with dynamic lights.
  279. .. _doc_introduction_to_global_illumination_alternatives:
  280. Alternatives to GI techniques
  281. -----------------------------
  282. If none of the GI techniques mentioned above fits, it's still possible to
  283. :ref:`simulate GI by placing additional lights manually <doc_faking_global_illumination>`.
  284. This requires more manual work, but it can offer good performance *and* good
  285. visuals if done right. This approach is still used in many modern games to this
  286. day.
  287. When targeting low-end hardware in situations where using LightmapGI is not
  288. viable (such as procedurally generated levels), relying on environment lighting
  289. alone or a constant ambient light factor may be a necessity. This may result in
  290. flatter visuals, but adjusting the ambient light color and sky contribution
  291. still makes it possible to achieve acceptable results in most cases.