fog_shader.rst 6.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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" are for optional
  19. writing and will not necessarily contain sensible values. Samplers cannot be
  20. 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, in seconds. |
  28. +---------------------------------+-----------------------------------------------------------------------------------------+
  29. | in float **PI** | A ``PI`` constant (``3.141592``). |
  30. | | A ratio of a circle's circumference to its diameter and amount of radians in half turn. |
  31. +---------------------------------+-----------------------------------------------------------------------------------------+
  32. | in float **TAU** | A ``TAU`` constant (``6.283185``). |
  33. | | An equivalent of ``PI * 2`` and amount of radians in full turn. |
  34. +---------------------------------+-----------------------------------------------------------------------------------------+
  35. | in float **E** | A ``E`` constant (``2.718281``). |
  36. | | Euler's number and a base of the natural logarithm. |
  37. +---------------------------------+-----------------------------------------------------------------------------------------+
  38. Fog built-ins
  39. ^^^^^^^^^^^^^
  40. All of the output values of fog volumes overlap one another. This allows
  41. :ref:`FogVolumes <class_FogVolume>` to be rendered efficiently as they can all
  42. be drawn at once.
  43. +-------------------------------+-------------------------------------------------------------------------------------------------+
  44. | Built-in | Description |
  45. +===============================+=================================================================================================+
  46. | in vec3 **WORLD_POSITION** | Position of current froxel cell in world space. |
  47. +-------------------------------+-------------------------------------------------------------------------------------------------+
  48. | in vec3 **OBJECT_POSITION** | Position of the center of the current :ref:`FogVolume <class_FogVolume>` in world space. |
  49. +-------------------------------+-------------------------------------------------------------------------------------------------+
  50. | in vec3 **UVW** | 3-dimensional uv, used to map a 3D texture to the current :ref:`FogVolume <class_FogVolume>`. |
  51. +-------------------------------+-------------------------------------------------------------------------------------------------+
  52. | in vec3 **EXTENTS** | Color value of corresponding pixel from half resolution pass. Uses linear filter. |
  53. +-------------------------------+-------------------------------------------------------------------------------------------------+
  54. | in vec3 **SDF** | Signed distance field to the surface of the :ref:`FogVolume <class_FogVolume>`. Negative if |
  55. | | inside volume, positive otherwise. |
  56. +-------------------------------+-------------------------------------------------------------------------------------------------+
  57. | out vec3 **ALBEDO** | Output base color value, interacts with light to produce final color. Only written to fog |
  58. | | volume if used. |
  59. +-------------------------------+-------------------------------------------------------------------------------------------------+
  60. | out float **DENSITY** | Output density value. Can be negative to allow subtracting one volume from another. Density |
  61. | | must be used for fog shader to write anything at all. |
  62. +-------------------------------+-------------------------------------------------------------------------------------------------+
  63. | out vec3 **EMISSION** | Output emission color value, added to color during light pass to produce final color. Only |
  64. | | written to fog volume if used. |
  65. +-------------------------------+-------------------------------------------------------------------------------------------------+