瀏覽代碼

Add notes on bit depth for ints and floats (#10028)

* Added notes on bit depth for ints and floats

Added a small note about the bit depth of integers and floats in Godot's shading language as it is not explicitly stated anywhere.

The bit depth of integer and floats in GDscript and Godot's shading language are different, which can cause problems with lost precision in calculations when integers are set from GDscript as floats/ints in GDscript are 64 bits instead of 32 bits (the standard in GLSL ES 3.0).

While most are unlikely to run into problems due to this difference in bit depth, it can cause mathematical errors in edge cases. As stated by previous contributors, no error will be thrown if types do not match while setting a shader uniform. This includes GDscript floats being set as Godot shader floats (which may not be intuitive).
Brian Huynh 9 月之前
父節點
當前提交
67e37b547c
共有 1 個文件被更改,包括 6 次插入3 次删除
  1. 6 3
      tutorials/shaders/shader_reference/shading_language.rst

+ 6 - 3
tutorials/shaders/shader_reference/shading_language.rst

@@ -32,7 +32,7 @@ Most GLSL ES 3.0 datatypes are supported:
 +----------------------+---------------------------------------------------------------------------------+
 | **bvec4**            | Four-component vector of booleans.                                              |
 +----------------------+---------------------------------------------------------------------------------+
-| **int**              | Signed scalar integer.                                                          |
+| **int**              | 32 bit signed scalar integer.                                                   |
 +----------------------+---------------------------------------------------------------------------------+
 | **ivec2**            | Two-component vector of signed integers.                                        |
 +----------------------+---------------------------------------------------------------------------------+
@@ -48,7 +48,7 @@ Most GLSL ES 3.0 datatypes are supported:
 +----------------------+---------------------------------------------------------------------------------+
 | **uvec4**            | Four-component vector of unsigned integers.                                     |
 +----------------------+---------------------------------------------------------------------------------+
-| **float**            | Floating-point scalar.                                                          |
+| **float**            | 32 bit floating-point scalar.                                                   |
 +----------------------+---------------------------------------------------------------------------------+
 | **vec2**             | Two-component vector of floating-point values.                                  |
 +----------------------+---------------------------------------------------------------------------------+
@@ -227,7 +227,7 @@ variables, arguments and varyings:
 
     lowp vec4 a = vec4(0.0, 1.0, 2.0, 3.0); // low precision, usually 8 bits per component mapped to 0-1
     mediump vec4 a = vec4(0.0, 1.0, 2.0, 3.0); // medium precision, usually 16 bits or half float
-    highp vec4 a = vec4(0.0, 1.0, 2.0, 3.0); // high precision, uses full float or integer range (default)
+    highp vec4 a = vec4(0.0, 1.0, 2.0, 3.0); // high precision, uses full float or integer range (32 bit default)
 
 
 Using lower precision for some operations can speed up the math involved (at the
@@ -938,6 +938,9 @@ table of the corresponding types:
           be thrown if the type does not match. Your shader will just exhibit
           undefined behavior.
 
+.. warning::
+    As with the last note, no error will be thrown if the typing does not match while setting a shader uniform, this unintuitively includes setting a (GDscript) 64 bit int/float into a Godot shader language int/float (32 bit). This may lead to unintentional consequences in cases where high precision is required.
+
 Uniforms can also be assigned default values:
 
 .. code-block:: glsl