shading_language.rst 102 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492
  1. .. _doc_shading_language:
  2. Shading language
  3. ================
  4. Introduction
  5. ------------
  6. Godot uses a shading language similar to GLSL ES 3.0. Most datatypes and
  7. functions are supported, and the few remaining ones will likely be added over
  8. time.
  9. If you are already familiar with GLSL, the :ref:`Godot Shader Migration
  10. Guide<doc_converting_glsl_to_godot_shaders>` is a resource that will help you
  11. transition from regular GLSL to Godot's shading language.
  12. Data types
  13. ----------
  14. Most GLSL ES 3.0 datatypes are supported:
  15. +----------------------+---------------------------------------------------------------------------------+
  16. | Type | Description |
  17. +======================+=================================================================================+
  18. | **void** | Void datatype, useful only for functions that return nothing. |
  19. +----------------------+---------------------------------------------------------------------------------+
  20. | **bool** | Boolean datatype, can only contain ``true`` or ``false``. |
  21. +----------------------+---------------------------------------------------------------------------------+
  22. | **bvec2** | Two-component vector of booleans. |
  23. +----------------------+---------------------------------------------------------------------------------+
  24. | **bvec3** | Three-component vector of booleans. |
  25. +----------------------+---------------------------------------------------------------------------------+
  26. | **bvec4** | Four-component vector of booleans. |
  27. +----------------------+---------------------------------------------------------------------------------+
  28. | **int** | Signed scalar integer. |
  29. +----------------------+---------------------------------------------------------------------------------+
  30. | **ivec2** | Two-component vector of signed integers. |
  31. +----------------------+---------------------------------------------------------------------------------+
  32. | **ivec3** | Three-component vector of signed integers. |
  33. +----------------------+---------------------------------------------------------------------------------+
  34. | **ivec4** | Four-component vector of signed integers. |
  35. +----------------------+---------------------------------------------------------------------------------+
  36. | **uint** | Unsigned scalar integer; can't contain negative numbers. |
  37. +----------------------+---------------------------------------------------------------------------------+
  38. | **uvec2** | Two-component vector of unsigned integers. |
  39. +----------------------+---------------------------------------------------------------------------------+
  40. | **uvec3** | Three-component vector of unsigned integers. |
  41. +----------------------+---------------------------------------------------------------------------------+
  42. | **uvec4** | Four-component vector of unsigned integers. |
  43. +----------------------+---------------------------------------------------------------------------------+
  44. | **float** | Floating-point scalar. |
  45. +----------------------+---------------------------------------------------------------------------------+
  46. | **vec2** | Two-component vector of floating-point values. |
  47. +----------------------+---------------------------------------------------------------------------------+
  48. | **vec3** | Three-component vector of floating-point values. |
  49. +----------------------+---------------------------------------------------------------------------------+
  50. | **vec4** | Four-component vector of floating-point values. |
  51. +----------------------+---------------------------------------------------------------------------------+
  52. | **mat2** | 2x2 matrix, in column major order. |
  53. +----------------------+---------------------------------------------------------------------------------+
  54. | **mat3** | 3x3 matrix, in column major order. |
  55. +----------------------+---------------------------------------------------------------------------------+
  56. | **mat4** | 4x4 matrix, in column major order. |
  57. +----------------------+---------------------------------------------------------------------------------+
  58. | **sampler2D** | Sampler type for binding 2D textures, which are read as float. |
  59. +----------------------+---------------------------------------------------------------------------------+
  60. | **isampler2D** | Sampler type for binding 2D textures, which are read as signed integer. |
  61. +----------------------+---------------------------------------------------------------------------------+
  62. | **usampler2D** | Sampler type for binding 2D textures, which are read as unsigned integer. |
  63. +----------------------+---------------------------------------------------------------------------------+
  64. | **sampler2DArray** | Sampler type for binding 2D texture arrays, which are read as float. |
  65. +----------------------+---------------------------------------------------------------------------------+
  66. | **isampler2DArray** | Sampler type for binding 2D texture arrays, which are read as signed integer. |
  67. +----------------------+---------------------------------------------------------------------------------+
  68. | **usampler2DArray** | Sampler type for binding 2D texture arrays, which are read as unsigned integer. |
  69. +----------------------+---------------------------------------------------------------------------------+
  70. | **sampler3D** | Sampler type for binding 3D textures, which are read as float. |
  71. +----------------------+---------------------------------------------------------------------------------+
  72. | **isampler3D** | Sampler type for binding 3D textures, which are read as signed integer. |
  73. +----------------------+---------------------------------------------------------------------------------+
  74. | **usampler3D** | Sampler type for binding 3D textures, which are read as unsigned integer. |
  75. +----------------------+---------------------------------------------------------------------------------+
  76. | **samplerCube** | Sampler type for binding Cubemaps, which are read as float. |
  77. +----------------------+---------------------------------------------------------------------------------+
  78. | **samplerCubeArray** | Sampler type for binding Cubemap arrays, which are read as float. |
  79. +----------------------+---------------------------------------------------------------------------------+
  80. Comments
  81. ~~~~~~~~
  82. The shading language supports the same comment syntax as used in C# and C++:
  83. .. code-block:: glsl
  84. // Single-line comment.
  85. int a = 2; // Another single-line comment.
  86. /*
  87. Multi-line comment.
  88. The comment ends when the ending delimiter is found
  89. (here, it's on the line below).
  90. */
  91. int b = 3;
  92. Additionally, you can use documentation comments that are displayed in the
  93. inspector when hovering a shader parameter. Documentation comments are currently
  94. only supported when placed immediately above a ``uniform`` declaration. These
  95. documentation comments only support the **multiline** comment syntax and must use
  96. **two** leading asterisks (``/**``) instead of just one (``/*``):
  97. .. code-block:: glsl
  98. /**
  99. * This is a documentation comment.
  100. * These lines will appear in the inspector when hovering the shader parameter
  101. * named "Something".
  102. * You can use [b]BBCode[/b] [i]formatting[/i] in the comment.
  103. */
  104. uniform int something = 1;
  105. The asterisks on the follow-up lines are not required, but are recommended as
  106. per the :ref:`doc_shaders_style_guide`. These asterisks are automatically
  107. stripped by the inspector, so they won't appear in the tooltip.
  108. Casting
  109. ~~~~~~~
  110. Just like GLSL ES 3.0, implicit casting between scalars and vectors of the same
  111. size but different type is not allowed. Casting of types of different size is
  112. also not allowed. Conversion must be done explicitly via constructors.
  113. Example:
  114. .. code-block:: glsl
  115. float a = 2; // invalid
  116. float a = 2.0; // valid
  117. float a = float(2); // valid
  118. Default integer constants are signed, so casting is always needed to convert to
  119. unsigned:
  120. .. code-block:: glsl
  121. int a = 2; // valid
  122. uint a = 2; // invalid
  123. uint a = uint(2); // valid
  124. Members
  125. ~~~~~~~
  126. Individual scalar members of vector types are accessed via the "x", "y", "z" and
  127. "w" members. Alternatively, using "r", "g", "b" and "a" also works and is
  128. equivalent. Use whatever fits best for your needs.
  129. For matrices, use the ``m[column][row]`` indexing syntax to access each scalar,
  130. or ``m[idx]`` to access a vector by row index. For example, for accessing the y
  131. position of an object in a mat4 you use ``m[3][1]``.
  132. Constructing
  133. ~~~~~~~~~~~~
  134. Construction of vector types must always pass:
  135. .. code-block:: glsl
  136. // The required amount of scalars
  137. vec4 a = vec4(0.0, 1.0, 2.0, 3.0);
  138. // Complementary vectors and/or scalars
  139. vec4 a = vec4(vec2(0.0, 1.0), vec2(2.0, 3.0));
  140. vec4 a = vec4(vec3(0.0, 1.0, 2.0), 3.0);
  141. // A single scalar for the whole vector
  142. vec4 a = vec4(0.0);
  143. Construction of matrix types requires vectors of the same dimension as the
  144. matrix. You can also build a diagonal matrix using ``matx(float)`` syntax.
  145. Accordingly, ``mat4(1.0)`` is an identity matrix.
  146. .. code-block:: glsl
  147. mat2 m2 = mat2(vec2(1.0, 0.0), vec2(0.0, 1.0));
  148. mat3 m3 = mat3(vec3(1.0, 0.0, 0.0), vec3(0.0, 1.0, 0.0), vec3(0.0, 0.0, 1.0));
  149. mat4 identity = mat4(1.0);
  150. Matrices can also be built from a matrix of another dimension. There are two
  151. rules:
  152. 1. If a larger matrix is constructed from a smaller matrix, the additional rows
  153. and columns are set to the values they would have in an identity matrix.
  154. 2. If a smaller matrix is constructed from a larger matrix, the top, left
  155. submatrix of the larger matrix is used.
  156. .. code-block:: glsl
  157. mat3 basis = mat3(MODEL_MATRIX);
  158. mat4 m4 = mat4(basis);
  159. mat2 m2 = mat2(m4);
  160. Swizzling
  161. ~~~~~~~~~
  162. It is possible to obtain any combination of components in any order, as long as
  163. the result is another vector type (or scalar). This is easier shown than
  164. explained:
  165. .. code-block:: glsl
  166. vec4 a = vec4(0.0, 1.0, 2.0, 3.0);
  167. vec3 b = a.rgb; // Creates a vec3 with vec4 components.
  168. vec3 b = a.ggg; // Also valid; creates a vec3 and fills it with a single vec4 component.
  169. vec3 b = a.bgr; // "b" will be vec3(2.0, 1.0, 0.0).
  170. vec3 b = a.xyz; // Also rgba, xyzw are equivalent.
  171. vec3 b = a.stp; // And stpq (for texture coordinates).
  172. float c = b.w; // Invalid, because "w" is not present in vec3 b.
  173. vec3 c = b.xrt; // Invalid, mixing different styles is forbidden.
  174. b.rrr = a.rgb; // Invalid, assignment with duplication.
  175. b.bgr = a.rgb; // Valid assignment. "b"'s "blue" component will be "a"'s "red" and vice versa.
  176. Precision
  177. ~~~~~~~~~
  178. It is possible to add precision modifiers to datatypes; use them for uniforms,
  179. variables, arguments and varyings:
  180. .. code-block:: glsl
  181. lowp vec4 a = vec4(0.0, 1.0, 2.0, 3.0); // low precision, usually 8 bits per component mapped to 0-1
  182. mediump vec4 a = vec4(0.0, 1.0, 2.0, 3.0); // medium precision, usually 16 bits or half float
  183. highp vec4 a = vec4(0.0, 1.0, 2.0, 3.0); // high precision, uses full float or integer range (default)
  184. Using lower precision for some operations can speed up the math involved (at the
  185. cost of less precision). This is rarely needed in the vertex processor function
  186. (where full precision is needed most of the time), but is often useful in the
  187. fragment processor.
  188. Some architectures (mainly mobile) can benefit significantly from this, but
  189. there are downsides such as the additional overhead of conversion between
  190. precisions. Refer to the documentation of the target architecture for further
  191. information. In many cases, mobile drivers cause inconsistent or unexpected
  192. behavior and it is best to avoid specifying precision unless necessary.
  193. Arrays
  194. ------
  195. Arrays are containers for multiple variables of a similar type.
  196. Local arrays
  197. ~~~~~~~~~~~~
  198. Local arrays are declared in functions. They can use all of the allowed
  199. datatypes, except samplers. The array declaration follows a C-style syntax:
  200. ``[const] + [precision] + typename + identifier + [array size]``.
  201. .. code-block:: glsl
  202. void fragment() {
  203. float arr[3];
  204. }
  205. They can be initialized at the beginning like:
  206. .. code-block:: glsl
  207. float float_arr[3] = float[3] (1.0, 0.5, 0.0); // first constructor
  208. int int_arr[3] = int[] (2, 1, 0); // second constructor
  209. vec2 vec2_arr[3] = { vec2(1.0, 1.0), vec2(0.5, 0.5), vec2(0.0, 0.0) }; // third constructor
  210. bool bool_arr[] = { true, true, false }; // fourth constructor - size is defined automatically from the element count
  211. You can declare multiple arrays (even with different sizes) in one expression:
  212. .. code-block:: glsl
  213. float a[3] = float[3] (1.0, 0.5, 0.0),
  214. b[2] = { 1.0, 0.5 },
  215. c[] = { 0.7 },
  216. d = 0.0,
  217. e[5];
  218. To access an array element, use the indexing syntax:
  219. .. code-block:: glsl
  220. float arr[3];
  221. arr[0] = 1.0; // setter
  222. COLOR.r = arr[0]; // getter
  223. Arrays also have a built-in function ``.length()`` (not to be confused with the
  224. built-in ``length()`` function). It doesn't accept any parameters and will
  225. return the array's size.
  226. .. code-block:: glsl
  227. float arr[] = { 0.0, 1.0, 0.5, -1.0 };
  228. for (int i = 0; i < arr.length(); i++) {
  229. // ...
  230. }
  231. .. note::
  232. If you use an index either below 0 or greater than array size - the shader will
  233. crash and break rendering. To prevent this, use ``length()``, ``if``, or
  234. ``clamp()`` functions to ensure the index is between 0 and the array's
  235. length. Always carefully test and check your code. If you pass a constant
  236. expression or a number, the editor will check its bounds to prevent
  237. this crash.
  238. Global arrays
  239. ~~~~~~~~~~~~~
  240. You can declare arrays at global space like:
  241. .. code-block:: glsl
  242. shader_type spatial;
  243. const lowp vec3 v[1] = lowp vec3[1] ( vec3(0, 0, 1) );
  244. void fragment() {
  245. ALBEDO = v[0];
  246. }
  247. .. note::
  248. Global arrays have to be declared as global constants, otherwise they can be
  249. declared the same as local arrays.
  250. Constants
  251. ---------
  252. Use the ``const`` keyword before the variable declaration to make that variable
  253. immutable, which means that it cannot be modified. All basic types, except
  254. samplers can be declared as constants. Accessing and using a constant value is
  255. slightly faster than using a uniform. Constants must be initialized at their
  256. declaration.
  257. .. code-block:: glsl
  258. const vec2 a = vec2(0.0, 1.0);
  259. vec2 b;
  260. a = b; // invalid
  261. b = a; // valid
  262. Constants cannot be modified and additionally cannot have hints, but multiple of
  263. them (if they have the same type) can be declared in a single expression e.g
  264. .. code-block:: glsl
  265. const vec2 V1 = vec2(1, 1), V2 = vec2(2, 2);
  266. Similar to variables, arrays can also be declared with ``const``.
  267. .. code-block:: glsl
  268. const float arr[] = { 1.0, 0.5, 0.0 };
  269. arr[0] = 1.0; // invalid
  270. COLOR.r = arr[0]; // valid
  271. Constants can be declared both globally (outside of any function) or locally
  272. (inside a function). Global constants are useful when you want to have access to
  273. a value throughout your shader that does not need to be modified. Like uniforms,
  274. global constants are shared between all shader stages, but they are not
  275. accessible outside of the shader.
  276. .. code-block:: glsl
  277. shader_type spatial;
  278. const float PI = 3.14159265358979323846;
  279. Constants of the ``float`` type must be initialized using ``.`` notation after the
  280. decimal part or by using the scientific notation. The optional ``f`` post-suffix is
  281. also supported.
  282. .. code-block:: glsl
  283. float a = 1.0;
  284. float b = 1.0f; // same, using suffix for clarity
  285. float c = 1e-1; // gives 0.1 by using the scientific notation
  286. Constants of the ``uint`` (unsigned int) type must have a ``u`` suffix to differentiate them from signed integers.
  287. Alternatively, this can be done by using the ``uint(x)`` built-in conversion function.
  288. .. code-block:: glsl
  289. uint a = 1u;
  290. uint b = uint(1);
  291. Structs
  292. -------
  293. Structs are compound types which can be used for better abstraction of shader
  294. code. You can declare them at the global scope like:
  295. .. code-block:: glsl
  296. struct PointLight {
  297. vec3 position;
  298. vec3 color;
  299. float intensity;
  300. };
  301. After declaration, you can instantiate and initialize them like:
  302. .. code-block:: glsl
  303. void fragment()
  304. {
  305. PointLight light;
  306. light.position = vec3(0.0);
  307. light.color = vec3(1.0, 0.0, 0.0);
  308. light.intensity = 0.5;
  309. }
  310. Or use struct constructor for same purpose:
  311. .. code-block:: glsl
  312. PointLight light = PointLight(vec3(0.0), vec3(1.0, 0.0, 0.0), 0.5);
  313. Structs may contain other struct or array, you can also instance them as global
  314. constant:
  315. .. code-block:: glsl
  316. shader_type spatial;
  317. ...
  318. struct Scene {
  319. PointLight lights[2];
  320. };
  321. const Scene scene = Scene(PointLight[2](PointLight(vec3(0.0, 0.0, 0.0), vec3(1.0, 0.0, 0.0), 1.0), PointLight(vec3(0.0, 0.0, 0.0), vec3(1.0, 0.0, 0.0), 1.0)));
  322. void fragment()
  323. {
  324. ALBEDO = scene.lights[0].color;
  325. }
  326. You can also pass them to functions:
  327. .. code-block:: glsl
  328. shader_type canvas_item;
  329. ...
  330. Scene construct_scene(PointLight light1, PointLight light2) {
  331. return Scene({light1, light2});
  332. }
  333. void fragment()
  334. {
  335. COLOR.rgb = construct_scene(PointLight(vec3(0.0, 0.0, 0.0), vec3(1.0, 0.0, 0.0), 1.0), PointLight(vec3(0.0, 0.0, 0.0), vec3(1.0, 0.0, 1.0), 1.0)).lights[0].color;
  336. }
  337. Operators
  338. ---------
  339. Godot shading language supports the same set of operators as GLSL ES 3.0. Below
  340. is the list of them in precedence order:
  341. +-------------+------------------------+------------------+
  342. | Precedence | Class | Operator |
  343. +-------------+------------------------+------------------+
  344. | 1 (highest) | parenthetical grouping | **()** |
  345. +-------------+------------------------+------------------+
  346. | 2 | unary | **+, -, !, ~** |
  347. +-------------+------------------------+------------------+
  348. | 3 | multiplicative | **/, \*, %** |
  349. +-------------+------------------------+------------------+
  350. | 4 | additive | **+, -** |
  351. +-------------+------------------------+------------------+
  352. | 5 | bit-wise shift | **<<, >>** |
  353. +-------------+------------------------+------------------+
  354. | 6 | relational | **<, >, <=, >=** |
  355. +-------------+------------------------+------------------+
  356. | 7 | equality | **==, !=** |
  357. +-------------+------------------------+------------------+
  358. | 8 | bit-wise AND | **&** |
  359. +-------------+------------------------+------------------+
  360. | 9 | bit-wise exclusive OR | **^** |
  361. +-------------+------------------------+------------------+
  362. | 10 | bit-wise inclusive OR | **|** |
  363. +-------------+------------------------+------------------+
  364. | 11 | logical AND | **&&** |
  365. +-------------+------------------------+------------------+
  366. | 12 (lowest) | logical inclusive OR | **||** |
  367. +-------------+------------------------+------------------+
  368. Flow control
  369. ------------
  370. Godot Shading language supports the most common types of flow control:
  371. .. code-block:: glsl
  372. // `if` and `else`.
  373. if (cond) {
  374. } else {
  375. }
  376. // Ternary operator.
  377. // This is an expression that behaves like `if`/`else` and returns the value.
  378. // If `cond` evaluates to `true`, `result` will be `9`.
  379. // Otherwise, `result` will be `5`.
  380. int result = cond ? 9 : 5;
  381. // `switch`.
  382. switch (i) { // `i` should be a signed integer expression.
  383. case -1:
  384. break;
  385. case 0:
  386. return; // `break` or `return` to avoid running the next `case`.
  387. case 1: // Fallthrough (no `break` or `return`): will run the next `case`.
  388. case 2:
  389. break;
  390. //...
  391. default: // Only run if no `case` above matches. Optional.
  392. break;
  393. }
  394. // `for` loop. Best used when the number of elements to iterate on
  395. // is known in advance.
  396. for (int i = 0; i < 10; i++) {
  397. }
  398. // `while` loop. Best used when the number of elements to iterate on
  399. // is not known in advance.
  400. while (cond) {
  401. }
  402. // `do while`. Like `while`, but always runs at least once even if `cond`
  403. // never evaluates to `true`.
  404. do {
  405. } while (cond);
  406. Keep in mind that in modern GPUs, an infinite loop can exist and can freeze
  407. your application (including editor). Godot can't protect you from this, so be
  408. careful not to make this mistake!
  409. Also, when comparing floating-point values against a number, make sure to
  410. compare them against a *range* instead of an exact number.
  411. A comparison like ``if (value == 0.3)`` may not evaluate to ``true``.
  412. Floating-point math is often approximate and can defy expectations. It can also
  413. behave differently depending on the hardware.
  414. **Don't** do this.
  415. .. code-block:: glsl
  416. float value = 0.1 + 0.2;
  417. // May not evaluate to `true`!
  418. if (value == 0.3) {
  419. // ...
  420. }
  421. Instead, always perform a range comparison with an epsilon value. The larger the
  422. floating-point number (and the less precise the floating-point number), the
  423. larger the epsilon value should be.
  424. .. code-block:: glsl
  425. const float EPSILON = 0.0001;
  426. if (value >= 0.3 - EPSILON && value <= 0.3 + EPSILON) {
  427. // ...
  428. }
  429. See `floating-point-gui.de <https://floating-point-gui.de/>`__ for more
  430. information.
  431. Discarding
  432. ----------
  433. Fragment and light functions can use the ``discard`` keyword. If used, the
  434. fragment is discarded and nothing is written.
  435. Beware that ``discard`` has a performance cost when used, as it will prevent the
  436. depth prepass from being effective on any surfaces using the shader. Also, a
  437. discarded pixel still needs to be rendered in the vertex shader, which means a
  438. shader that uses ``discard`` on all of its pixels is still more expensive to
  439. render compared to not rendering any object in the first place.
  440. Functions
  441. ---------
  442. It is possible to define functions in a Godot shader. They use the following
  443. syntax:
  444. .. code-block:: glsl
  445. ret_type func_name(args) {
  446. return ret_type; // if returning a value
  447. }
  448. // a more specific example:
  449. int sum2(int a, int b) {
  450. return a + b;
  451. }
  452. You can only use functions that have been defined above (higher in the editor)
  453. the function from which you are calling them. Redefining a function that has
  454. already been defined above (or is a built-in function name) will cause an error.
  455. Function arguments can have special qualifiers:
  456. * **in**: Means the argument is only for reading (default).
  457. * **out**: Means the argument is only for writing.
  458. * **inout**: Means the argument is fully passed via reference.
  459. * **const**: Means the argument is a constant and cannot be changed, may be
  460. combined with **in** qualifier.
  461. Example below:
  462. .. code-block:: glsl
  463. void sum2(int a, int b, inout int result) {
  464. result = a + b;
  465. }
  466. .. note::
  467. Unlike GLSL, Godot's shader language does **not** support function
  468. overloading. This means that a function cannot be defined several times with
  469. different argument types or numbers of arguments. As a workaround, use
  470. different names for functions that accept a different number of arguments or
  471. arguments of different types.
  472. Varyings
  473. --------
  474. To send data from the vertex to the fragment (or light) processor function, *varyings* are
  475. used. They are set for every primitive vertex in the *vertex processor*, and the
  476. value is interpolated for every pixel in the *fragment processor*.
  477. .. code-block:: glsl
  478. shader_type spatial;
  479. varying vec3 some_color;
  480. void vertex() {
  481. some_color = NORMAL; // Make the normal the color.
  482. }
  483. void fragment() {
  484. ALBEDO = some_color;
  485. }
  486. void light() {
  487. DIFFUSE_LIGHT = some_color * 100; // optionally
  488. }
  489. Varying can also be an array:
  490. .. code-block:: glsl
  491. shader_type spatial;
  492. varying float var_arr[3];
  493. void vertex() {
  494. var_arr[0] = 1.0;
  495. var_arr[1] = 0.0;
  496. }
  497. void fragment() {
  498. ALBEDO = vec3(var_arr[0], var_arr[1], var_arr[2]); // red color
  499. }
  500. It's also possible to send data from *fragment* to *light* processors using *varying* keyword. To do so you can assign it in the *fragment* and later use it in the *light* function.
  501. .. code-block:: glsl
  502. shader_type spatial;
  503. varying vec3 some_light;
  504. void fragment() {
  505. some_light = ALBEDO * 100.0; // Make a shining light.
  506. }
  507. void light() {
  508. DIFFUSE_LIGHT = some_light;
  509. }
  510. Note that varying may not be assigned in custom functions or a *light processor* function like:
  511. .. code-block:: glsl
  512. shader_type spatial;
  513. varying float test;
  514. void foo() {
  515. test = 0.0; // Error.
  516. }
  517. void vertex() {
  518. test = 0.0;
  519. }
  520. void light() {
  521. test = 0.0; // Error too.
  522. }
  523. This limitation was introduced to prevent incorrect usage before initialization.
  524. Interpolation qualifiers
  525. ------------------------
  526. Certain values are interpolated during the shading pipeline. You can modify how
  527. these interpolations are done by using *interpolation qualifiers*.
  528. .. code-block:: glsl
  529. shader_type spatial;
  530. varying flat vec3 our_color;
  531. void vertex() {
  532. our_color = COLOR.rgb;
  533. }
  534. void fragment() {
  535. ALBEDO = our_color;
  536. }
  537. There are two possible interpolation qualifiers:
  538. +-------------------+---------------------------------------------------------------------------------+
  539. | Qualifier | Description |
  540. +===================+=================================================================================+
  541. | **flat** | The value is not interpolated. |
  542. +-------------------+---------------------------------------------------------------------------------+
  543. | **smooth** | The value is interpolated in a perspective-correct fashion. This is the default.|
  544. +-------------------+---------------------------------------------------------------------------------+
  545. Uniforms
  546. --------
  547. Passing values to shaders is possible. These are global to the whole shader and
  548. are called *uniforms*. When a shader is later assigned to a material, the
  549. uniforms will appear as editable parameters in it. Uniforms can't be written
  550. from within the shader.
  551. .. code-block:: glsl
  552. shader_type spatial;
  553. uniform float some_value;
  554. uniform vec3 colors[3];
  555. You can set uniforms in the editor in the material. Or you can set them through
  556. GDScript:
  557. .. code-block:: gdscript
  558. material.set_shader_parameter("some_value", some_value)
  559. material.set_shader_parameter("colors", [Vector3(1, 0, 0), Vector3(0, 1, 0), Vector3(0, 0, 1)])
  560. .. note:: The first argument to ``set_shader_parameter`` is the name of the uniform
  561. in the shader. It must match *exactly* to the name of the uniform in
  562. the shader or else it will not be recognized.
  563. Any GLSL type except for *void* can be a uniform. Additionally, Godot provides
  564. optional shader hints to make the compiler understand for what the uniform is
  565. used, and how the editor should allow users to modify it.
  566. .. code-block:: glsl
  567. shader_type spatial;
  568. uniform vec4 color : source_color;
  569. uniform float amount : hint_range(0, 1);
  570. uniform vec4 other_color : source_color = vec4(1.0); // Default values go after the hint.
  571. uniform sampler2D image : source_color;
  572. It's important to understand that textures *that are supplied as color* require
  573. hints for proper sRGB -> linear conversion (i.e. ``source_color``), as Godot's
  574. 3D engine renders in linear color space. If this is not done, the texture will
  575. appear washed out.
  576. .. note::
  577. The 2D renderer also renders in linear color space if the
  578. **Rendering > Viewport > HDR 2D** project setting is enabled, so
  579. ``source_color`` must also be used in ``canvas_item`` shaders. If 2D HDR is
  580. disabled, ``source_color`` will keep working correctly in ``canvas_item``
  581. shaders, so it's recommend to use it either way.
  582. Full list of hints below:
  583. +----------------------+--------------------------------------------------+-----------------------------------------------------------------------------+
  584. | Type | Hint | Description |
  585. +======================+==================================================+=============================================================================+
  586. | **vec3, vec4** | source_color | Used as color. |
  587. +----------------------+--------------------------------------------------+-----------------------------------------------------------------------------+
  588. | **int, float** | hint_range(min, max[, step]) | Restricted to values in a range (with min/max/step). |
  589. +----------------------+--------------------------------------------------+-----------------------------------------------------------------------------+
  590. | **sampler2D** | source_color | Used as albedo color. |
  591. +----------------------+--------------------------------------------------+-----------------------------------------------------------------------------+
  592. | **sampler2D** | hint_normal | Used as normalmap. |
  593. +----------------------+--------------------------------------------------+-----------------------------------------------------------------------------+
  594. | **sampler2D** | hint_default_white | As value or albedo color, default to opaque white. |
  595. +----------------------+--------------------------------------------------+-----------------------------------------------------------------------------+
  596. | **sampler2D** | hint_default_black | As value or albedo color, default to opaque black. |
  597. +----------------------+--------------------------------------------------+-----------------------------------------------------------------------------+
  598. | **sampler2D** | hint_default_transparent | As value or albedo color, default to transparent black. |
  599. +----------------------+--------------------------------------------------+-----------------------------------------------------------------------------+
  600. | **sampler2D** | hint_anisotropy | As flowmap, default to right. |
  601. +----------------------+--------------------------------------------------+-----------------------------------------------------------------------------+
  602. | **sampler2D** | hint_roughness[_r, _g, _b, _a, _normal, _gray] | Used for roughness limiter on import (attempts reducing specular aliasing). |
  603. | | | ``_normal`` is a normal map that guides the roughness limiter, |
  604. | | | with roughness increasing in areas that have high-frequency detail. |
  605. +----------------------+--------------------------------------------------+-----------------------------------------------------------------------------+
  606. | **sampler2D** | filter[_nearest, _linear][_mipmap][_anisotropic] | Enabled specified texture filtering. |
  607. +----------------------+--------------------------------------------------+-----------------------------------------------------------------------------+
  608. | **sampler2D** | repeat[_enable, _disable] | Enabled texture repeating. |
  609. +----------------------+--------------------------------------------------+-----------------------------------------------------------------------------+
  610. | **sampler2D** | hint_screen_texture | Texture is the screen texture. |
  611. +----------------------+--------------------------------------------------+-----------------------------------------------------------------------------+
  612. | **sampler2D** | hint_depth_texture | Texture is the depth texture. |
  613. +----------------------+--------------------------------------------------+-----------------------------------------------------------------------------+
  614. | **sampler2D** | hint_normal_roughness_texture | Texture is the normal roughness texture (only supported in Forward+). |
  615. +----------------------+--------------------------------------------------+-----------------------------------------------------------------------------+
  616. GDScript uses different variable types than GLSL does, so when passing variables
  617. from GDScript to shaders, Godot converts the type automatically. Below is a
  618. table of the corresponding types:
  619. +----------------------+-------------------------+------------------------------------------------------------+
  620. | GLSL type | GDScript type | Notes |
  621. +======================+=========================+============================================================+
  622. | **bool** | **bool** | |
  623. +----------------------+-------------------------+------------------------------------------------------------+
  624. | **bvec2** | **int** | Bitwise packed int where bit 0 (LSB) corresponds to x. |
  625. | | | |
  626. | | | For example, a bvec2 of (bx, by) could be created in |
  627. | | | the following way: |
  628. | | | |
  629. | | | .. code-block:: gdscript |
  630. | | | |
  631. | | | bvec2_input: int = (int(bx)) | (int(by) << 1) |
  632. | | | |
  633. +----------------------+-------------------------+------------------------------------------------------------+
  634. | **bvec3** | **int** | Bitwise packed int where bit 0 (LSB) corresponds to x. |
  635. +----------------------+-------------------------+------------------------------------------------------------+
  636. | **bvec4** | **int** | Bitwise packed int where bit 0 (LSB) corresponds to x. |
  637. +----------------------+-------------------------+------------------------------------------------------------+
  638. | **int** | **int** | |
  639. +----------------------+-------------------------+------------------------------------------------------------+
  640. | **ivec2** | **Vector2i** | |
  641. +----------------------+-------------------------+------------------------------------------------------------+
  642. | **ivec3** | **Vector3i** | |
  643. +----------------------+-------------------------+------------------------------------------------------------+
  644. | **ivec4** | **Vector4i** | |
  645. +----------------------+-------------------------+------------------------------------------------------------+
  646. | **uint** | **int** | |
  647. +----------------------+-------------------------+------------------------------------------------------------+
  648. | **uvec2** | **Vector2i** | |
  649. +----------------------+-------------------------+------------------------------------------------------------+
  650. | **uvec3** | **Vector3i** | |
  651. +----------------------+-------------------------+------------------------------------------------------------+
  652. | **uvec4** | **Vector4i** | |
  653. +----------------------+-------------------------+------------------------------------------------------------+
  654. | **float** | **float** | |
  655. +----------------------+-------------------------+------------------------------------------------------------+
  656. | **vec2** | **Vector2** | |
  657. +----------------------+-------------------------+------------------------------------------------------------+
  658. | **vec3** | **Vector3**, **Color** | When Color is used, it will be interpreted as (r, g, b). |
  659. +----------------------+-------------------------+------------------------------------------------------------+
  660. | **vec4** | **Vector4**, **Color**, | When Color is used, it will be interpreted as (r, g, b, a).|
  661. | | **Rect2**, **Plane**, | |
  662. | | **Quaternion** | When Rect2 is used, it will be interpreted as |
  663. | | | (position.x, position.y, size.x, size.y). |
  664. | | | |
  665. | | | When Plane is used it will be interpreted as |
  666. | | | (normal.x, normal.y, normal.z, d). |
  667. | | | |
  668. | | | |
  669. +----------------------+-------------------------+------------------------------------------------------------+
  670. | **mat2** | **Transform2D** | |
  671. | | | |
  672. +----------------------+-------------------------+------------------------------------------------------------+
  673. | **mat3** | **Basis** | |
  674. +----------------------+-------------------------+------------------------------------------------------------+
  675. | **mat4** | **Projection**, | When a Transform3D is used, the w Vector is set to the |
  676. | | **Transform3D** | identity. |
  677. +----------------------+-------------------------+------------------------------------------------------------+
  678. | **sampler2D** | **Texture2D** | |
  679. +----------------------+-------------------------+------------------------------------------------------------+
  680. | **isampler2D** | **Texture2D** | |
  681. +----------------------+-------------------------+------------------------------------------------------------+
  682. | **usampler2D** | **Texture2D** | |
  683. +----------------------+-------------------------+------------------------------------------------------------+
  684. | **sampler2DArray** | **Texture2DArray** | |
  685. +----------------------+-------------------------+------------------------------------------------------------+
  686. | **isampler2DArray** | **Texture2DArray** | |
  687. +----------------------+-------------------------+------------------------------------------------------------+
  688. | **usampler2DArray** | **Texture2DArray** | |
  689. +----------------------+-------------------------+------------------------------------------------------------+
  690. | **sampler3D** | **Texture3D** | |
  691. +----------------------+-------------------------+------------------------------------------------------------+
  692. | **isampler3D** | **Texture3D** | |
  693. +----------------------+-------------------------+------------------------------------------------------------+
  694. | **usampler3D** | **Texture3D** | |
  695. +----------------------+-------------------------+------------------------------------------------------------+
  696. | **samplerCube** | **Cubemap** | |
  697. +----------------------+-------------------------+------------------------------------------------------------+
  698. | **samplerCubeArray** | **CubemapArray** | |
  699. +----------------------+-------------------------+------------------------------------------------------------+
  700. .. note:: Be careful when setting shader uniforms from GDScript, no error will
  701. be thrown if the type does not match. Your shader will just exhibit
  702. undefined behavior.
  703. Uniforms can also be assigned default values:
  704. .. code-block:: glsl
  705. shader_type spatial;
  706. uniform vec4 some_vector = vec4(0.0);
  707. uniform vec4 some_color : source_color = vec4(1.0);
  708. Note that when adding a default value and a hint, the default value goes after the hint.
  709. If you need to make multiple uniforms to be grouped in the specific category of an inspector, you can use a `group_uniform` keyword like:
  710. .. code-block:: glsl
  711. group_uniforms MyGroup;
  712. uniform sampler2D test;
  713. You can close the group by using:
  714. .. code-block:: glsl
  715. group_uniforms;
  716. The syntax also supports subgroups (it's not mandatory to declare the base group before this):
  717. .. code-block:: glsl
  718. group_uniforms MyGroup.MySubgroup;
  719. Global uniforms
  720. ~~~~~~~~~~~~~~~
  721. Sometimes, you want to modify a parameter in many different shaders at once.
  722. With a regular uniform, this takes a lot of work as all these shaders need to be
  723. tracked and the uniform needs to be set for each of them. Global uniforms allow
  724. you to create and update uniforms that will be available in all shaders, in
  725. every shader type (``canvas_item``, ``spatial``, ``particles``, ``sky`` and
  726. ``fog``).
  727. Global uniforms are especially useful for environmental effects that affect many
  728. objects in a scene, like having foliage bend when the player is nearby, or having
  729. objects move with the wind.
  730. To create a global uniform, open the **Project Settings** then go to the
  731. **Shader Globals** tab. Specify a name for the uniform (case-sensitive) and a
  732. type, then click **Add** in the top-right corner of the dialog. You can then
  733. edit the value assigned to the uniform by clicking the value in the list of
  734. uniforms:
  735. .. figure:: img/shading_language_adding_global_uniforms.webp
  736. :align: center
  737. :alt: Adding a global uniform in the Shader Globals tab of the Project Settings
  738. Adding a global uniform in the Shader Globals tab of the Project Settings
  739. After creating a global uniform, you can use it in a shader as follows:
  740. .. code-block:: glsl
  741. shader_type canvas_item;
  742. global uniform vec4 my_color;
  743. void fragment() {
  744. COLOR = my_color.rgb;
  745. }
  746. Note that the global uniform *must* exist in the Project Settings at the time
  747. the shader is saved, or compilation will fail. While you can assign a default
  748. value using ``global uniform vec4 my_color = ...`` in the shader code, it will
  749. be ignored as the global uniform must always be defined in the Project Settings
  750. anyway.
  751. To change the value of a global uniform at run-time, use the
  752. :ref:`RenderingServer.global_shader_parameter_set <class_RenderingServer_method_global_shader_parameter_set>`
  753. method in a script:
  754. .. code-block:: gdscript
  755. RenderingServer.global_shader_parameter_set("my_color", Color(0.3, 0.6, 1.0))
  756. Assigning global uniform values can be done as many times as desired without
  757. impacting performance, as setting data doesn't require synchronization between
  758. the CPU and GPU.
  759. You can also add or remove global uniforms at run-time:
  760. .. code-block:: gdscript
  761. RenderingServer.global_shader_parameter_add("my_color", RenderingServer.GLOBAL_VAR_TYPE_COLOR, Color(0.3, 0.6, 1.0))
  762. RenderingServer.global_shader_parameter_remove("my_color")
  763. Adding or removing global uniforms at run-time has a performance cost, although
  764. it's not as pronounced compared to getting global uniform values from a script
  765. (see the warning below).
  766. .. warning::
  767. While you *can* query the value of a global uniform at run-time in a script
  768. using ``RenderingServer.global_shader_parameter_get("uniform_name")``, this
  769. has a large performance penalty as the rendering thread needs to synchronize
  770. with the calling thread.
  771. Therefore, it's not recommended to read global shader uniform values
  772. continuously in a script. If you need to read values in a script after
  773. setting them, consider creating an :ref:`autoload <doc_singletons_autoload>`
  774. where you store the values you need to query at the same time you're setting
  775. them as global uniforms.
  776. .. _doc_shading_language_per_instance_uniforms:
  777. Per-instance uniforms
  778. ~~~~~~~~~~~~~~~~~~~~~
  779. .. note::
  780. Per-instance uniforms are only available in ``spatial`` (3D) shaders.
  781. .. note::
  782. Per-instance uniforms are not supported when using the Compatibility renderer.
  783. Sometimes, you want to modify a parameter on each node using the material. As an
  784. example, in a forest full of trees, when you want each tree to have a slightly
  785. different color that is editable by hand. Without per-instance uniforms, this
  786. requires creating a unique material for each tree (each with a slightly
  787. different hue). This makes material management more complex, and also has a
  788. performance overhead due to the scene requiring more unique material instances.
  789. Vertex colors could also be used here, but they'd require creating unique copies
  790. of the mesh for each different color, which also has a performance overhead.
  791. Per-instance uniforms are set on each GeometryInstance3D, rather than on each
  792. Material instance. Take this into account when working with meshes that have
  793. multiple materials assigned to them, or MultiMesh setups.
  794. .. code-block:: glsl
  795. shader_type spatial;
  796. // Provide a hint to edit as a color. Optionally, a default value can be provided.
  797. // If no default value is provided, the type's default is used (e.g. opaque black for colors).
  798. instance uniform vec4 my_color : source_color = vec4(1.0, 0.5, 0.0, 1.0);
  799. void fragment() {
  800. ALBEDO = my_color.rgb;
  801. }
  802. After saving the shader, you can change the per-instance uniform's value using
  803. the inspector:
  804. .. figure:: img/shading_language_per_instance_uniforms_inspector.webp
  805. :align: center
  806. :alt: Setting a per-instance uniform's value in the GeometryInstance3D section of the inspector
  807. Setting a per-instance uniform's value in the GeometryInstance3D section of the inspector
  808. Per-instance uniform values can also be set at run-time using
  809. :ref:`set_instance_shader_parameter <class_GeometryInstance3D_method_set_instance_shader_parameter>`
  810. method on a node that inherits from :ref:`class_GeometryInstance3D`:
  811. .. code-block:: gdscript
  812. $MeshInstance3D.set_instance_shader_parameter("my_color", Color(0.3, 0.6, 1.0))
  813. When using per-instance uniforms, there are some restrictions you should be aware of:
  814. - **Per-instance uniforms do not support textures**, only regular scalar and
  815. vector types. As a workaround, you can pass a texture array as a regular
  816. uniform, then pass the index of the texture to be drawn using a per-instance
  817. uniform.
  818. - There is a practical maximum limit of 16 instance uniforms per shader.
  819. - If your mesh uses multiple materials, the parameters for the first mesh
  820. material found will "win" over the subsequent ones, unless they have the same
  821. name, index *and* type. In this case, all parameters are affected correctly.
  822. - If you run into the above situation, you can avoid clashes by manually
  823. specifying the index (0-15) of the instance uniform by using the
  824. ``instance_index`` hint:
  825. .. code-block:: glsl
  826. instance uniform vec4 my_color : source_color, instance_index(5);
  827. Built-in variables
  828. ------------------
  829. A large number of built-in variables are available, like ``UV``, ``COLOR`` and ``VERTEX``. What variables are available depends on the type of shader (``spatial``, ``canvas_item`` or ``particle``) and the function used (``vertex``, ``fragment`` or ``light``).
  830. For a list of the built-in variables that are available, please see the corresponding pages:
  831. - :ref:`Spatial shaders <doc_spatial_shader>`
  832. - :ref:`Canvas item shaders <doc_canvas_item_shader>`
  833. - :ref:`Particle shaders <doc_particle_shader>`
  834. - :ref:`Sky shaders <doc_sky_shader>`
  835. - :ref:`Fog shaders <doc_fog_shader>`
  836. Built-in functions
  837. ------------------
  838. A large number of built-in functions are supported, conforming to GLSL ES 3.0.
  839. When vec_type (float), vec_int_type, vec_uint_type, vec_bool_type nomenclature
  840. is used, it can be scalar or vector.
  841. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  842. | Function | Description / Return value |
  843. +=============================================================================+=====================================================================+
  844. | vec_type **radians** (vec_type degrees) | Convert degrees to radians. |
  845. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  846. | vec_type **degrees** (vec_type radians) | Convert radians to degrees. |
  847. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  848. | vec_type **sin** (vec_type x) | Sine. |
  849. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  850. | vec_type **cos** (vec_type x) | Cosine. |
  851. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  852. | vec_type **tan** (vec_type x) | Tangent. |
  853. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  854. | vec_type **asin** (vec_type x) | Arcsine. |
  855. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  856. | vec_type **acos** (vec_type x) | Arccosine. |
  857. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  858. | vec_type **atan** (vec_type y_over_x) | Arctangent. |
  859. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  860. | vec_type **atan** (vec_type y, vec_type x) | Arctangent. |
  861. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  862. | vec_type **sinh** (vec_type x) | Hyperbolic sine. |
  863. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  864. | vec_type **cosh** (vec_type x) | Hyperbolic cosine. |
  865. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  866. | vec_type **tanh** (vec_type x) | Hyperbolic tangent. |
  867. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  868. | vec_type **asinh** (vec_type x) | Inverse hyperbolic sine. |
  869. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  870. | vec_type **acosh** (vec_type x) | Inverse hyperbolic cosine. |
  871. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  872. | vec_type **atanh** (vec_type x) | Inverse hyperbolic tangent. |
  873. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  874. | vec_type **pow** (vec_type x, vec_type y) | Power (undefined if ``x`` < 0 or if ``x`` == 0 and ``y`` <= 0). |
  875. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  876. | vec_type **exp** (vec_type x) | Base-e exponential. |
  877. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  878. | vec_type **exp2** (vec_type x) | Base-2 exponential. |
  879. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  880. | vec_type **log** (vec_type x) | Natural logarithm. |
  881. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  882. | vec_type **log2** (vec_type x) | Base-2 logarithm. |
  883. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  884. | vec_type **sqrt** (vec_type x) | Square root. |
  885. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  886. | vec_type **inversesqrt** (vec_type x) | Inverse square root. |
  887. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  888. | vec_type **abs** (vec_type x) | Absolute value (returns positive value if negative). |
  889. | | |
  890. | ivec_type **abs** (ivec_type x) | |
  891. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  892. | vec_type **sign** (vec_type x) | Sign (returns ``1.0`` if positive, ``-1.0`` if negative, |
  893. | | ``0.0`` if zero). |
  894. | ivec_type **sign** (ivec_type x) | |
  895. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  896. | vec_type **floor** (vec_type x) | Round to the integer below. |
  897. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  898. | vec_type **round** (vec_type x) | Round to the nearest integer. |
  899. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  900. | vec_type **roundEven** (vec_type x) | Round to the nearest even integer. |
  901. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  902. | vec_type **trunc** (vec_type x) | Truncation. |
  903. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  904. | vec_type **ceil** (vec_type x) | Round to the integer above. |
  905. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  906. | vec_type **fract** (vec_type x) | Fractional (returns ``x - floor(x)``). |
  907. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  908. | vec_type **mod** (vec_type x, vec_type y) | Modulo (division remainder). |
  909. | | |
  910. | vec_type **mod** (vec_type x, float y) | |
  911. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  912. | vec_type **modf** (vec_type x, out vec_type i) | Fractional of ``x``, with ``i`` as integer part. |
  913. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  914. | vec_type **min** (vec_type a, vec_type b) | Lowest value between ``a`` and ``b``. |
  915. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  916. | vec_type **max** (vec_type a, vec_type b) | Highest value between ``a`` and ``b``. |
  917. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  918. | vec_type **clamp** (vec_type x, vec_type min, vec_type max) | Clamp ``x`` between ``min`` and ``max`` (inclusive). |
  919. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  920. | float **mix** (float a, float b, float c) | Linear interpolate between ``a`` and ``b`` by ``c``. |
  921. | | |
  922. | vec_type **mix** (vec_type a, vec_type b, float c) | |
  923. | | |
  924. | vec_type **mix** (vec_type a, vec_type b, bvec_type c) | |
  925. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  926. | vec_type **fma** (vec_type a, vec_type b, vec_type c) | Performs a fused multiply-add operation: ``(a * b + c)`` |
  927. | | (faster than doing it manually). |
  928. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  929. | vec_type **step** (vec_type a, vec_type b) | ``b[i] < a[i] ? 0.0 : 1.0``. |
  930. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  931. | vec_type **step** (float a, vec_type b) | ``b[i] < a ? 0.0 : 1.0``. |
  932. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  933. | vec_type **smoothstep** (vec_type a, vec_type b, vec_type c) | Hermite interpolate between ``a`` and ``b`` by ``c``. |
  934. | | |
  935. | vec_type **smoothstep** (float a, float b, vec_type c) | |
  936. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  937. | bvec_type **isnan** (vec_type x) | Returns ``true`` if scalar or vector component is ``NaN``. |
  938. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  939. | bvec_type **isinf** (vec_type x) | Returns ``true`` if scalar or vector component is ``INF``. |
  940. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  941. | ivec_type **floatBitsToInt** (vec_type x) | Float->Int bit copying, no conversion. |
  942. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  943. | uvec_type **floatBitsToUint** (vec_type x) | Float->UInt bit copying, no conversion. |
  944. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  945. | vec_type **intBitsToFloat** (ivec_type x) | Int->Float bit copying, no conversion. |
  946. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  947. | vec_type **uintBitsToFloat** (uvec_type x) | UInt->Float bit copying, no conversion. |
  948. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  949. | float **length** (vec_type x) | Vector length. |
  950. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  951. | float **distance** (vec_type a, vec_type b) | Distance between vectors i.e ``length(a - b)``. |
  952. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  953. | float **dot** (vec_type a, vec_type b) | Dot product. |
  954. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  955. | vec3 **cross** (vec3 a, vec3 b) | Cross product. |
  956. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  957. | vec_type **normalize** (vec_type x) | Normalize to unit length. |
  958. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  959. | vec3 **reflect** (vec3 I, vec3 N) | Reflect. |
  960. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  961. | vec3 **refract** (vec3 I, vec3 N, float eta) | Refract. |
  962. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  963. | vec_type **faceforward** (vec_type N, vec_type I, vec_type Nref) | If ``dot(Nref, I)`` < 0, return ``N``, otherwise ``-N``. |
  964. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  965. | mat_type **matrixCompMult** (mat_type x, mat_type y) | Matrix component multiplication. |
  966. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  967. | mat_type **outerProduct** (vec_type column, vec_type row) | Matrix outer product. |
  968. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  969. | mat_type **transpose** (mat_type m) | Transpose matrix. |
  970. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  971. | float **determinant** (mat_type m) | Matrix determinant. |
  972. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  973. | mat_type **inverse** (mat_type m) | Inverse matrix. |
  974. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  975. | bvec_type **lessThan** (vec_type x, vec_type y) | Bool vector comparison on < int/uint/float vectors. |
  976. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  977. | bvec_type **greaterThan** (vec_type x, vec_type y) | Bool vector comparison on > int/uint/float vectors. |
  978. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  979. | bvec_type **lessThanEqual** (vec_type x, vec_type y) | Bool vector comparison on <= int/uint/float vectors. |
  980. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  981. | bvec_type **greaterThanEqual** (vec_type x, vec_type y) | Bool vector comparison on >= int/uint/float vectors. |
  982. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  983. | bvec_type **equal** (vec_type x, vec_type y) | Bool vector comparison on == int/uint/float vectors. |
  984. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  985. | bvec_type **notEqual** (vec_type x, vec_type y) | Bool vector comparison on != int/uint/float vectors. |
  986. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  987. | bool **any** (bvec_type x) | ``true`` if any component is ``true``, ``false`` otherwise. |
  988. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  989. | bool **all** (bvec_type x) | ``true`` if all components are ``true``, ``false`` otherwise. |
  990. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  991. | bvec_type **not** (bvec_type x) | Invert boolean vector. |
  992. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  993. | ivec2 **textureSize** (gsampler2D s, int lod) | Get the size of a texture. |
  994. | | |
  995. | ivec3 **textureSize** (gsampler2DArray s, int lod) | The LOD defines which mipmap level is used. An LOD value of ``0`` |
  996. | | will use the full resolution texture. |
  997. | ivec3 **textureSize** (gsampler3D s, int lod) | |
  998. | | |
  999. | ivec2 **textureSize** (samplerCube s, int lod) | |
  1000. | | |
  1001. | ivec2 **textureSize** (samplerCubeArray s, int lod) | |
  1002. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1003. | vec2 **textureQueryLod** (gsampler2D s, vec2 p) | Compute the level-of-detail that would be used to sample from a |
  1004. | | texture. The ``x`` component of the resulted value is the mipmap |
  1005. | vec3 **textureQueryLod** (gsampler2DArray s, vec2 p) | array that would be accessed. The ``y`` component is computed |
  1006. | | level-of-detail relative to the base level (regardless of the |
  1007. | vec2 **textureQueryLod** (gsampler3D s, vec3 p) | mipmap levels of the texture). |
  1008. | | |
  1009. | vec2 **textureQueryLod** (samplerCube s, vec3 p) | |
  1010. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1011. | int **textureQueryLevels** (gsampler2D s) | Get the number of accessible mipmap levels of a texture. |
  1012. | | |
  1013. | int **textureQueryLevels** (gsampler2DArray s) | If the texture is unassigned to a sampler, ``1`` is returned (Godot |
  1014. | | always internally assigns a texture even to an empty sampler). |
  1015. | int **textureQueryLevels** (gsampler3D s) | |
  1016. | | |
  1017. | int **textureQueryLevels** (samplerCube s) | |
  1018. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1019. | gvec4_type **texture** (gsampler2D s, vec2 p [, float bias]) | Perform a texture read. |
  1020. | | |
  1021. | gvec4_type **texture** (gsampler2DArray s, vec3 p [, float bias]) | |
  1022. | | |
  1023. | gvec4_type **texture** (gsampler3D s, vec3 p [, float bias]) | |
  1024. | | |
  1025. | vec4 **texture** (samplerCube s, vec3 p [, float bias]) | |
  1026. | | |
  1027. | vec4 **texture** (samplerCubeArray s, vec4 p [, float bias]) | |
  1028. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1029. | gvec4_type **textureProj** (gsampler2D s, vec3 p [, float bias]) | Perform a texture read with projection. |
  1030. | | |
  1031. | gvec4_type **textureProj** (gsampler2D s, vec4 p [, float bias]) | |
  1032. | | |
  1033. | gvec4_type **textureProj** (gsampler3D s, vec4 p [, float bias]) | |
  1034. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1035. | gvec4_type **textureLod** (gsampler2D s, vec2 p, float lod) | Perform a texture read at custom mipmap. |
  1036. | | |
  1037. | gvec4_type **textureLod** (gsampler2DArray s, vec3 p, float lod) | The LOD defines which mipmap level is used. An LOD value of ``0.0`` |
  1038. | | will use the full resolution texture. If the texture lacks mipmaps, |
  1039. | gvec4_type **textureLod** (gsampler3D s, vec3 p, float lod) | all LOD values will act like ``0.0``. |
  1040. | | |
  1041. | vec4 **textureLod** (samplerCube s, vec3 p, float lod) | |
  1042. | | |
  1043. | vec4 **textureLod** (samplerCubeArray s, vec4 p, float lod) | |
  1044. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1045. | gvec4_type **textureProjLod** (gsampler2D s, vec3 p, float lod) | Performs a texture read with projection/LOD. |
  1046. | | |
  1047. | gvec4_type **textureProjLod** (gsampler2D s, vec4 p, float lod) | The LOD defines which mipmap level is used. An LOD value of ``0.0`` |
  1048. | | will use the full resolution texture. If the texture lacks mipmaps, |
  1049. | gvec4_type **textureProjLod** (gsampler3D s, vec4 p, float lod) | all LOD values will act like ``0.0``. |
  1050. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1051. | gvec4_type **textureGrad** (gsampler2D s, vec2 p, vec2 dPdx, | Performs a texture read with explicit gradients. |
  1052. | vec2 dPdy) | |
  1053. | | |
  1054. | gvec4_type **textureGrad** (gsampler2DArray s, vec3 p, vec2 dPdx, | |
  1055. | vec2 dPdy) | |
  1056. | | |
  1057. | gvec4_type **textureGrad** (gsampler3D s, vec3 p, vec2 dPdx, | |
  1058. | vec2 dPdy) | |
  1059. | | |
  1060. | vec4 **textureGrad** (samplerCube s, vec3 p, vec3 dPdx, vec3 dPdy) | |
  1061. | | |
  1062. | vec4 **textureGrad** (samplerCubeArray s, vec3 p, vec3 dPdx, | |
  1063. | vec3 dPdy) | |
  1064. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1065. | gvec4_type **textureProjGrad** (gsampler2D s, vec3 p, vec2 dPdx, vec2 dPdy) | Performs a texture read with projection/LOD and with explicit |
  1066. | | gradients. |
  1067. | gvec4_type **textureProjGrad** (gsampler2D s, vec4 p, vec2 dPdx, vec2 dPdy) | |
  1068. | | |
  1069. | gvec4_type **textureProjGrad** (gsampler3D s, vec4 p, vec3 dPdx, vec3 dPdy) | |
  1070. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1071. | gvec4_type **texelFetch** (gsampler2D s, ivec2 p, int lod) | Fetches a single texel using integer coordinates. |
  1072. | | |
  1073. | gvec4_type **texelFetch** (gsampler2DArray s, ivec3 p, int lod) | The LOD defines which mipmap level is used. An LOD value of ``0`` |
  1074. | | will use the full resolution texture. |
  1075. | gvec4_type **texelFetch** (gsampler3D s, ivec3 p, int lod) | |
  1076. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1077. | gvec4_type **textureGather** (gsampler2D s, vec2 p [, int comps]) | Gathers four texels from a texture. |
  1078. | | Use ``comps`` within range of 0..3 to |
  1079. | gvec4_type **textureGather** (gsampler2DArray s, vec3 p [, int comps]) | define which component (x, y, z, w) is returned. |
  1080. | | If ``comps`` is not provided: 0 (or x-component) is used. |
  1081. | vec4 **textureGather** (samplerCube s, vec3 p [, int comps]) | |
  1082. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1083. | vec_type **dFdx** (vec_type p) | Derivative in ``x`` using local differencing. |
  1084. | | Internally, can use either ``dFdxCoarse`` or ``dFdxFine``, but the |
  1085. | | decision for which to use is made by the GPU driver. |
  1086. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1087. | vec_type **dFdxCoarse** (vec_type p) | Calculates derivative with respect to ``x`` window coordinate using |
  1088. | | local differencing based on the value of ``p`` for the current |
  1089. | | fragment neighbour(s), and will possibly, but not necessarily, |
  1090. | | include the value for the current fragment. |
  1091. | | This function is not available on ``gl_compatibility`` profile. |
  1092. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1093. | vec_type **dFdxFine** (vec_type p) | Calculates derivative with respect to ``x`` window coordinate using |
  1094. | | local differencing based on the value of ``p`` for the current |
  1095. | | fragment and its immediate neighbour(s). |
  1096. | | This function is not available on ``gl_compatibility`` profile. |
  1097. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1098. | vec_type **dFdy** (vec_type p) | Derivative in ``y`` using local differencing. |
  1099. | | Internally, can use either ``dFdyCoarse`` or ``dFdyFine``, but the |
  1100. | | decision for which to use is made by the GPU driver. |
  1101. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1102. | vec_type **dFdyCoarse** (vec_type p) | Calculates derivative with respect to ``y`` window coordinate using |
  1103. | | local differencing based on the value of ``p`` for the current |
  1104. | | fragment neighbour(s), and will possibly, but not necessarily, |
  1105. | | include the value for the current fragment. |
  1106. | | This function is not available on ``gl_compatibility`` profile. |
  1107. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1108. | vec_type **dFdyFine** (vec_type p) | Calculates derivative with respect to ``y`` window coordinate using |
  1109. | | local differencing based on the value of ``p`` for the current |
  1110. | | fragment and its immediate neighbour(s). |
  1111. | | This function is not available on ``gl_compatibility`` profile. |
  1112. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1113. | vec_type **fwidth** (vec_type p) | Sum of absolute derivative in ``x`` and ``y``. |
  1114. | | This is the equivalent of using ``abs(dFdx(p)) + abs(dFdy(p))``. |
  1115. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1116. | vec_type **fwidthCoarse** (vec_type p) | Sum of absolute derivative in ``x`` and ``y``. |
  1117. | | This is the equivalent of using |
  1118. | | ``abs(dFdxCoarse(p)) + abs(dFdyCoarse(p))``. |
  1119. | | This function is not available on ``gl_compatibility`` profile. |
  1120. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1121. | vec_type **fwidthFine** (vec_type p) | Sum of absolute derivative in ``x`` and ``y``. |
  1122. | | This is the equivalent of using |
  1123. | | ``abs(dFdxFine(p)) + abs(dFdyFine(p))``. |
  1124. | | This function is not available on ``gl_compatibility`` profile. |
  1125. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1126. | uint **packHalf2x16** (vec2 v) | Convert two 32-bit floating-point numbers into 16-bit |
  1127. | | and pack them into a 32-bit unsigned integer and vice-versa. |
  1128. | vec2 **unpackHalf2x16** (uint v) | |
  1129. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1130. | uint **packUnorm2x16** (vec2 v) | Convert two 32-bit floating-point numbers (clamped |
  1131. | | within 0..1 range) into 16-bit and pack them |
  1132. | vec2 **unpackUnorm2x16** (uint v) | into a 32-bit unsigned integer and vice-versa. |
  1133. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1134. | uint **packSnorm2x16** (vec2 v) | Convert two 32-bit floating-point numbers (clamped |
  1135. | | within -1..1 range) into 16-bit and pack them |
  1136. | vec2 **unpackSnorm2x16** (uint v) | into a 32-bit unsigned integer and vice-versa. |
  1137. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1138. | uint **packUnorm4x8** (vec4 v) | Convert four 32-bit floating-point numbers (clamped |
  1139. | | within 0..1 range) into 8-bit and pack them |
  1140. | vec4 **unpackUnorm4x8** (uint v) | into a 32-bit unsigned integer and vice-versa. |
  1141. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1142. | uint **packSnorm4x8** (vec4 v) | Convert four 32-bit floating-point numbers (clamped |
  1143. | | within -1..1 range) into 8-bit and pack them |
  1144. | vec4 **unpackSnorm4x8** (uint v) | into a 32-bit unsigned integer and vice-versa. |
  1145. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1146. | ivec_type **bitfieldExtract** (ivec_type value, int offset, int bits) | Extracts a range of bits from an integer. |
  1147. | | |
  1148. | uvec_type **bitfieldExtract** (uvec_type value, int offset, int bits) | |
  1149. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1150. | ivec_type **bitfieldInsert** (ivec_type base, ivec_type insert, | Insert a range of bits into an integer. |
  1151. | int offset, int bits) | |
  1152. | | |
  1153. | uvec_type **bitfieldInsert** (uvec_type base, uvec_type insert, | |
  1154. | int offset, int bits) | |
  1155. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1156. | ivec_type **bitfieldReverse** (ivec_type value) | Reverse the order of bits in an integer. |
  1157. | | |
  1158. | uvec_type **bitfieldReverse** (uvec_type value) | |
  1159. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1160. | ivec_type **bitCount** (ivec_type value) | Counts the number of 1 bits in an integer. |
  1161. | | |
  1162. | uvec_type **bitCount** (uvec_type value) | |
  1163. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1164. | ivec_type **findLSB** (ivec_type value) | Find the index of the least significant bit set to 1 in an integer. |
  1165. | | |
  1166. | uvec_type **findLSB** (uvec_type value) | |
  1167. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1168. | ivec_type **findMSB** (ivec_type value) | Find the index of the most significant bit set to 1 in an integer. |
  1169. | | |
  1170. | uvec_type **findMSB** (uvec_type value) | |
  1171. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1172. | void **imulExtended** (ivec_type x, ivec_type y, out ivec_type msb, | Multiplies two 32-bit numbers and produce a 64-bit result. |
  1173. | out ivec_type lsb) | ``x`` - the first number. |
  1174. | | ``y`` - the second number. |
  1175. | void **umulExtended** (uvec_type x, uvec_type y, out uvec_type msb, | ``msb`` - will contain the most significant bits. |
  1176. | out uvec_type lsb) | ``lsb`` - will contain the least significant bits. |
  1177. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1178. | uvec_type **uaddCarry** (uvec_type x, uvec_type y, out uvec_type carry) | Adds two unsigned integers and generates carry. |
  1179. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1180. | uvec_type **usubBorrow** (uvec_type x, uvec_type y, out uvec_type borrow) | Subtracts two unsigned integers and generates borrow. |
  1181. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1182. | vec_type **ldexp** (vec_type x, out ivec_type exp) | Assemble a floating-point number from a value and exponent. |
  1183. | | |
  1184. | | If this product is too large to be represented in the |
  1185. | | floating-point type the result is undefined. |
  1186. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+
  1187. | vec_type **frexp** (vec_type x, out ivec_type exp) | Splits a floating-point number(``x``) into significand |
  1188. | | (in the range of [0.5, 1.0]) and an integral exponent. |
  1189. | | |
  1190. | | For ``x`` equals zero the significand and exponent are both zero. |
  1191. | | For ``x`` of infinity or NaN, the results are undefined. |
  1192. +-----------------------------------------------------------------------------+---------------------------------------------------------------------+