From 67e37b547cf67f57fdd0e95ef18933aada39a05e Mon Sep 17 00:00:00 2001 From: Brian Huynh <51097402+BrianBHuynh@users.noreply.github.com> Date: Thu, 3 Oct 2024 21:30:24 -0400 Subject: [PATCH] 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). --- tutorials/shaders/shader_reference/shading_language.rst | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tutorials/shaders/shader_reference/shading_language.rst b/tutorials/shaders/shader_reference/shading_language.rst index db74e561809..ba2ca01d7c0 100644 --- a/tutorials/shaders/shader_reference/shading_language.rst +++ b/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