Skip to content

Commit

Permalink
Added note about global shader arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaosus committed Jun 19, 2020
1 parent 91c508d commit b631870
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions tutorials/shading/shading_reference/shading_language.rst
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ Arrays
------

Arrays are containers for multiple variables of a similar type.
Note: As of Godot 3.2, only local and varying arrays have been implemented.
Note: As of Godot 4.0, local, global and varying arrays have been implemented.

Local arrays
~~~~~~~~~~~~

Local arrays are declared in functions. They can use all of the allowed datatypes, except samplers.
The array declaration follows a C-style syntax: ``typename + identifier + [array size]``.
The array declaration follows a C-style syntax: ``[const] + [precision] + typename + identifier + [array size]``.

.. code-block:: glsl
Expand Down Expand Up @@ -252,6 +252,22 @@ Arrays also have a built-in function ``.length()`` (not to be confused with the
Note: If you use an index below 0 or greater than array size - the shader will crash and break rendering. To prevent this, use ``length()``, ``if``, or ``clamp()`` functions to ensure the index is between 0 and the array's length. Always carefully test and check your code. If you pass a constant expression or a simple number, the editor will check its bounds to prevent this crash.

Global arrays
~~~~~~~~~~~~~

You can declare arrays at global space like:

.. code-block:: glsl
shader_type spatial;
const lowp vec3 v[1] = lowp vec3[1] ( vec3(0, 0, 1) );
void fragment() {
ALBEDO = v[0];
}
The only difference in syntax from local shader arrays is the required constness.

Constants
---------

Expand Down

0 comments on commit b631870

Please sign in to comment.