浏览代码

More fixes for shader built-ins

Yuri Roubinsky 3 年之前
父节点
当前提交
729648f135

+ 1 - 1
tutorials/shaders/making_trees.rst

@@ -39,7 +39,7 @@ This is an example of a shader for leaves:
 .. code-block:: glsl
 
     shader_type spatial;
-    render_mode depth_draw_alpha_prepass, cull_disabled, world_vertex_coords;
+    render_mode depth_prepass_alpha, cull_disabled, world_vertex_coords;
 
 This is a spatial shader. There is no front/back culling (so leaves can be seen from both sides), and alpha prepass is used, so there are less depth artifacts that result from using transparency (and leaves cast shadow). Finally, for the sway effect, world coordinates are recommended, so the tree can be duplicated, moved, etc. and it will still work together with other trees.
 

+ 18 - 0
tutorials/shaders/shader_reference/canvas_item_shader.rst

@@ -144,6 +144,24 @@ is usually:
 | inout float **POINT_SIZE**     | Point size for point drawing.                     |
 +--------------------------------+---------------------------------------------------+
 
+SDF functions
+^^^^^^^^^^^^^
+
+There are some functions implemented to support a SDF (Signed Distance Field) feature.
+They are available for Fragment and Light functions of CanvasItem shader.
+
++-----------------------------------------------+----------------------------------------+
+| Function                                      | Description                            |
++===============================================+========================================+
+| float **texture_sdf** (vec2 sdf_pos)          | Performs an SDF texture lookup.        |
++-----------------------------------------------+----------------------------------------+
+| vec2 **texture_sdf_normal** (vec2 sdf_pos)    | Performs an SDF normal texture lookup. |
++-----------------------------------------------+----------------------------------------+
+| vec2 **sdf_to_screen_uv** (vec2 sdf_pos)      | Converts a SDF to screen UV.           |
++-----------------------------------------------+----------------------------------------+
+| vec2 **screen_uv_to_sdf** (vec2 uv)           | Converts screen UV to a SDF.           |
++-----------------------------------------------+----------------------------------------+
+
 Fragment built-ins
 ^^^^^^^^^^^^^^^^^^
 

+ 79 - 89
tutorials/shaders/shader_reference/particle_shader.rst

@@ -63,99 +63,89 @@ Global built-ins are available everywhere, including custom functions.
 | in float **E**    | A ``E`` constant (``2.718281``). Euler's number and a base of natural logarithm.       |
 +-------------------+----------------------------------------------------------------------------------------+
 
+Start and Process built-ins
+^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
++---------------------------------+--------------------------------------------------------------------------------+
+| Function                        | Description                                                                    |
++=================================+================================================================================+
+| in float **LIFETIME**           | Particle lifetime.                                                             |
++---------------------------------+--------------------------------------------------------------------------------+
+| in float **DELTA**              | Delta process time.                                                            |
++---------------------------------+--------------------------------------------------------------------------------+
+| in uint **NUMBER**              | Unique number since emission start.                                            |
++---------------------------------+--------------------------------------------------------------------------------+
+| in uint **INDEX**               | Particle index (from total particles).                                         |
++---------------------------------+--------------------------------------------------------------------------------+
+| in mat4 **EMISSION_TRANSFORM**  | Emitter transform (used for non-local systems).                                |
++---------------------------------+--------------------------------------------------------------------------------+
+| in uint **RANDOM_SEED**         | Random seed used as base for random.                                           |
++---------------------------------+--------------------------------------------------------------------------------+
+| inout bool **ACTIVE**           | ``true`` when Particle is active, can be set ``false``.                        |
++---------------------------------+--------------------------------------------------------------------------------+
+| inout vec4 **COLOR**            | Particle color, can be written to and accessed in mesh's vertex function.      |
++---------------------------------+--------------------------------------------------------------------------------+
+| inout vec3 **VELOCITY**         | Particle velocity, can be modified.                                            |
++---------------------------------+--------------------------------------------------------------------------------+
+| inout mat4 **TRANSFORM**        | Particle transform.                                                            |
++---------------------------------+--------------------------------------------------------------------------------+
+| inout vec4 **CUSTOM**           | Custom particle data. Accessible from shader of mesh as **INSTANCE_CUSTOM**.   |
++---------------------------------+--------------------------------------------------------------------------------+
+| inout float **MASS**            | Particle mass, intended to be used with attractors. Equals ``1.0`` by default. |
++---------------------------------+--------------------------------------------------------------------------------+
+
+.. note:: In order to use the ``COLOR`` variable in a StandardMaterial3D, set ``vertex_color_use_as_albedo``
+          to ``true``. In a ShaderMaterial, access it with the ``COLOR`` variable.
+
 Start built-ins
 ^^^^^^^^^^^^^^^
 
