瀏覽代碼

Updates GLSL reference to contain GDScript types

The typing information was ultimately determined in this file where
Varients are converted and packed:
https://github.com/godotengine/godot/blob/a51ca2beafc5d74d3e62cb56fbba76ceb39160a3/servers/rendering/renderer_rd/storage_rd/material_storage.cpp#L42

The documentation doesn't contain a reference to dealing with how
Packed[Float|Int]Arrays are interpreted, but should be a much better
starting point for new users.
Kenneth Lee 2 年之前
父節點
當前提交
ad1d3072c4
共有 1 個文件被更改,包括 82 次插入20 次删除
  1. 82 20
      tutorials/shaders/shader_reference/shading_language.rst

+ 82 - 20
tutorials/shaders/shader_reference/shading_language.rst

@@ -788,26 +788,88 @@ GDScript uses different variable types than GLSL does, so when passing variables
 from GDScript to shaders, Godot converts the type automatically. Below is a
 table of the corresponding types:
 
-+-----------------+-----------+
-| GDScript type   | GLSL type |
-+=================+===========+
-| **bool**        | **bool**  |
-+-----------------+-----------+
-| **int**         | **int**   |
-+-----------------+-----------+
-| **float**       | **float** |
-+-----------------+-----------+
-| **Vector2**     | **vec2**  |
-+-----------------+-----------+
-| **Vector3**     | **vec3**  |
-+-----------------+-----------+
-| **Color**       | **vec4**  |
-+-----------------+-----------+
-| **Transform3D** | **mat4**  |
-+-----------------+-----------+
-| **Transform2D** | **mat4**  |
-+-----------------+-----------+
-
++----------------------+-------------------------+------------------------------------------------------------+
+| GLSL type            | GDScript type           | Notes                                                      |
++======================+=========================+============================================================+
+| **bool**             | **bool**                |                                                            |
++----------------------+-------------------------+------------------------------------------------------------+
+| **bvec2**            | **int**                 | Bitwise packed int where bit 0 (LSB) corresponds to x.     |
+|                      |                         |                                                            |
+|                      |                         | For example, a bvec2 of (bx, by) could be created in       |
+|                      |                         | the following way:                                         |
+|                      |                         |                                                            |
+|                      |                         | .. code-block:: gdscript                                   |
+|                      |                         |                                                            |
+|                      |                         |   bvec2_input: int = (int(bx)) | (int(by) << 1)            |
+|                      |                         |                                                            |
++----------------------+-------------------------+------------------------------------------------------------+
+| **bvec3**            | **int**                 | Bitwise packed int where bit 0 (LSB) corresponds to x.     |
++----------------------+-------------------------+------------------------------------------------------------+
+| **bvec4**            | **int**                 | Bitwise packed int where bit 0 (LSB) corresponds to x.     |
++----------------------+-------------------------+------------------------------------------------------------+
+| **int**              | **int**                 |                                                            |
++----------------------+-------------------------+------------------------------------------------------------+
+| **ivec2**            | **Vector2i**            |                                                            |
++----------------------+-------------------------+------------------------------------------------------------+
+| **ivec3**            | **Vector3i**            |                                                            |
++----------------------+-------------------------+------------------------------------------------------------+
+| **ivec4**            | **Vector4i**            |                                                            |
++----------------------+-------------------------+------------------------------------------------------------+
+| **uint**             | **int**                 |                                                            |
++----------------------+-------------------------+------------------------------------------------------------+
+| **uvec2**            | **Vector2i**            |                                                            |
++----------------------+-------------------------+------------------------------------------------------------+
+| **uvec3**            | **Vector3i**            |                                                            |
++----------------------+-------------------------+------------------------------------------------------------+
+| **uvec4**            | **Vector4i**            |                                                            |
++----------------------+-------------------------+------------------------------------------------------------+
+| **float**            | **float**               |                                                            |
++----------------------+-------------------------+------------------------------------------------------------+
+| **vec2**             | **Vector2**             |                                                            |
++----------------------+-------------------------+------------------------------------------------------------+
+| **vec3**             | **Vector3**, **Color**  | When Color is used, it will be interpreted as (r, g, b).   |
++----------------------+-------------------------+------------------------------------------------------------+
+| **vec4**             | **Vector4**, **Color**, | When Color is used, it will be interpreted as (r, g, b, a).|
+|                      | **Rect2**, **Plane**,   |                                                            |
+|                      | **Quaternion**          | When Rect2 is used, it will be interpreted as              |
+|                      |                         | (position.x, position.y, size.x, size.y).                  |
+|                      |                         |                                                            |
+|                      |                         | When Plane is used it will be interpreted as               |
+|                      |                         | (normal.x, normal.y, normal.z, d).                         |
+|                      |                         |                                                            |
+|                      |                         |                                                            |
++----------------------+-------------------------+------------------------------------------------------------+
+| **mat2**             | **Transform2D**         |                                                            |
+|                      |                         |                                                            |
++----------------------+-------------------------+------------------------------------------------------------+
+| **mat3**             | **Basis**               |                                                            |
++----------------------+-------------------------+------------------------------------------------------------+
+| **mat4**             | **Projection**,         | When a Transform3D is used, the w Vector is set to the     |
+| **mat4**             | **Transform3D**         | identity.                                                  |
++----------------------+-------------------------+------------------------------------------------------------+
+| **sampler2D**        | **Texture2D**           |                                                            |
++----------------------+-------------------------+------------------------------------------------------------+
+| **isampler2D**       | **Texture2D**           |                                                            |
++----------------------+-------------------------+------------------------------------------------------------+
+| **usampler2D**       | **Texture2D**           |                                                            |
++----------------------+-------------------------+------------------------------------------------------------+
+| **sampler2DArray**   | **Texture2DArray**      |                                                            |
++----------------------+-------------------------+------------------------------------------------------------+
+| **isampler2DArray**  | **Texture2DArray**      |                                                            |
++----------------------+-------------------------+------------------------------------------------------------+
+| **usampler2DArray**  | **Texture2DArray**      |                                                            |
++----------------------+-------------------------+------------------------------------------------------------+
+| **sampler3D**        | **Texture3D**           |                                                            |
++----------------------+-------------------------+------------------------------------------------------------+
+| **isampler3D**       | **Texture3D**           |                                                            |
++----------------------+-------------------------+------------------------------------------------------------+
+| **usampler3D**       | **Texture3D**           |                                                            |
++----------------------+-------------------------+------------------------------------------------------------+
+| **samplerCube**      | **Cubemap**             |                                                            |
++----------------------+-------------------------+------------------------------------------------------------+
+| **samplerCubeArray** | **CubemapArray**        |                                                            |
++----------------------+-------------------------+------------------------------------------------------------+
+ 
 .. note:: Be careful when setting shader uniforms from GDScript, no error will
           be thrown if the type does not match. Your shader will just exhibit
           undefined behavior.