mirror of
https://github.com/godotengine/godot-docs.git
synced 2026-01-05 22:09:56 +03:00
Merge pull request #11492 from Calinou/shading-language-data-types-array-struct
Clarify array and struct uniforms being supported in Shading language
This commit is contained in:
@@ -91,6 +91,10 @@ Most GLSL ES 3.0 datatypes are supported:
|
|||||||
| | Only supported in Compatibility/Android platform. |
|
| | Only supported in Compatibility/Android platform. |
|
||||||
+------------------------+---------------------------------------------------------------------------------+
|
+------------------------+---------------------------------------------------------------------------------+
|
||||||
|
|
||||||
|
These types can also be put inside :ref:`arrays <doc_shading_language_arrays>`
|
||||||
|
or :ref:`structs <doc_shading_language_structs>`, which are also usable as function parameters
|
||||||
|
or return values. Arrays can be used as uniforms, but structs cannot.
|
||||||
|
|
||||||
.. warning::
|
.. warning::
|
||||||
|
|
||||||
Local variables are not initialized to a default value such as ``0.0``. If
|
Local variables are not initialized to a default value such as ``0.0``. If
|
||||||
@@ -202,7 +206,7 @@ rules:
|
|||||||
|
|
||||||
1. If a larger matrix is constructed from a smaller matrix, the additional rows
|
1. If a larger matrix is constructed from a smaller matrix, the additional rows
|
||||||
and columns are set to the values they would have in an identity matrix.
|
and columns are set to the values they would have in an identity matrix.
|
||||||
2. If a smaller matrix is constructed from a larger matrix, the top, left
|
1. If a smaller matrix is constructed from a larger matrix, the top, left
|
||||||
submatrix of the larger matrix is used.
|
submatrix of the larger matrix is used.
|
||||||
|
|
||||||
.. code-block:: glsl
|
.. code-block:: glsl
|
||||||
@@ -255,6 +259,8 @@ precisions. Refer to the documentation of the target architecture for further
|
|||||||
information. In many cases, mobile drivers cause inconsistent or unexpected
|
information. In many cases, mobile drivers cause inconsistent or unexpected
|
||||||
behavior and it is best to avoid specifying precision unless necessary.
|
behavior and it is best to avoid specifying precision unless necessary.
|
||||||
|
|
||||||
|
.. _doc_shading_language_arrays:
|
||||||
|
|
||||||
Arrays
|
Arrays
|
||||||
------
|
------
|
||||||
|
|
||||||
@@ -411,6 +417,8 @@ Alternatively, this can be done by using the ``uint(x)`` built-in conversion fun
|
|||||||
uint a = 1u;
|
uint a = 1u;
|
||||||
uint b = uint(1);
|
uint b = uint(1);
|
||||||
|
|
||||||
|
.. _doc_shading_language_structs:
|
||||||
|
|
||||||
Structs
|
Structs
|
||||||
-------
|
-------
|
||||||
|
|
||||||
@@ -1104,23 +1112,23 @@ method on a node that inherits from :ref:`class_GeometryInstance3D`:
|
|||||||
|
|
||||||
When using per-instance uniforms, there are some restrictions you should be aware of:
|
When using per-instance uniforms, there are some restrictions you should be aware of:
|
||||||
|
|
||||||
- **Per-instance uniforms do not support textures or arrays**, only regular scalar and vector types.
|
- **Per-instance uniforms do not support textures or arrays**, only regular scalar and vector types.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
Due to GLSL limitations, you cannot directly index a texture array
|
Due to GLSL limitations, you cannot directly index a texture array
|
||||||
using a per-instance uniform. Sampler arrays can only be indexed by
|
using a per-instance uniform. Sampler arrays can only be indexed by
|
||||||
compile-time constant expressions.
|
compile-time constant expressions.
|
||||||
|
|
||||||
As a workaround, pass a texture array as a regular uniform and the
|
As a workaround, pass a texture array as a regular uniform and the
|
||||||
desired texture index as a per-instance uniform. Then use a ``switch``
|
desired texture index as a per-instance uniform. Then use a ``switch``
|
||||||
statement to select the texture:
|
statement to select the texture:
|
||||||
|
|
||||||
.. code-block:: glsl
|
.. code-block:: glsl
|
||||||
|
|
||||||
uniform sampler2D texture_array[4];
|
uniform sampler2D texture_array[4];
|
||||||
instance uniform int texture_index;
|
instance uniform int texture_index;
|
||||||
|
|
||||||
void fragment() {
|
void fragment() {
|
||||||
vec4 color;
|
vec4 color;
|
||||||
switch (texture_index) {
|
switch (texture_index) {
|
||||||
@@ -1137,7 +1145,7 @@ When using per-instance uniforms, there are some restrictions you should be awar
|
|||||||
color = texture(texture_array[3], UV);
|
color = texture(texture_array[3], UV);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
COLOR = color;
|
COLOR = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user