shading_language.rst 103 KB

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