environment_and_post_processing.rst 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930
  1. .. _doc_environment_and_post_processing:
  2. Environment and post-processing
  3. ===============================
  4. Godot 4 provides a redesigned Environment resource, as well as a new
  5. post-processing system with many available effects right out of the box.
  6. .. note::
  7. As of Godot 4, Environment *performance/quality* settings are defined in the
  8. project settings instead of in the Environment resource. This makes global
  9. adjustments easier, as you no longer have to tweak Environment resources
  10. individually to suit various hardware configurations.
  11. Note that most Environment performance/quality settings are only visible
  12. after enabling the **Advanced** toggle in the Project Settings.
  13. Environment
  14. -----------
  15. The :ref:`class_Environment` resource stores all the information required for
  16. controlling the 2D and 3D rendering environment. This includes the sky, ambient
  17. lighting, tone mapping, effects, and adjustments. By itself, it does nothing,
  18. but you can enable it by using it in one of the following locations, in order
  19. of priority:
  20. Camera3D node (high priority)
  21. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  22. An Environment can be set to a Camera3D node. It will have priority over any
  23. other setting.
  24. .. image:: img/environment_camera.webp
  25. This is mostly useful when you want to override an existing environment,
  26. but in general it's a better idea to use the option below.
  27. WorldEnvironment node (medium priority, recommended)
  28. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  29. The WorldEnvironment node can be added to any scene, but only one can exist per
  30. active scene tree. Adding more than one will result in a warning.
  31. .. image:: img/environment_world.webp
  32. Any Environment added has higher priority than the default Environment
  33. (explained below). This means it can be overridden on a per-scene basis,
  34. which makes it quite useful.
  35. Preview environment and sun (low priority)
  36. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  37. .. note::
  38. Since Godot 4, the preview environment and sun system replace the
  39. ``default_env.tres`` file that was used in Godot 3 projects.
  40. If no WorldEnvironment node or DirectionalLight3D node is present in the current
  41. scene, the editor will display a preview environment and sun instead. This can
  42. be disabled using the buttons at the top of the 3D editor:
  43. .. image:: img/environment_preview_sun_sky_toggle.webp
  44. Clicking on the 3 vertical dots on the right will display a dialog which allows
  45. you to customize the appearance of the preview environment:
  46. .. image:: img/environment_preview_sun_sky_dialog.webp
  47. **The preview sun and sky is only visible in the editor, not in the running
  48. project.** Using the buttons at the bottom of the dialog, you can add the
  49. preview sun and sky into the scene as nodes.
  50. .. tip::
  51. If you hold :kbd:`Shift` while clicking **Add Sun to Scene** or **Add
  52. Environment to Scene** in the preview environment editor, this will add both
  53. a preview sun and environment to the current scene (as if you clicked both
  54. buttons separately). Use this to speed up project setup and prototyping.
  55. Camera attributes
  56. -----------------
  57. .. note::
  58. In Godot 4, exposure and depth of field information was split from the
  59. Environment resource into a separate CameraAttributes resource. This allows
  60. adjusting those properties independently of other Environment settings more
  61. easily.
  62. The :ref:`class_CameraAttributes` resource stores exposure and depth of field
  63. information. It also allows enabling automatic exposure adjustments depending on
  64. scene brightness.
  65. There are two kinds of CameraAttribute resources available:
  66. - **CameraAttributesPractical:** Features are exposed using arbitrary units,
  67. which are easier to reason about for most game use cases.
  68. - **CameraAttributesPhysical:** Features are exposed using real world units,
  69. similar to a digital camera. For example, field of view is set using a focal
  70. length in millimeters instead of a value in degrees. Recommended when physical
  71. accuracy is important, such as for photorealistic rendering.
  72. Both CameraAttribute resource types allow you to use the same features, but they
  73. are configured differently. If you don't know which one to choose, use
  74. **CameraAttributesPractical**.
  75. .. note::
  76. Using a :ref:`class_CameraAttributesPhysical` on a Camera3D node will lock
  77. out FOV and aspect adjustments in that Camera3D, as field of view is
  78. adjusted in the CameraAttributesPhysical resource instead. If used in a
  79. WorldEnvironment, the CameraAttributesPhysical will not override any
  80. Camera3D in the scene.
  81. A CameraAttributes resource can be added to a Camera3D or a WorldEnvironment
  82. node. When the current camera has a CameraAttributes set, it will *override* the
  83. one set in WorldEnvironment (if any).
  84. In most situations, setting the CameraAttributes resource on the Camera3D node
  85. instead of the WorldEnvironment is recommended. Unlike WorldEnvironment,
  86. assigning the CameraAttributes resource to the Camera3D node prevents depth of
  87. field from displaying in the 3D editor viewport, unless the camera is being
  88. previewed.
  89. Environment options
  90. -------------------
  91. The following is a detailed description of all environment options and how
  92. they are intended to be used.
  93. Background
  94. ~~~~~~~~~~
  95. The Background section contains settings on how to fill the background (parts of
  96. the screen where objects were not drawn). The background not only serves the
  97. purpose of displaying an image or color. By default, it also affects how objects
  98. are affected by ambient and reflected light. This is called image-based lighting
  99. (IBL).
  100. As a result, the background sky may greatly impact your scene's overall
  101. appearance, even if the sky is never directly visible on screen. This should be
  102. taken into account when tweaking lighting in your scene.
  103. .. image:: img/environment_background1.webp
  104. There are several background modes available:
  105. - **Clear Color** uses the default clear color defined in the project settings.
  106. The background will be a constant color.
  107. - **Custom Color** is like Clear Color, but with a custom color value.
  108. - **Sky** lets you define a background sky material (see below). By default,
  109. objects in the scene will reflect this sky material and absorb ambient light
  110. from it.
  111. - **Canvas** displays the 2D scene as a background to the 3D scene. This can be used
  112. to make environment effects visible on 2D rendering, such as
  113. :ref:`glow in 2D <doc_environment_and_post_processing_using_glow_in_2d>`.
  114. - **Keep** does not draw any sky, keeping what was present on previous frames
  115. instead. This improves performance in purely indoor scenes, but creates a
  116. "hall of mirrors" visual glitch if the sky is visible at any time.
  117. Sky materials
  118. ~~~~~~~~~~~~~
  119. When using the **Sky** background mode (or the ambient/reflected light mode is
  120. set to **Sky**), a Sky subresource becomes available to edit in the Environment
  121. resource. Editing this subresource allows you to create a SkyMaterial resource
  122. within the Sky.
  123. There are 3 built-in sky materials to choose from:
  124. - **PanoramaSkyMaterial:** Use a 360 degree panorama sky image (2:1 aspect ratio
  125. recommended). To benefit from high dynamic range, the panorama image must be
  126. in an HDR-compatible format such as ``.hdr`` or ``.exr`` rather than a
  127. standard dynamic range format like ``.png`` or ``.jpg``.
  128. - **ProceduralSkyMaterial:** Use a procedurally generated sky with adjustable
  129. ground, sun, sky and horizon colors. This is the type of sky used in the
  130. editor preview. The sun's position is automatically derived from the first 4
  131. DirectionalLight3D nodes present in the scene. There can be up to 4 suns at a
  132. given time.
  133. - **PhysicalSkyMaterial:** Use a physically-based procedural sky with adjustable
  134. scattering parameters. The sun's position is automatically derived from the
  135. first DirectionalLight3D node present in the scene. PhysicalSkyMaterial is
  136. slightly more expensive to render compared to ProceduralSkyMaterial. There can
  137. be up to 1 sun at a given time.
  138. Panorama sky images are sometimes called HDRIs (High Dynamic Range Images).
  139. You can find freely licensed HDRIs on `Poly Haven <https://polyhaven.com/hdris>`__.
  140. .. note::
  141. HDR PanoramaSkyMaterial textures with very bright spots (such as real life
  142. photos with the sun visible) may result in visible sparkles on ambient and
  143. specular reflections. This is caused by the texture's peak exposure being
  144. too high.
  145. To resolve this, select the panorama texture in the FileSystem dock, go to
  146. the Import dock, enable **HDR Clamp Exposure** then click **Reimport**.
  147. If you need a custom sky material (e.g. for procedural clouds), you can
  148. create a custom :ref:`sky shader <doc_sky_shader>`.
  149. Ambient light
  150. ~~~~~~~~~~~~~
  151. Ambient light (as defined here) is a type of light that affects every piece of
  152. geometry with the same intensity. It is global and independent of lights that
  153. might be added to the scene. Ambient light is one of the two components of
  154. image-based lighting. Unlike reflected light, ambient light does not vary
  155. depending on the camera's position and viewing angle.
  156. There are several types of ambient light to choose from:
  157. - **Background:** Source ambient light from the background, such as the sky,
  158. custom color or clear color (default). Ambient light intensity will vary
  159. depending on the sky image's contents, which can result in more visually
  160. appealing ambient lighting. A sky must be set as background for this mode to
  161. be visible.
  162. - **Disabled:** Do not use any ambient light. Useful for purely indoor scenes.
  163. - **Color:** Use a constant color for ambient light, ignoring the background
  164. sky. Ambient light intensity will be the same on all sides, which may result
  165. in the scene's lighting looking more flat. Useful for indoor scenes where
  166. pitch black shadows may be too dark, or to maximize performance on low-end
  167. devices.
  168. - **Sky:** Source ambient light from a specified sky, even if the background is
  169. set to a mode other than **Sky**. If the background mode is already **Sky**,
  170. this mode behaves identically to **Background**.
  171. When the ambient light mode is set to Sky or Background (and background is set
  172. to Sky), it's possible to blend between the ambient color and sky using the
  173. **Sky Contribution** property. This value is set to ``1.0`` by default, which
  174. means that only the ambient sky is used. The ambient color is ignored unless
  175. **Sky Contribution** is decreased below ``1.0``.
  176. Here is a comparison of how different ambient light affects a scene:
  177. .. image:: img/environment_ambient2.webp
  178. Finally, there is an **Energy** setting which is a multiplier. It's useful when
  179. working with HDR.
  180. In general, you should only rely on ambient light alone for simple scenes or
  181. large exteriors. You may also do so to boost performance. Ambient light is fast
  182. to render, but it doesn't provide the best lighting quality. It's better to
  183. generate ambient light from :ref:`ReflectionProbe <doc_reflection_probes>`,
  184. :ref:`VoxelGI <doc_using_voxel_gi>` or :ref:`SDFGI <doc_using_sdfgi>`, as these
  185. will simulate how indirect light propagates more accurately. Below is a comparison,
  186. in terms of quality, between using a flat ambient color and a VoxelGI:
  187. .. image:: img/environment_ambient_comparison.webp
  188. Using one of the methods described above will replace constant ambient
  189. lighting with ambient lighting from the probes.
  190. Reflected light
  191. ~~~~~~~~~~~~~~~
  192. Reflected light (also called specular light) is the other of the two components
  193. of image-based lighting.
  194. Reflected light can be set to one of 3 modes:
  195. - **Background:** Reflect from the background, such as the sky, custom color or
  196. clear color (default).
  197. - **Disabled:** Do not reflect any light from the environment. Useful for purely
  198. indoor scenes, or to maximize performance on low-end devices.
  199. - **Sky:** Reflect from the background sky, even if the background is set to a
  200. mode other than **Sky**. If the background mode is already **Sky**, this mode
  201. behaves identically to **Background**.
  202. Fog
  203. ~~~
  204. .. note::
  205. This section refers to non-volumetric fog only.
  206. It is possible to use both non-volumetric fog and :ref:`doc_volumetric_fog`
  207. at the same time.
  208. Fog, as in real life, makes distant objects fade away into a uniform color.
  209. There are two kinds of fog in Godot:
  210. - **Depth Fog:** This one is applied based on the distance from the camera.
  211. - **Height Fog:** This one is applied to any objects below (or above) a certain
  212. height, regardless of the distance from the camera.
  213. .. image:: img/environment_fog_depth_height.webp
  214. Both of these fog types can have their curve tweaked, making their transition more or less sharp.
  215. Two properties can be tweaked to make the fog effect more interesting:
  216. The first is **Sun Scatter**, which makes use of the DirectionalLight3D's color
  217. and energy in the current scene. When looking towards the directional light
  218. (usually a sun), the fog will be tinted according to the light's color to
  219. simulate the sunlight passing through the fog.
  220. The second is **Aerial Perspective**, which tints the fog color according to the
  221. sky color to better blend the sky with the background. Higher values will result
  222. in more tinting, with ``1.0`` fully replacing the regular fog color with aerial
  223. perspective. This can be used in large open world levels to provide a better
  224. sense of depth, or to avoid color discontinuities between the sky and fog colors.
  225. If both **Sun Scatter** and **Aerial Perspective** are greater than ``0.0``, sun
  226. scattering is applied on top of aerial perspective.
  227. .. note::
  228. Fog can cause banding to appear on the viewport, especially at
  229. higher density levels. See :ref:`doc_3d_rendering_limitations_color_banding`
  230. for guidance on reducing banding.
  231. Volumetric Fog
  232. ~~~~~~~~~~~~~~
  233. Volumetric fog provides a realistic fog effect to the scene, with fog color
  234. being affected by the lights that traverse the fog.
  235. .. seealso::
  236. See :ref:`doc_volumetric_fog` for documentation on setting up volumetric fog.
  237. Tonemap
  238. ~~~~~~~
  239. Tonemap selects the tonemapping algorithm that will be applied to the scene, from a
  240. list of standard algorithms used in the film and game industries. Tonemapping modes
  241. other than **Linear** are used to make light and dark areas more homogeneous,
  242. while also avoiding clipping of bright highlights. Each algorithm has a different
  243. performance characteristic that should be considered when choosing your tonemapper.
  244. The tone mapping options are:
  245. - **Mode:** The tonemapping mode to use.
  246. - **Linear:** Does not modify color data, resulting in a linear tonemapping
  247. curve which unnaturally clips bright values, causing bright lighting to
  248. look blown out. The simplest and fastest tonemapper.
  249. - **Reinhard:** A simple tonemapping curve that rolls off bright values to
  250. prevent clipping. This results in an image that can appear dull and low
  251. contrast. Slower than Linear. When **White** is left at the default
  252. value of ``1.0``, Reinhard produces an identical image to Linear.
  253. - **Filmic:** Uses a film-like tonemapping curve to prevent clipping of
  254. bright values and provide better contrast than Reinhard. Slightly slower
  255. than Reinhard.
  256. - **ACES:** Uses a high-contrast film-like tonemapping curve and desaturates
  257. bright values for a more realistic appearance. Slightly slower than Filmic.
  258. - **AgX:** Uses a film-like tonemapping curve and desaturates bright values
  259. for a more realistic appearance. Better than other tonemappers at
  260. maintaining the hue of colors as they become brighter. The slowest
  261. tonemapping option. **White** is fixed at a value of ``16.29``,
  262. which makes AgX unsuitable for use with the Mobile rendering method.
  263. - **Exposure:** Adjusts the brightness of values before they are provided to
  264. the tonemapper. Higher **Exposure** values result in a brighter image.
  265. Values provided to the tonemapper will also be multiplied by ``2.0``
  266. and ``1.8`` for **Filmic** and **ACES** respectively to produce a similar
  267. apparent brightness as Linear.
  268. - **White:** The white reference value for tonemapping, which indicates where
  269. bright white is located in the scale of values provided to the tonemapper.
  270. For photorealistic lighting, recommended values are between ``6.0`` and
  271. ``8.0``. Higher values result in less blown out highlights, but may make the
  272. scene appear lower contrast. **White** is not available when using
  273. **Linear** or **AgX**.
  274. Mid- and post-processing effects
  275. --------------------------------
  276. The Environment resource supports many popular mid- and post-processing effects.
  277. .. note::
  278. Screen-space effects such as :abbr:`SSR (Screen-Space Reflections)`,
  279. :abbr:`SSAO (Screen-Space Ambient Occlusion)`,
  280. :abbr:`SSIL (Screen-Space Indirect Lighting)` and glow do not operate on
  281. geometry that is located outside the camera view or is occluded by other
  282. opaque geometry. Consider this when tweaking their settings to avoid
  283. distracting changes during gameplay.
  284. Screen-Space Reflections (SSR)
  285. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  286. *This feature is only available when using the Forward+ renderer, not
  287. Mobile or Compatibility.*
  288. While Godot supports several sources of reflection data such as
  289. :ref:`doc_reflection_probes`, they may not provide enough detail for all
  290. situations. Scenarios where screen-space reflections make the most sense are
  291. when objects are in contact with each other (object over floor, over a table,
  292. floating on water, etc).
  293. .. image:: img/environment_ssr.webp
  294. On top of providing more detail, screen-space reflections also work in real-time
  295. (while other types of reflections are usually precomputed). This can be used to
  296. make characters, cars, etc. reflect on surrounding surfaces when moving around.
  297. Screen-space reflections can be used at the same time as other reflection
  298. sources to benefit from detailed reflections when possible, while having a
  299. fallback when screen-space reflections cannot be used (for example, to reflect
  300. off-screen objects).
  301. A few user-controlled parameters are available to better tweak the technique:
  302. - **Max Steps:** Determines the length of the reflection. The bigger this
  303. number, the more costly it is to compute.
  304. - **Fade In:** Allows adjusting the fade-in curve, which is useful to make the
  305. contact area softer.
  306. - **Fade Out:** Allows adjusting the fade-out curve, so the step limit fades out
  307. softly.
  308. - **Depth Tolerance:** Can be used to allow screen-space rays to pass behind
  309. objects. The rays will treat each object as if it has this depth in
  310. determining if it can pass behind the object. Higher values will make
  311. screen-space reflections exhibit fewer "breakups", at the cost of some objects
  312. creating physically incorrect reflections.
  313. Keep in mind that screen-space-reflections only work for reflecting opaque
  314. geometry. Transparent materials won't be reflected, as they don't write to the depth buffer.
  315. This also applies to shaders that use ``hint_screen_texture`` or ``hint_depth_texture``
  316. uniforms.
  317. Screen-Space Ambient Occlusion (SSAO)
  318. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  319. *This feature is only available when using the Forward+ renderer, not
  320. Mobile or Compatibility.*
  321. As mentioned in the **Ambient** section, areas where light from light nodes
  322. does not reach (either because it's outside the radius or shadowed) are lit
  323. with ambient light. Godot can simulate this using VoxelGI, ReflectionProbe,
  324. the Sky, or a constant ambient color. The problem, however, is that all the
  325. methods proposed previously act more on a larger scale (large regions) than at the
  326. smaller geometry level.
  327. Constant ambient color and Sky are the same everywhere, while GI and
  328. Reflection probes have more local detail, but not enough to simulate situations
  329. where light is not able to fill inside hollow or concave features.
  330. This can be simulated with Screen Space Ambient Occlusion. As you can see in the
  331. image below, its purpose is to make sure concave areas are darker, simulating
  332. a narrower path for the light to enter:
  333. .. image:: img/environment_ssao.webp
  334. It is a common mistake to enable this effect, turn on a light, and not be able to
  335. appreciate it. This is because :abbr:`SSAO (Screen-Space Ambient Occlusion)`
  336. only acts on *ambient* light. It does not affect direct light.
  337. This is why, in the image above, the effect is less noticeable under the direct
  338. light (on the left). If you want to force
  339. :abbr:`SSAO (Screen-Space Ambient Occlusion)` to work with direct light too,
  340. use the **Light Affect** parameter. Even though this is not physically correct,
  341. some artists like how it looks.
  342. :abbr:`SSAO (Screen-Space Ambient Occlusion)` looks best when combined with a
  343. real source of indirect light, like VoxelGI:
  344. .. image:: img/environment_ssao2.webp
  345. Tweaking :abbr:`SSAO (Screen-Space Ambient Occlusion)` is possible with several
  346. parameters:
  347. .. image:: img/environment_ssao_parameters.webp
  348. - **Radius:** The distance at which objects can occlude each other when
  349. calculating screen-space ambient occlusion. Higher values will result in
  350. occlusion over a greater distance at the cost of performance and quality.
  351. - **Intensity:** The primary screen-space ambient occlusion intensity. Acts as a
  352. multiplier for the screen-space ambient occlusion effect. A higher value
  353. results in darker occlusion.
  354. Since :abbr:`SSAO (Screen-Space Ambient Occlusion)` is a screen-space effect,
  355. it's recommended to remain conservative with this value.
  356. :abbr:`SSAO (Screen-Space Ambient Occlusion)` that is too strong can be
  357. distracting during gameplay.
  358. - **Power:** The distribution of occlusion. A higher value results in darker
  359. occlusion, similar to **Intensity**, but with a sharper falloff.
  360. - **Detail:** Sets the strength of the additional level of detail for the
  361. screen-space ambient occlusion effect. A high value makes the detail pass more
  362. prominent, but it may contribute to aliasing in your final image.
  363. - **Horizon:** The threshold for considering whether a given point on a surface
  364. is occluded or not represented as an angle from the horizon mapped into the
  365. 0.0-1.0 range. A value of 1.0 results in no occlusion.
  366. - **Sharpness:** The amount that the screen-space ambient occlusion effect is
  367. allowed to blur over the edges of objects. Setting too high will result in
  368. aliasing around the edges of objects. Setting too low will make object edges
  369. appear blurry.
  370. - **Light Affect:** The screen-space ambient occlusion intensity in direct
  371. light. In real life, ambient occlusion only applies to indirect light, which
  372. means its effects can't be seen in direct light. Values higher than 0 will
  373. make the :abbr:`SSAO (Screen-Space Ambient Occlusion)` effect visible in
  374. direct light. Values above ``0.0`` are not physically accurate, but some
  375. artists prefer this effect.
  376. - **AO Channel Affect** The screen-space ambient occlusion intensity on
  377. materials that have an AO texture defined. Values higher than ``0.0`` will
  378. make the SSAO effect visible in areas darkened by AO textures.
  379. .. _doc_environment_and_post_processing_ssil:
  380. Screen-Space Indirect Lighting (SSIL)
  381. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  382. *This feature is only available when using the Forward+ renderer, not
  383. Mobile or Compatibility.*
  384. :abbr:`SSIL (Screen-Space Indirect Lighting)` provides indirect lighting for
  385. small details or dynamic geometry that other global illumination techniques
  386. cannot cover. This applies to bounced diffuse lighting, but also emissive
  387. materials. When :abbr:`SSIL (Screen-Space Indirect Lighting)` is enabled on its
  388. own, the effect may not be that noticeable, which is intended.
  389. Instead, :abbr:`SSIL (Screen-Space Indirect Lighting)` is meant to be used as a
  390. *complement* to other global illumination techniques such as VoxelGI, SDFGI and
  391. LightmapGI. :abbr:`SSIL (Screen-Space Indirect Lighting)` also provides
  392. a subtle ambient occlusion effect, similar to SSAO, but with less detail.
  393. This feature only provides indirect lighting. It is not a full global illumination
  394. solution. This makes it different from screen-space global illumination (SSGI)
  395. offered by other 3D engines. :abbr:`SSIL (Screen-Space Indirect Lighting)`
  396. can be combined with :abbr:`SSR (Screen-Space Reflections)` and/or
  397. :abbr:`SSAO (Screen-Space Ambient Occlusion)` for greater visual quality
  398. (at the cost of performance).
  399. Tweaking :abbr:`SSIL (Screen-Space Indirect Lighting)` is possible with several parameters:
  400. - **Radius:** The distance that bounced lighting can travel when using the
  401. screen space indirect lighting effect. A larger value will result in light
  402. bouncing further in a scene, but may result in under-sampling artifacts which
  403. look like long spikes surrounding light sources.
  404. - **Intensity:** The brightness multiplier for the screen-space indirect
  405. lighting effect. A higher value will result in brighter light.
  406. - **Sharpness:** The amount that the screen-space indirect lighting effect is
  407. allowed to blur over the edges of objects. Setting too high will result in
  408. aliasing around the edges of objects. Setting too low will make object edges
  409. appear blurry.
  410. - **Normal Rejection:** Amount of normal rejection used when calculating
  411. screen-space indirect lighting. Normal rejection uses the normal of a given
  412. sample point to reject samples that are facing away from the current pixel.
  413. Normal rejection is necessary to avoid light leaking when only one side of an
  414. object is illuminated. However, normal rejection can be disabled if light
  415. leaking is desirable, such as when the scene mostly contains emissive objects
  416. that emit light from faces that cannot be seen from the camera.
  417. .. image:: img/environment_ssil.webp
  418. Signed Distance Field Global Illumination (SDFGI)
  419. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  420. *This feature is only available when using the Forward+ renderer, not
  421. Mobile or Compatibility.*
  422. Signed distance field global illumination (SDFGI) is a form of real-time global
  423. illumination. It is not a screen-space effect, which means it can provide global
  424. illumination for off-screen elements (unlike :abbr:`SSIL (Screen-Space Indirect Lighting)`).
  425. .. seealso::
  426. See :ref:`doc_using_sdfgi` for instructions on setting up this global
  427. illumination technique.
  428. .. image:: img/environment_sdfgi.webp
  429. .. _doc_environment_and_post_processing_glow:
  430. Glow
  431. ~~~~
  432. .. note::
  433. When using the Compatibility rendering method, glow uses a different
  434. implementation with some properties being unavailable and hidden from the
  435. inspector: **Levels**, **Normalized**, **Strength**, **Blend Mode**,
  436. **Mix**, **Map**, and **Map Strength**.
  437. This implementation is optimized to run on low-end devices and is less
  438. flexible as a result.
  439. In photography and film, when light amount exceeds the maximum *luminance*
  440. (brightness) supported by the media, it generally bleeds outwards to darker
  441. regions of the image. This is simulated in Godot with the **Glow** effect.
  442. .. image:: img/environment_glow1.webp
  443. By default, even if the effect is enabled, it will be weak or invisible. One of
  444. two conditions need to happen for it to actually show:
  445. - 1) The light in a pixel surpasses the **HDR Threshold** (where 0 is all light
  446. surpasses it, and 1.0 is light over the tonemapper **White** value).
  447. Normally, this value is expected to be at 1.0, but it can be lowered to
  448. allow more light to bleed. There is also an extra parameter, **HDR Scale**,
  449. that allows scaling (making brighter or darker) the light surpassing the
  450. threshold.
  451. .. image:: img/environment_glow_threshold.webp
  452. - 2) The **Bloom** property has a value greater than ``0.0``. As it increases,
  453. it sends the whole screen to the glow processor at higher amounts.
  454. .. image:: img/environment_glow_bloom.webp
  455. Both will cause the light to start bleeding out of the brighter areas.
  456. Once glow is visible, it can be controlled with a few extra parameters:
  457. - **Intensity** is an overall scale for the effect, it can be made stronger or
  458. weaker (``0.0`` removes it).
  459. - **Strength** is how strong the gaussian filter kernel is processed. Greater
  460. values make the filter saturate and expand outwards. In general, changing this
  461. is not needed, as the size can be adjusted more efficiently with the **Levels**.
  462. The **Blend Mode** of the effect can also be changed:
  463. - **Additive** is the strongest one, as it only adds the glow effect over the
  464. image with no blending involved. In general, it's too strong to be used, but
  465. can look good with low-intensity **Bloom** (produces a dream-like effect).
  466. - **Screen** ensures glow never brightens more than itself and it works great as
  467. an all around.
  468. - **Softlight** is the default and weakest one, producing only a subtle color
  469. disturbance around the objects. This mode works best on dark scenes.
  470. - **Replace** can be used to
  471. :ref:`blur the whole screen <doc_environment_and_post_processing_using_glow_to_blur_the_screen>`
  472. or debug the effect. It only shows the glow effect without the image below.
  473. - **Mix** mixes the glow effect with the main image. This can be used for
  474. greater artistic control. The mix factor is controlled by the **Mix** property
  475. which appears above the blend mode (only when the blend mode is set to Mix).
  476. High mix factor values will appear to darken the image unless **Bloom** is
  477. increased.
  478. To change the glow effect size and shape, Godot provides **Levels**. Smaller
  479. levels are strong glows that appear around objects, while large levels are hazy
  480. glows covering the whole screen:
  481. .. image:: img/environment_glow_layers.webp
  482. The real strength of this system, though, is to combine levels to create more
  483. interesting glow patterns:
  484. .. image:: img/environment_glow_layers2.webp
  485. Finally, the glow effect can be controlled using a *glow map*, which is a
  486. texture that determines how bright glow should be on each part of the screen.
  487. This texture can optionally be colored to tint the glow effect to the glow map's
  488. color. The texture is stretched to fit the viewport, so using an aspect ratio
  489. that matches your viewport's most common aspect ratio (such as 16:9) is recommended
  490. to avoid visible distortion.
  491. There are 2 main use cases for a glow map texture:
  492. - Create a "lens dirt" effect using a dirt pattern texture.
  493. - Make glow less strong on specific parts of the screen by using a gradient texture.
  494. .. image:: img/environment_glow_map.webp
  495. By default, glow uses a bicubic scaling filter on desktop platforms and a
  496. bilinear scaling filter on mobile platforms. The bicubic scaling filter results
  497. in higher quality with a less blocky appearance, but it has a performance cost
  498. on the GPU which can be significant on integrated graphics.
  499. The scale mode can be controlled using the
  500. **Rendering > Environment > Glow > Upscale Mode** project setting.
  501. This setting is only effective when using the Forward+ or Mobile renderers,
  502. as Compatibility uses a different glow implementation.
  503. .. image:: img/environment_and_post_processing_glow_scale_mode.webp
  504. .. _doc_environment_and_post_processing_using_glow_in_2d:
  505. Using glow in 2D
  506. ~~~~~~~~~~~~~~~~
  507. There are 2 ways to use glow in 2D:
  508. - Since Godot 4.2, you can enable HDR for 2D rendering when using the Forward+
  509. and Mobile rendering methods. This has a performance cost, but it allows for a
  510. greater dynamic range. This also allows you to control which objects glow
  511. using their individual **Modulate** or **Self Modulate** properties (use the
  512. RAW mode in the color picker). Enabling HDR can also reduce banding in the 2D
  513. rendering output.
  514. - To enable HDR in 2D, open the Project Settings, enable
  515. :ref:`Rendering > Viewport > HDR 2D<class_ProjectSettings_property_rendering/viewport/hdr_2d>`
  516. then restart the editor.
  517. - If you want to maximize performance, you can leave HDR disabled for 2D
  518. rendering. However, you will have less control on which objects glow.
  519. - Enable glow, set the environment background mode to **Canvas** then decrease
  520. **Glow HDR Threshold** so that pixels that are not overbright will still
  521. glow. To prevent UI elements from glowing, make them children of a
  522. :ref:`class_CanvasLayer` node. You can control which layers are affected by
  523. glow using the **Background > Canvas Max Layer** property of the Environment
  524. resource.
  525. .. figure:: img/environment_and_post_processing_glow_in_2d.webp
  526. :align: center
  527. :alt: Example of using glow in a 2D scene
  528. Example of using glow in a 2D scene. HDR 2D is enabled, while coins and the
  529. bullet have their **Modulate** property increased to overbright values using the
  530. RAW mode in the color picker.
  531. .. warning::
  532. The 2D renderer renders in linear color space if the
  533. :ref:`Rendering > Viewport > HDR 2D<class_ProjectSettings_property_rendering/viewport/hdr_2d>`
  534. project setting is enabled, so the ``source_color`` hint must also be used
  535. for uniform samplers that are used as color input in ``canvas_item`` shaders.
  536. If this is not done, the texture will appear washed out.
  537. If 2D HDR is disabled, ``source_color`` will keep working correctly in
  538. ``canvas_item`` shaders, so it's recommend to use it when relevant either
  539. way.
  540. Using linear color space also means that alpha blending will change. Sprites
  541. with low opacity values generally become more visible, and font rendering will
  542. look bolder due to the low-opacity pixels from the font antialiasing becoming
  543. more visible. This also affects the editor's own rendering.
  544. .. _doc_environment_and_post_processing_using_glow_to_blur_the_screen:
  545. Using glow to blur the screen
  546. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  547. Glow can be used to blur the whole viewport, which is useful for background blur
  548. when a menu is open. Only 3D rendering will be affected unless the environment's
  549. background mode is set to **Canvas**. To prevent UI elements from being blurred
  550. when using the Canvas background mode, make them children of a :ref:`class_CanvasLayer`
  551. node. You can control which layers are affected by this blurring effect using the
  552. **Background > Canvas Max Layer** property of the Environment resource.
  553. To use glow as a blurring solution:
  554. - Enable **Normalized** and adjust levels according to preference. Increasing
  555. higher level indices will result in a more blurred image. It's recommended to
  556. leave a single glow level at ``1.0`` and leave all other glow levels at
  557. ``0.0``, but this is not required. Note that the final appearance will vary
  558. depending on viewport resolution.
  559. - Set **Intensity** to ``1.0`` and **Bloom** to ``1.0``.
  560. - Set the blend mode to **Replace** and **HDR Luminance Cap** to ``1.0``.
  561. .. figure:: img/environment_and_post_processing_glow_blur.webp
  562. :align: center
  563. :alt: Example of using glow to blur the 2D rendering in the menu's background
  564. Example of using glow to blur the 2D rendering in the menu's background
  565. Adjustments
  566. ~~~~~~~~~~~
  567. At the end of processing, Godot offers the possibility to do some standard
  568. image adjustments.
  569. .. image:: img/environment_adjustments.webp
  570. **Basic BCS adjustments**
  571. The first adjustment is being able to change the typical **Brightness**, **Contrast**,
  572. and **Saturation** properties:
  573. .. image:: img/environment_adjustments_bcs.webp
  574. **Color correction using a 1D gradient**
  575. The second adjustment is by supplying a color correction gradient. This can be
  576. done by assigning a GradientTexture1D resource to the **Color Correction**
  577. property, or by loading a texture containing a horizontal gradient. The leftmost
  578. part of the gradient represents black in the source image, whereas the rightmost
  579. part of the gradient represents white in the source image.
  580. A linear black-to-white gradient like the following one will produce no effect:
  581. .. image:: img/environment_adjustments_default_gradient.webp
  582. But creating custom ones will allow to map each channel to a different color:
  583. .. image:: img/environment_adjustments_custom_gradient.webp
  584. **Color correction using a 3D LUT**
  585. A 3D look-up-texture (LUT) can also be used for color correction. This is a
  586. special texture used to modify each color channel separately from one another
  587. (red, green, blue). This image can be of any resolution, but since color
  588. correction is low-frequency data, sticking to low resolutions is recommended for
  589. performance reasons. A LUT texture's resolution is typically 17×17×17, 33×33×33,
  590. 51×51×51 or 65×65×65 (the odd size allows for better interpolation).
  591. For this to work, the look-up texture's import mode must be set to Texture3D
  592. in the Import dock (instead of being imported as a regular Texture2D):
  593. .. image:: img/environment_adjustments_3d_lut_import.webp
  594. Make sure to configure the number of horizontal and vertical slices to import as
  595. well. If you don't do this, the LUT texture will not affect the viewport
  596. correctly when used. You can preview how the 3D texture was imported by
  597. double-clicking it, in the FileSystem dock, then going to the inspector to flip
  598. through the texture's layers.
  599. You can use this neutral 33×33×33 LUT template as a base (right-click and choose
  600. **Save as…**):
  601. .. image:: img/environment_adjustments_3d_lut_template.webp
  602. With the above LUT template, after changing its import mode to **Texture3D**,
  603. set its number of **Horizontal** slices to ``33`` in the Import dock then click
  604. **Reimport**. If you load this LUT into the **Color Correction** property, you
  605. won't see any visible difference for now since this texture is designed to be a
  606. neutral starting point.
  607. This LUT template can be modified in an image editor to provide a different
  608. mood to the image. A common workflow is to place the LUT image next to a
  609. screenshot of the project's 3D viewport, then use an image editor to modify both
  610. the LUT image and the screenshot at the same time. The LUT can then be saved and
  611. applied to the game engine to perform the same color correction in real-time.
  612. For example, modifying the LUT template in an image editor to give it a
  613. "sepia" look results in the image on the right:
  614. .. image:: img/environment_adjustments_3d_lut_comparison.webp
  615. .. note::
  616. Adjustments and color correction are applied *after* tonemapping.
  617. This means the tonemapping properties defined above still have an effect
  618. when adjustments are enabled.
  619. Camera attribute options
  620. ------------------------
  621. Depth of Field / Far Blur
  622. ~~~~~~~~~~~~~~~~~~~~~~~~~
  623. This effect simulates focal distance on cameras. It blurs objects behind
  624. a given range. It has an initial **Distance** with a **Transition** region
  625. (in world units):
  626. .. image:: img/environment_dof_far.webp
  627. The **Amount** parameter controls the amount of blur. For larger blurs, tweaking
  628. the depth of field quality in the advanced project settings may be needed to
  629. avoid artifacts.
  630. Depth of Field / Near Blur
  631. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  632. This effect simulates focal distance on cameras. It blurs objects close
  633. to the camera (acts in the opposite direction as far blur).
  634. It has an initial **Distance** with a **Transition** region (in world units):
  635. .. image:: img/environment_dof_near.webp
  636. The **Amount** parameter controls the amount of blur. For larger blurs, tweaking
  637. the **Quality** may be needed in order to avoid artifacts.
  638. It is common to use both blurs together to focus the viewer's attention on a
  639. given object, or create a so-called
  640. `"tilt shift" effect <https://en.wikipedia.org/wiki/Miniature_faking>`__.
  641. .. image:: img/environment_mixed_blur.webp
  642. .. note::
  643. When using CameraAttributesPhysical instead of CameraAttributesPractical,
  644. depth of field is automatically computed from the camera attributes' focus
  645. distance, focal length, and aperture.
  646. Exposure
  647. ~~~~~~~~
  648. This multiplies the overall scene brightness visible from the camera. Higher
  649. values result in a visually brighter scene.
  650. Auto Exposure
  651. ~~~~~~~~~~~~~
  652. *This feature is only available when using the Forward+ renderer, not
  653. Mobile or Compatibility.*
  654. Even though, in most cases, lighting and texturing are heavily artist controlled,
  655. Godot supports a basic high dynamic range implementation with the auto exposure
  656. mechanism. This is generally used to add realism when combining interior areas
  657. with low light and bright outdoor areas. Auto exposure simulates the camera
  658. (or eye) in an effort to adapt between light and dark locations and their
  659. different amounts of light.
  660. .. note::
  661. Auto exposure needs to evaluate the scene's brightness every frame, which
  662. has a moderate performance cost. Therefore, it's recommended to leave Auto
  663. Exposure disabled if it doesn't make much of a difference in your scene.
  664. .. image:: img/environment_hdr_autoexp.webp
  665. The simplest way to use auto exposure is to make sure outdoor lights (or other
  666. strong lights) have energy beyond 1.0. This is done by tweaking their **Energy**
  667. multiplier (on the Light itself). To make it consistent, the **Sky** usually
  668. needs to use the energy multiplier too, to match with the directional light.
  669. Normally, values between 3.0 and 6.0 are enough to simulate indoor-outdoor conditions.
  670. By combining Auto Exposure with :ref:`doc_environment_and_post_processing_glow`
  671. post-processing, pixels that go over the tonemap **White** will bleed to the
  672. glow buffer, creating the typical bloom effect in photography.
  673. .. image:: img/environment_hdr_bloom.webp
  674. The user-controllable values in the Auto Exposure section come with sensible
  675. defaults, but you can still tweak them:
  676. .. image:: img/environment_hdr.webp
  677. - **Scale:** Value to scale the lighting. Higher values produce brighter
  678. images, and lower values produce darker ones.
  679. - **Min Sensitivity / Min Exposure Value:** Minimum luminance that auto exposure
  680. will aim to adjust for (in ISO when using CameraAttributesPractical, or in
  681. EV100 when using CameraAttributesPhysical). Luminance is the average of the
  682. light in all the pixels of the screen.
  683. - **Max Sensitivity / Max Exposure Value:** Maximum luminance that auto exposure
  684. will aim to adjust for (in ISO when using CameraAttributesPractical, or in
  685. EV100 when using CameraAttributesPhysical).
  686. - **Speed:** Speed at which luminance corrects itself. The higher the value, the
  687. faster luminance correction happens. High values may be more suited to
  688. fast-paced games, but can be distracting in some scenarios.
  689. When using CameraAttributesPractical, exposure is set using *sensitivity*
  690. defined in ISO instead of an exposure value in EV100. Typical ISO values are
  691. between 50 and 3200, with higher values resulting in higher final exposure. In
  692. real life, daytime photography generally uses ISO values between 100 and 800.
  693. .. seealso::
  694. See :ref:`doc_physical_light_and_camera_units` if you wish to use real world
  695. units to configure your camera's exposure, field of view and depth of field.