-In order to use the ``COLOR`` variable in a StandardMaterial3D, set ``use_vertex_as_albedo``
-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.                                                          |
-+--------------------------------+------------------------------------------------------------------------------+
-| in uint **NUMBER**             | Unique number since emission start.                                          |
-+--------------------------------+------------------------------------------------------------------------------+
-| in uint **INDEX**              | Particle index (from total particles).                                       |
-+--------------------------------+------------------------------------------------------------------------------+
-| in mat4 **EMISSION_TRANSFORM** | Emitter transform (used for non-local systems).                              |
-+--------------------------------+------------------------------------------------------------------------------+
-| in uint **RANDOM_SEED**        | Random seed used as base for random.                                         |
-+--------------------------------+------------------------------------------------------------------------------+
-| in bool **RESTART**            | ``true`` when particle must restart (lifetime cycled).                       |
-+--------------------------------+------------------------------------------------------------------------------+
-| in bool **RESTART_POSITION**   |                                                                              |
-+--------------------------------+------------------------------------------------------------------------------+
-| in bool **RESTART_ROT_SCALE**  |                                                                              |
-+--------------------------------+------------------------------------------------------------------------------+
-| in bool **RESTART_VELOCITY**   |                                                                              |
-+--------------------------------+------------------------------------------------------------------------------+
-| in bool **RESTART_COLOR**      |                                                                              |
-+--------------------------------+------------------------------------------------------------------------------+
-| in bool **RESTART_CUSTOM**     |                                                                              |
-+--------------------------------+------------------------------------------------------------------------------+
-| inout bool **ACTIVE**          | ``true`` when Particle is active, can be set ``false``.                      |
-+--------------------------------+------------------------------------------------------------------------------+
-| inout vec4 **COLOR**           | Particle color, can be written to and accessed in mesh's vertex function.    |
-+--------------------------------+------------------------------------------------------------------------------+
-| inout vec3 **VELOCITY**        | Particle velocity, can be modified.                                          |
-+--------------------------------+------------------------------------------------------------------------------+
-| inout mat4 **TRANSFORM**       | Particle transform.                                                          |
-+--------------------------------+------------------------------------------------------------------------------+
-| inout vec4 **CUSTOM**          | Custom particle data. Accessible from shader of mesh as **INSTANCE_CUSTOM**. |
-+--------------------------------+------------------------------------------------------------------------------+
-| out float **MASS**             | Particle mass, use for attractors.                                           |
-+--------------------------------+------------------------------------------------------------------------------+
++---------------------------------+-------------+
+| Built-in                        | Description |
++=================================+=============+
+| in bool **RESTART_POSITION**    |             |
++---------------------------------+-------------+
+| in bool **RESTART_ROT_SCALE**   |             |
++---------------------------------+-------------+
+| in bool **RESTART_VELOCITY**    |             |
++---------------------------------+-------------+
+| in bool **RESTART_COLOR**       |             |
++---------------------------------+-------------+
+| in bool **RESTART_CUSTOM**      |             |
++---------------------------------+-------------+
+| in bool **RESTART_VELOCITY**    |             |
++---------------------------------+-------------+
 
 Process built-ins
 ^^^^^^^^^^^^^^^^^
 
