Browse Source

Merge pull request #5005 from Chaosus/shader_constants

Added shader built-in constants + fix formatting of table headers
Yuri Roubinsky 4 years ago
parent
commit
4ca31c73b7

+ 21 - 12
tutorials/shaders/shader_reference/canvas_item_shader.rst

@@ -48,15 +48,24 @@ Global built-ins
 
 Global built-ins are available everywhere, including custom functions.
 
-+-------------------+-----------------------------------------------------------------------------+
-| Built-in          | Description                                                                 |
-+===================+=============================================================================+
-| in float **TIME** | Global time since the engine has started, in seconds (always positive).     |
-|                   | It's subject to the rollover setting (which is 3,600 seconds by default).   |
-|                   | It's not affected by :ref:`time_scale<class_Engine_property_time_scale>`    |
-|                   | or pausing, but you can define a global shader uniform to add a "scaled"    |
-|                   | ``TIME`` variable if desired.                                               |
-+-------------------+-----------------------------------------------------------------------------+
++-------------------+----------------------------------------------------------------------------------------+
+| Built-in          | Description                                                                            |
++===================+========================================================================================+
+| in float **TIME** | Global time since the engine has started, in seconds (always positive).                |
+|                   | It's subject to the rollover setting (which is 3,600 seconds by default).              |
+|                   | It's not affected by :ref:`time_scale<class_Engine_property_time_scale>`               |
+|                   | or pausing, but you can define a global shader uniform to add a "scaled"               |
+|                   | ``TIME`` variable if desired.                                                          |
++-------------------+----------------------------------------------------------------------------------------+
+| in float **PI**   | A ``PI`` constant (``3.141592``).                                                      |
+|                   | A ration of circle's circumference to its diameter and amount of radians in half turn. |
++-------------------+----------------------------------------------------------------------------------------+
+| in float **TAU**  | A ``TAU`` constant (``6.283185``).                                                     |
+|                   | An equivalent of ``PI * 2`` and amount of radians in full turn.                        |
++-------------------+----------------------------------------------------------------------------------------+
+| in float **E**    | A ``E`` constant (``2.718281``).                                                       |
+|                   | Euler's number and a base of natural logarithm.                                        |
++-------------------+----------------------------------------------------------------------------------------+
 
 Vertex built-ins
 ^^^^^^^^^^^^^^^^
@@ -111,7 +120,7 @@ is usually:
 
 +--------------------------------+---------------------------------------------------+
 | Built-in                       | Description                                       |
-+--------------------------------+---------------------------------------------------+
++================================+===================================================+
 | in mat4 **WORLD_MATRIX**       | Image space to view space transform.              |
 +--------------------------------+---------------------------------------------------+
 | in mat4 **CANVAS_MATRIX**      |                                                   |
@@ -158,7 +167,7 @@ it to the ``NORMALMAP`` property. Godot will handle converting it for use in 2D
 
 +---------------------------------------------+---------------------------------------------------------------+
 | Built-in                                    | Description                                                   |
-+---------------------------------------------+---------------------------------------------------------------+
++=============================================+===============================================================+
 | in vec4 **FRAGCOORD**                       | Coordinate of pixel center. In screen space. ``xy`` specifies |
 |                                             | position in window, ``z`` specifies fragment depth if         |
 |                                             | ``DEPTH`` is not used. Origin is lower-left.                  |
@@ -217,7 +226,7 @@ When the shader is on a light pass, the ``AT_LIGHT_PASS`` variable will be ``tru
 
 +--------------------------------+------------------------------------------------------------------------------+
 | Built-in                       | Description                                                                  |
-+--------------------------------+------------------------------------------------------------------------------+
++================================+==============================================================================+
 | in vec4 **FRAGCOORD**          | Coordinate of pixel center. In screen space. ``xy`` specifies                |
 |                                | position in window, ``z`` specifies fragment depth if                        |
 |                                | ``DEPTH`` is not used. Origin is lower-left.                                 |

+ 15 - 7
tutorials/shaders/shader_reference/particle_shader.rst

@@ -49,11 +49,19 @@ Global built-ins
 
 Global built-ins are available everywhere, including custom functions.
 
-+-------------------+--------------------------+
-| Built-in          | Description              |
-+===================+==========================+
-| in float **TIME** | Global time, in seconds. |
-+-------------------+--------------------------+
++-------------------+----------------------------------------------------------------------------------------+
+|  Built-in         |  Description                                                                           |
++===================+========================================================================================+
+| in float **TIME** | Global time, in seconds.                                                               |
++-------------------+----------------------------------------------------------------------------------------+
+| in float **PI**   | A ``PI`` constant (``3.141592``).                                                      |
+|                   | A ration of circle's circumference to its diameter and amount of radians in half turn. |
++-------------------+----------------------------------------------------------------------------------------+
+| in float **TAU**  | A ``TAU`` constant (``6.283185``).                                                     |
+|                   | An equivalent of ``PI * 2`` and amount of radians in full turn.                        |
++-------------------+----------------------------------------------------------------------------------------+
+| in float **E**    | A ``E`` constant (``2.718281``). Euler's number and a base of natural logarithm.       |
++-------------------+----------------------------------------------------------------------------------------+
 
 Start built-ins
 ^^^^^^^^^^^^^^^
@@ -63,7 +71,7 @@ to ``true``. In a ShaderMaterial, access it with the ``COLOR`` variable.
 
 +--------------------------------+------------------------------------------------------------------------------+
 | Built-in                       | Description                                                                  |
