fog_shader.rst 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. .. _doc_fog_shader:
  2. Fog shaders
  3. ===========
  4. Fog shaders are used to define how fog is added (or subtracted) from a scene in
  5. a given area. Fog shaders are always used together with
  6. :ref:`FogVolumes <class_FogVolume>` and volumetric fog. Fog shaders only have
  7. one processing function, the ``fog()`` function.
  8. The resolution of the fog shaders depends on the resolution of the
  9. volumetric fog froxel grid. Accordingly, the level of detail that a fog shader
  10. can add depends on how close the :ref:`FogVolume <class_FogVolume>` is to the
  11. camera.
  12. Fog shaders are a special form of compute shader that is called once for
  13. every froxel that is touched by an axis aligned bounding box of the associated
  14. :ref:`FogVolume <class_FogVolume>`. This means that froxels that just barely
  15. touch a given :ref:`FogVolume <class_FogVolume>` will still be used.
  16. Built-ins
  17. ^^^^^^^^^
  18. Values marked as ``in`` are read-only. Values marked as ``out`` can optionally
  19. be written to and will not necessarily contain sensible values. Samplers cannot
  20. be written to so they are not marked.
  21. Global built-ins
  22. ^^^^^^^^^^^^^^^^
  23. Global built-ins are available everywhere, including in custom functions.
  24. +-----------------------------------+------------------------------------------------------------------------------------------+
  25. | Built-in | Description |
  26. +===================================+==========================================================================================+
  27. | in float **TIME** | Global time since the engine has started, in seconds. It repeats after every ``3,600`` |
  28. | | seconds (which can be changed with the |
  29. | | :ref:`rollover<class_ProjectSettings_property_rendering/limits/time/time_rollover_secs>` |
  30. | | setting). It's affected by |
  31. | | :ref:`time_scale<class_Engine_property_time_scale>` but not by pausing. If you need a |
  32. | | ``TIME`` variable that is not affected by time scale, add your own |
  33. | | :ref:`global shader uniform<doc_shading_language_global_uniforms>` and update it each |
  34. | | frame. |
  35. +-----------------------------------+------------------------------------------------------------------------------------------+
  36. | in float **PI** | A ``PI`` constant (``3.141592``). |
  37. | | A ratio of a circle's circumference to its diameter and amount of radians in half turn. |
  38. +-----------------------------------+------------------------------------------------------------------------------------------+
  39. | in float **TAU** | A ``TAU`` constant (``6.283185``). |
  40. | | An equivalent of ``PI * 2`` and amount of radians in full turn. |
  41. +-----------------------------------+------------------------------------------------------------------------------------------+
  42. | in float **E** | An ``E`` constant (``2.718281``). |
  43. | | Euler's number and a base of the natural logarithm. |
  44. +-----------------------------------+------------------------------------------------------------------------------------------+
  45. Fog built-ins
  46. ^^^^^^^^^^^^^
  47. All of the output values of fog volumes overlap one another. This allows
  48. :ref:`FogVolumes <class_FogVolume>` to be rendered efficiently as they can all
  49. be drawn at once.
  50. +-------------------------------+-------------------------------------------------------------------------------------------------+
  51. | Built-in | Description |
  52. +===============================+=================================================================================================+
  53. | in vec3 **WORLD_POSITION** | Position of current froxel cell in world space. |
  54. +-------------------------------+-------------------------------------------------------------------------------------------------+
  55. | in vec3 **OBJECT_POSITION** | Position of the center of the current :ref:`FogVolume <class_FogVolume>` in world space. |
  56. +-------------------------------+-------------------------------------------------------------------------------------------------+
  57. | in vec3 **UVW** | 3-dimensional UV, used to map a 3D texture to the current :ref:`FogVolume <class_FogVolume>`. |
  58. +-------------------------------+-------------------------------------------------------------------------------------------------+
  59. | in vec3 **SIZE** | Size of the current :ref:`FogVolume <class_FogVolume>` when its |
  60. | | :ref:`shape<class_FogVolume_property_shape>` has a size. |
  61. +-------------------------------+-------------------------------------------------------------------------------------------------+
  62. | in vec3 **SDF** | Signed distance field to the surface of the :ref:`FogVolume <class_FogVolume>`. Negative if |
  63. | | inside volume, positive otherwise. |
  64. +-------------------------------+-------------------------------------------------------------------------------------------------+
  65. | out vec3 **ALBEDO** | Output base color value, interacts with light to produce final color. Only written to fog |
  66. | | volume if used. |
  67. +-------------------------------+-------------------------------------------------------------------------------------------------+
  68. | out float **DENSITY** | Output density value. Can be negative to allow subtracting one volume from another. Density |
  69. | | must be used for fog shader to write anything at all. |
  70. +-------------------------------+-------------------------------------------------------------------------------------------------+
  71. | out vec3 **EMISSION** | Output emission color value, added to color during light pass to produce final color. Only |
  72. | | written to fog volume if used. |
  73. +-------------------------------+-------------------------------------------------------------------------------------------------+