-+---------------------------------+------------------------------------------------------------------------------+
-| Built-in                        | Description                                                                  |
-+=================================+==============================================================================+
-| in float **LIFETIME**           | Particle lifetime.                                                           |
-+---------------------------------+------------------------------------------------------------------------------+
-| in float **DELTA**              | Delta process time.                                                          |
-+---------------------------------+------------------------------------------------------------------------------+
-| in uint **NUMBER**              | Unique number since emission start.                                          |
-+---------------------------------+------------------------------------------------------------------------------+
-| in uint **INDEX**               | Particle index (from total particles).                                       |
-+---------------------------------+------------------------------------------------------------------------------+
-| in mat4 **EMISSION_TRANSFORM**  | Emitter transform (used for non-local systems).                              |
-+---------------------------------+------------------------------------------------------------------------------+
-| in uint **RANDOM_SEED**         | Random seed used as base for random.                                         |
-+---------------------------------+------------------------------------------------------------------------------+
-| in bool **RESTART**             | ``true`` when particle must restart (lifetime cycled).                       |
-+---------------------------------+------------------------------------------------------------------------------+
-| in uint **FLAG_EMIT_POSITION**  |                                                                              |
-+---------------------------------+------------------------------------------------------------------------------+
-| in uint **FLAG_EMIT_ROT_SCALE** |                                                                              |
-+---------------------------------+------------------------------------------------------------------------------+
-| in uint **FLAG_EMIT_VELOCITY**  |                                                                              |
-+---------------------------------+------------------------------------------------------------------------------+
-| in uint **FLAG_EMIT_COLOR**     |                                                                              |
-+---------------------------------+------------------------------------------------------------------------------+
-| in uint **FLAG_EMIT_CUSTOM**    |                                                                              |
-+---------------------------------+------------------------------------------------------------------------------+
-| in bool **COLLIDED**            | ``true`` when particle is collided with particle collider.                   |
-+---------------------------------+------------------------------------------------------------------------------+
-| in vec3 **COLLISION_NORMAL**    |                                                                              |
-+---------------------------------+------------------------------------------------------------------------------+
-| in float **COLLISION_DEPTH**    |                                                                              |
-+---------------------------------+------------------------------------------------------------------------------+
-| in vec3 **ATTRACTOR_FORCE**     |                                                                              |
-+---------------------------------+------------------------------------------------------------------------------+
-| inout bool **ACTIVE**           | ``true`` when Particle is active, can be set ``false``.                      |
-+---------------------------------+------------------------------------------------------------------------------+
-| inout vec4 **COLOR**            | Particle color, can be written to and accessed in mesh's vertex function.    |
-+---------------------------------+------------------------------------------------------------------------------+
-| inout vec3 **VELOCITY**         | Particle velocity, can be modified.                                          |
-+---------------------------------+------------------------------------------------------------------------------+
-| inout mat4 **TRANSFORM**        | Particle transform.                                                          |
-+---------------------------------+------------------------------------------------------------------------------+
-| inout vec4 **CUSTOM**           | Custom particle data. Accessible from shader of mesh as **INSTANCE_CUSTOM**. |
-+---------------------------------+------------------------------------------------------------------------------+
-| out float **MASS**              | Particle mass, use for attractors.                                           |
-+---------------------------------+------------------------------------------------------------------------------+
++------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
+| Built-in                           | Description                                                                                                                             |
++====================================+=========================================================================================================================================+
+| in uint **FLAG_EMIT_POSITION**     | A flag for using on the last argument of ``emit_subparticle`` function to assign a position to a new particle's transform.              |
++------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
+| in uint **FLAG_EMIT_ROT_SCALE**    | A flag for using on the last argument of ``emit_subparticle`` function to assign the rotation and scale to a new particle's transform.  |
++------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
+| in uint **FLAG_EMIT_VELOCITY**     | A flag for using on the last argument of ``emit_subparticle`` function to assign a velocity to a new particle.                          |
++------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
+| in uint **FLAG_EMIT_COLOR**        | A flag for using on the last argument of ``emit_subparticle`` function to assign a color to a new particle.                             |
++------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
+| in uint **FLAG_EMIT_CUSTOM**       | A flag for using on the last argument of ``emit_subparticle`` function to assign a custom data vector to a new particle.                |
++------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
+| in bool **COLLIDED**               | ``true`` when the particle has collided with a particle collider.                                                                       |
++------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
+| in vec3 **COLLISION_NORMAL**       | A normal of the last collision. If there is no collision detected it is equal to ``vec3(0.0)``.                                         |
++------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
+| in float **COLLISION_DEPTH**       | A length of normal of the last collision. If there is no collision detected it is equal to ``0.0``.                                     |
++------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
+| in vec3 **ATTRACTOR_FORCE**        | A combined force of the attractors at the moment on that particle.                                                                      |
++------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
+
+Process functions
+^^^^^^^^^^^^^^^^^
+
++--------------------------------------------------------------------------------------------+-----------------------------------------------+
+| Function                                                                                   | Description                                   |
++============================================================================================+===============================================+
+| bool **emit_subparticle** (mat4 xform, vec3 velocity, vec4 color, vec4 custom, uint flags) | Forces to emit a particle from a sub-emitter. |
++--------------------------------------------------------------------------------------------+-----------------------------------------------+

+ 2 - 2
tutorials/shaders/shader_reference/shading_language.rst

@@ -832,7 +832,7 @@ is used, it can be scalar or vector.
 +---------------------------------------------------------------------------+---------------------------------------------------------------------+
 | vec_type **atan** (vec_type y_over_x)                                     | Arctangent.                                                         |
 +---------------------------------------------------------------------------+---------------------------------------------------------------------+
-| vec_type **atan** (vec_type y, vec_type x)                                | Arctangent to convert vector to angle.                              |
+| vec_type **atan** (vec_type y, vec_type x)                                | Arctangent.                                                         |
 +---------------------------------------------------------------------------+---------------------------------------------------------------------+
 | vec_type **sinh** (vec_type x)                                            | Hyperbolic sine.                                                    |
 +---------------------------------------------------------------------------+---------------------------------------------------------------------+