-+--------------------------------+------------------------------------------------------------------------------+
++================================+==============================================================================+
 | in float **LIFETIME**          | Particle lifetime.                                                           |
 +--------------------------------+------------------------------------------------------------------------------+
 | in float **DELTA**             | Delta process time.                                                          |
@@ -106,7 +114,7 @@ Process built-ins
 
 +---------------------------------+------------------------------------------------------------------------------+
 | Built-in                        | Description                                                                  |
-+---------------------------------+------------------------------------------------------------------------------+
++=================================+==============================================================================+
 | in float **LIFETIME**           | Particle lifetime.                                                           |
 +---------------------------------+------------------------------------------------------------------------------+
 | in float **DELTA**              | Delta process time.                                                          |

+ 10 - 1
tutorials/shaders/shader_reference/sky_shader.rst

@@ -140,13 +140,22 @@ There are 4 ``LIGHTX`` lights, accessed as ``LIGHT0``, ``LIGHT1``, ``LIGHT2``, a
 +---------------------------------+--------------------------------------------------------------------------------------------------------------------------+
 | in float **LIGHTX_SIZE**        | Angular diameter of ``LIGHTX`` in the sky. Expressed in degrees. For reference, the sun from earth is about 0.5 degrees. |
 +---------------------------------+--------------------------------------------------------------------------------------------------------------------------+
+| in float **PI**                 | A ``PI`` constant (``3.141592``).                                                                                        |
+|                                 | A ration of circle's circumference to its diameter and amount of radians in half turn.                                   |
++---------------------------------+--------------------------------------------------------------------------------------------------------------------------+
+| in float **TAU**                | A ``TAU`` constant (``6.283185``).                                                                                       |
+|                                 | An equivalent of ``PI * 2`` and amount of radians in full turn.                                                          |
++---------------------------------+--------------------------------------------------------------------------------------------------------------------------+
+| in float **E**                  | A ``E`` constant (``2.718281``).                                                                                         |
+|                                 | Euler's number and a base of natural logarithm.                                                                          |
++---------------------------------+--------------------------------------------------------------------------------------------------------------------------+
 
 Sky built-ins
 ^^^^^^^^^^^^^
 
 +-------------------------------+-------------------------------------------------------------------------------------------------+
 | Built-in                      | Description                                                                                     |
-+-------------------------------+-------------------------------------------------------------------------------------------------+
++===============================+=================================================================================================+
 | in vec3 **EYEDIR**            | Normalized direction of current pixel. Use this as your basic direction for procedural effects. |
 +-------------------------------+-------------------------------------------------------------------------------------------------+
 | in vec2 **SCREEN_UV**         | Screen UV coordinate for current pixel. Used to map a texture to the full screen.               |

+ 16 - 8
tutorials/shaders/shader_reference/spatial_shader.rst

@@ -90,11 +90,19 @@ Global built-ins
 
 Global built-ins are available everywhere, including custom functions.
 
-+-------------------+--------------------------+
-| Built-in          | Description              |
-+===================+==========================+
-| in float **TIME** | Global time, in seconds. |
-+-------------------+--------------------------+
++-------------------+----------------------------------------------------------------------------------------+
+|  Built-in         |  Description                                                                           |
++===================+========================================================================================+
+| in float **TIME** | Global time, in seconds.                                                               |
++-------------------+----------------------------------------------------------------------------------------+
+| in float **PI**   | A ``PI`` constant (``3.141592``).                                                      |
+|                   | A ration of circle's circumference to its diameter and amount of radians in half turn. |
++-------------------+----------------------------------------------------------------------------------------+
+| in float **TAU**  | A ``TAU`` constant (``6.283185``).                                                     |
+|                   | An equivalent of ``PI * 2`` and amount of radians in full turn.                        |
++-------------------+----------------------------------------------------------------------------------------+
+| in float **E**    | A ``E`` constant (``2.718281``). Euler's number and a base of natural logarithm.       |
++-------------------+----------------------------------------------------------------------------------------+
 
 Vertex built-ins
 ^^^^^^^^^^^^^^^^
@@ -137,7 +145,7 @@ shader, this value can be used as desired.
 
 +----------------------------------------+--------------------------------------------------------+
 | Built-in                               | Description                                            |
-+----------------------------------------+--------------------------------------------------------+
++========================================+========================================================+
 | in vec2 **VIEWPORT_SIZE**              | Size of viewport (in pixels).                          |
 +----------------------------------------+--------------------------------------------------------+
 | in mat4 **INV_CAMERA_MATRIX**          | World space to view space transform.                   |
@@ -205,7 +213,7 @@ these properties, and if you don't write to them, Godot will optimize away the c
 
 +-------------------------------------------+--------------------------------------------------------------------------------------------------+
 | Built-in                                  | Description                                                                                      |
-+-------------------------------------------+--------------------------------------------------------------------------------------------------+
++===========================================+==================================================================================================+
 | in vec2 **VIEWPORT_SIZE**                 | Size of viewport (in pixels).                                                                    |
 +-------------------------------------------+--------------------------------------------------------------------------------------------------+
 | in vec4 **FRAGCOORD**                     | Coordinate of pixel center in screen space. ``xy`` specifies position in window, ``z``           |
@@ -347,7 +355,7 @@ If you want the lights to add together, add the light contribution to ``DIFFUSE_
 
 +-----------------------------------+----------------------------------------------------+
 | Built-in                          | Description                                        |
-+-----------------------------------+----------------------------------------------------+
++===================================+====================================================+
 | in vec2 **VIEWPORT_SIZE**         | Size of viewport (in pixels).                      |
 +-----------------------------------+----------------------------------------------------+
 | in vec4 **FRAGCOORD**             | Coordinate of pixel center in screen space.        |