@@ -846,7 +846,7 @@ is used, it can be scalar or vector.
 +---------------------------------------------------------------------------+---------------------------------------------------------------------+
 | vec_type **atanh** (vec_type x)                                           | Inverse hyperbolic tangent.                                         |
 +---------------------------------------------------------------------------+---------------------------------------------------------------------+
-| vec_type **pow** (vec_type x, vec_type y)                                 | Power (undefined if ``x`` < 0 or if ``x`` = 0 and ``y`` <= 0).      |
+| vec_type **pow** (vec_type x, vec_type y)                                 | Power (undefined if ``x`` < 0 or if ``x`` == 0 and ``y`` <= 0).     |
 +---------------------------------------------------------------------------+---------------------------------------------------------------------+
 | vec_type **exp** (vec_type x)                                             | Base-e exponential.                                                 |
 +---------------------------------------------------------------------------+---------------------------------------------------------------------+

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

@@ -28,24 +28,26 @@ Render modes
 +---------------------------------+-----------------------------------------------------------------------+
 | **depth_draw_never**            | Never draw depth.                                                     |
 +---------------------------------+-----------------------------------------------------------------------+
-| **depth_draw_alpha_prepass**    | Do opaque depth pre-pass for transparent geometry.                    |
+| **depth_prepass_alpha**         | Do opaque depth pre-pass for transparent geometry.                    |
 +---------------------------------+-----------------------------------------------------------------------+
-| **depth_test_disable**          | Disable depth testing.                                                |
+| **depth_test_disabled**         | Disable depth testing.                                                |
 +---------------------------------+-----------------------------------------------------------------------+
-| **cull_front**                  | Cull front-faces.                                                     |
+| **sss_mode_skin**               |                                                                       |
 +---------------------------------+-----------------------------------------------------------------------+
 | **cull_back**                   | Cull back-faces (default).                                            |
 +---------------------------------+-----------------------------------------------------------------------+
+| **cull_front**                  | Cull front-faces.                                                     |
++---------------------------------+-----------------------------------------------------------------------+
 | **cull_disabled**               | Culling disabled (double sided).                                      |
 +---------------------------------+-----------------------------------------------------------------------+
 | **unshaded**                    | Result is just albedo. No lighting/shading happens in material.       |
 +---------------------------------+-----------------------------------------------------------------------+
+| **wireframe**                   | Geometry draws using lines.                                           |
++---------------------------------+-----------------------------------------------------------------------+
 | **diffuse_lambert**             | Lambert shading for diffuse (default).                                |
 +---------------------------------+-----------------------------------------------------------------------+
 | **diffuse_lambert_wrap**        | Lambert wrapping (roughness dependent) for diffuse.                   |
 +---------------------------------+-----------------------------------------------------------------------+
-| **diffuse_oren_nayar**          | Oren Nayar for diffuse.                                               |
-+---------------------------------+-----------------------------------------------------------------------+
 | **diffuse_burley**              | Burley (Disney PBS) for diffuse.                                      |
 +---------------------------------+-----------------------------------------------------------------------+
 | **diffuse_toon**                | Toon shading for diffuse.                                             |
@@ -66,8 +68,6 @@ Render modes
 +---------------------------------+-----------------------------------------------------------------------+
 | **ensure_correct_normals**      | Use when non-uniform scale is applied to mesh.                        |
 +---------------------------------+-----------------------------------------------------------------------+
-| **vertex_lighting**             | Use vertex-based lighting.                                            |
-+---------------------------------+-----------------------------------------------------------------------+
 | **shadows_disabled**            | Disable computing shadows in shader.                                  |
 +---------------------------------+-----------------------------------------------------------------------+
 | **ambient_light_disabled**      | Disable contribution from ambient light and radiance map.             |
@@ -76,6 +76,14 @@ Render modes
 |                                 | non-shadowed areas are transparent. Useful for overlaying shadows onto|
 |                                 | a camera feed in AR.                                                  |
 +---------------------------------+-----------------------------------------------------------------------+
+| **vertex_lighting**             | Use vertex-based lighting.                                            |
++---------------------------------+-----------------------------------------------------------------------+
+| **particle_trails**             | Enables the trails when used on particles geometry.                   |
++---------------------------------+-----------------------------------------------------------------------+
+| **alpha_to_coverage**           |                                                                       |
++---------------------------------+-----------------------------------------------------------------------+
+| **alpha_to_coverage_and_one**   |                                                                       |
++---------------------------------+-----------------------------------------------------------------------+
 
 Built-ins
 ^^^^^^^^^