shading_language.rst 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  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 functions are supported,
  7. and the few remaining ones will likely be added over time.
  8. If you are already familiar with GLSL, the :ref:`Godot Shader Migration Guide<doc_migrating_to_godot_shader_language>`
  9. is a resource that will help you transition from regular GLSL to Godot's shading language.
  10. Data types
  11. ----------
  12. Most GLSL ES 3.0 datatypes are supported:
  13. +-----------------+---------------------------------------------------------------------------+
  14. | Type | Description |
  15. +=================+===========================================================================+
  16. | **void** | Void datatype, useful only for functions that return nothing. |
  17. +-----------------+---------------------------------------------------------------------------+
  18. | **bool** | Boolean datatype, can only contain "true" or "false" |
  19. +-----------------+---------------------------------------------------------------------------+
  20. | **bvec2** | Two component vector of booleans. |
  21. +-----------------+---------------------------------------------------------------------------+
  22. | **bvec3** | Three component vector of booleans. |
  23. +-----------------+---------------------------------------------------------------------------+
  24. | **bvec4** | Four component vector of booleans. |
  25. +-----------------+---------------------------------------------------------------------------+
  26. | **int** | Signed scalar integer. |
  27. +-----------------+---------------------------------------------------------------------------+
  28. | **ivec2** | Two component vector of signed integers. |
  29. +-----------------+---------------------------------------------------------------------------+
  30. | **ivec3** | Three component vector of signed integers. |
  31. +-----------------+---------------------------------------------------------------------------+
  32. | **ivec4** | Four component vector of signed integers. |
  33. +-----------------+---------------------------------------------------------------------------+
  34. | **uint** | Unsigned scalar integer, can't contain negative numbers. |
  35. +-----------------+---------------------------------------------------------------------------+
  36. | **uvec2** | Two component vector of unsigned integers. |
  37. +-----------------+---------------------------------------------------------------------------+
  38. | **uvec3** | Three component vector of unsigned integers. |
  39. +-----------------+---------------------------------------------------------------------------+
  40. | **uvec4** | Four component vector of unsigned integers. |
  41. +-----------------+---------------------------------------------------------------------------+
  42. | **float** | Floating point scalar. |
  43. +-----------------+---------------------------------------------------------------------------+
  44. | **vec2** | Two component vector of floating point values. |
  45. +-----------------+---------------------------------------------------------------------------+
  46. | **vec3** | Three component vector of floating point values. |
  47. +-----------------+---------------------------------------------------------------------------+
  48. | **vec4** | Four component vector of floating point values. |
  49. +-----------------+---------------------------------------------------------------------------+
  50. | **mat2** | 2x2 matrix, in column major order. |
  51. +-----------------+---------------------------------------------------------------------------+
  52. | **mat3** | 3x3 matrix, in column major order. |
  53. +-----------------+---------------------------------------------------------------------------+
  54. | **mat4** | 4x4 matrix, in column major order. |
  55. +-----------------+---------------------------------------------------------------------------+
  56. | **sampler2D** | Sampler type, for binding 2D textures, which are read as float. |
  57. +-----------------+---------------------------------------------------------------------------+
  58. | **isampler2D** | Sampler type for binding 2D textures, which are read as signed integer. |
  59. +-----------------+---------------------------------------------------------------------------+
  60. | **usampler2D** | Sampler type for binding 2D textures, which are read as unsigned integer. |
  61. +-----------------+---------------------------------------------------------------------------+
  62. | **samplerCube** | Sampler type for binding Cubemaps, which are read as floats. |
  63. +-----------------+---------------------------------------------------------------------------+
  64. Casting
  65. ~~~~~~~
  66. Just like GLSL ES 3.0, implicit casting between scalars and vectors of the same size but different type is not allowed.
  67. Casting of types of different size is also not allowed. Conversion must be done explicitly via constructors.
  68. Example:
  69. .. code-block:: glsl
  70. float a = 2; // invalid
  71. float a = 2.0; // valid
  72. float a = float(2); // valid
  73. Default integer constants are signed, so casting is always needed to convert to unsigned:
  74. .. code-block:: glsl
  75. int a = 2; // valid
  76. uint a = 2; // invalid
  77. uint a = uint(2); // valid
  78. Members
  79. ~~~~~~~
  80. Individual scalar members of vector types are accessed via the "x", "y", "z" and "w" members.
  81. Alternatively, using "r", "g", "b" and "a" also works and is equivalent. Use whatever fits
  82. best for your needs.
  83. For matrices, use ``m[row][column]`` indexing syntax to access each scalar, or ``m[idx]`` for access
  84. a vector by row index. For example, for accessing the y position of an object in a mat4 you use
  85. ``m[3][1]``.
  86. Constructing
  87. ~~~~~~~~~~~~
  88. Construction of vector types must always pass:
  89. .. code-block:: glsl
  90. // The required amount of scalars
  91. vec4 a = vec4(0.0, 1.0, 2.0, 3.0);
  92. // Complementary vectors and/or scalars
  93. vec4 a = vec4(vec2(0.0, 1.0), vec2(2.0, 3.0));
  94. vec4 a = vec4(vec3(0.0, 1.0, 2.0), 3.0);
  95. // A single scalar for the whole vector
  96. vec4 a = vec4(0.0);
  97. Construction of matrix types requires vectors of the same dimension as the matrix. You can
  98. also build a diagonal matrix using ``matx(float)`` syntax. Accordingly, ``mat4(1.0)`` is
  99. an identity matrix.
  100. .. code-block:: glsl
  101. mat2 m2 = mat2(vec2(1.0, 0.0), vec2(0.0, 1.0));
  102. mat3 m3 = mat3(vec3(1.0, 0.0, 0.0), vec3(0.0, 1.0, 0.0), vec3(0.0, 0.0, 1.0));
  103. mat4 identity = mat4(1.0);
  104. Matrices can also been built from a matrix of another dimension.
  105. There are two rules :
  106. If a larger matrix is constructed from a smaller matrix, the additional rows and columns are
  107. set to the values they would have in an identity matrix. If a smaller matrix is constructed
  108. from a larger matrix, the top, left submatrix of the larger matrix is used.
  109. .. code-block:: glsl
  110. mat3 basis = mat3(WORLD_MATRIX);
  111. mat4 m4 = mat4(basis);
  112. mat2 m2 = mat2(m4);
  113. Swizzling
  114. ~~~~~~~~~
  115. It is possible to obtain any combination of components in any order, as long as the result
  116. is another vector type (or scalar). This is easier shown than explained:
  117. .. code-block:: glsl
  118. vec4 a = vec4(0.0, 1.0, 2.0, 3.0);
  119. vec3 b = a.rgb; // Creates a vec3 with vec4 components
  120. vec3 b = a.aaa; // Also valid, creates a vec3 and fills it with "a".
  121. vec3 b = a.bgr; // Order does not matter
  122. vec3 b = a.xyz; // Also rgba, xyzw are equivalent
  123. float c = b.w; // Invalid, because "w" is not present in vec3 b
  124. Precision
  125. ~~~~~~~~~
  126. It is possible to add precision modifiers to datatypes, use them for uniforms, variables, arguments and varyings:
  127. .. code-block:: glsl
  128. lowp vec4 a = vec4(0.0, 1.0, 2.0, 3.0); // low precision, usually 8 bits per component mapped to 0-1
  129. mediump vec4 a = vec4(0.0, 1.0, 2.0, 3.0); // medium precision, usually 16 bits or half float
  130. highp vec4 a = vec4(0.0, 1.0, 2.0, 3.0); // high precision, uses full float or integer range (default)
  131. Using lower precision for some operations can speed up the math involved (at the cost of less precision).
  132. This is rarely needed in the vertex processor function (where full precision is needed most of the time),
  133. but is often useful in the fragment processor.
  134. Keep in mind that some architectures (mainly mobile) benefit a lot from this, but are also restricted
  135. (conversion between precisions has a cost). Please read the relevant documentation on the target architecture
  136. to find out more. In all honesty though, mobile drivers are buggy so to stay out of trouble make simple
  137. shaders without specifying precision unless you *really* need to.
  138. Operators
  139. ---------
  140. Godot shading language supports the same set of operators as GLSL ES 3.0. Below is the list of them in precedence order:
  141. +-------------+-----------------------+--------------------+
  142. | Precedence | Class | Operator |
  143. +-------------+-----------------------+--------------------+
  144. | 1 (highest) | parenthetical grouping| **()** |
  145. +-------------+-----------------------+--------------------+
  146. | 2 | unary | **+, -, !, ~** |
  147. +-------------+-----------------------+--------------------+
  148. | 3 | multiplicative | **/, \*, %** |
  149. +-------------+-----------------------+--------------------+
  150. | 4 | additive | **+, -** |
  151. +-------------+-----------------------+--------------------+
  152. | 5 | bit-wise shift | **<<, >>** |
  153. +-------------+-----------------------+--------------------+
  154. | 6 | relational | **<, >, <=, >=** |
  155. +-------------+-----------------------+--------------------+
  156. | 7 | equality | **==, !=** |
  157. +-------------+-----------------------+--------------------+
  158. | 8 | bit-wise and | **&** |
  159. +-------------+-----------------------+--------------------+
  160. | 9 | bit-wise exclusive or | **^** |
  161. +-------------+-----------------------+--------------------+
  162. | 10 | bit-wise inclusive or | **|** |
  163. +-------------+-----------------------+--------------------+
  164. | 11 | logical and | **&&** |
  165. +-------------+-----------------------+--------------------+
  166. | 12 (lowest) | logical inclusive or | **||** |
  167. +-------------+-----------------------+--------------------+
  168. Flow control
  169. ------------
  170. Godot Shading language supports the most common types of flow control:
  171. .. code-block:: glsl
  172. // if and else
  173. if (cond) {
  174. } else {
  175. }
  176. // for loops
  177. for (int i = 0; i < 10; i++) {
  178. }
  179. // while
  180. while (true) {
  181. }
  182. Keep in mind that, in modern GPUs, an infinite loop can exist and can freeze your application (including editor).
  183. Godot can't protect you from this, so be careful to not make this mistake!
  184. Discarding
  185. ----------
  186. Fragment and light functions can use the **discard** keyword. If used, the fragment is discarded and nothing is written.
  187. Functions
  188. ---------
  189. It is possible to define functions in a Godot shader. They use the following syntax:
  190. .. code-block:: glsl
  191. ret_type func_name(args) {
  192. return ret_type; // if returning a value
  193. }
  194. // a more specific example:
  195. int sum2(int a, int b) {
  196. return a + b;
  197. }
  198. You can only use functions that are defined above the function you are calling
  199. them from.
  200. Function argument can have special qualifiers:
  201. * **in**: Means the argument is only for reading (default).
  202. * **out**: Means the argument is only for writing.
  203. * **inout**: Means the argument is fully passed via reference.
  204. Example below:
  205. .. code-block:: glsl
  206. void sum2(int a, int b, inout int result) {
  207. result = a + b;
  208. }
  209. Varyings
  210. ~~~~~~~~
  211. To send data from the vertex to fragment processor function, *varyings* are used. They are set
  212. for every primitive vertex in the *vertex processor*, and the value is interpolated for every
  213. pixel in the fragment processor.
  214. .. code-block:: glsl
  215. shader_type spatial;
  216. varying vec3 some_color;
  217. void vertex() {
  218. some_color = NORMAL; // make the normal the color
  219. }
  220. void fragment() {
  221. ALBEDO = some_color;
  222. }
  223. Interpolation qualifiers
  224. ~~~~~~~~~~~~~~~~~~~~~~~~
  225. Certain values are interpolated during the shading pipeline. You can modify how these interpolations
  226. are done by using *interpolation qualifiers*.
  227. .. code-block:: glsl
  228. shader_type spatial;
  229. varying flat vec3 our_color;
  230. void vertex() {
  231. our_color = COLOR.rgb;
  232. }
  233. void fragment() {
  234. ALBEDO = our_color;
  235. }
  236. There are two possible interpolation qualifiers:
  237. +-------------------+---------------------------------------------------------------------------------+
  238. | Qualifier | Description |
  239. +===================+=================================================================================+
  240. | **flat** | The value is not interpolated |
  241. +-------------------+---------------------------------------------------------------------------------+
  242. | **smooth** | The value is interpolated in a perspective-correct fashion. This is the default |
  243. +-------------------+---------------------------------------------------------------------------------+
  244. Uniforms
  245. ~~~~~~~~
  246. Passing values to shaders is possible. These are global to the whole shader and are called *uniforms*.
  247. When a shader is later assigned to a material, the uniforms will appear as editable parameters in it.
  248. Uniforms can't be written from within the shader.
  249. .. code-block:: glsl
  250. shader_type spatial;
  251. uniform float some_value;
  252. You can set uniforms in the editor in the material. Or you can set them through GDScript:
  253. ::
  254. material.set_shader_param("some_value", some_value)
  255. .. note:: The first argument to ``set_shader_param`` is the name of the uniform in the shader. It
  256. must match *exactly* to the name of the uniform in the shader or else it will not be recognized.
  257. Any GLSL type except for *void* can be a uniform. Additionally, Godot provides optional shader hints
  258. to make the compiler understand what the uniform is used for.
  259. .. code-block:: glsl
  260. shader_type spatial;
  261. uniform vec4 color : hint_color;
  262. uniform float amount : hint_range(0, 1);
  263. uniform vec4 other_color : hint_color = vec4(1.0);
  264. Full list of hints below:
  265. +----------------+-------------------------------+-------------------------------------+
  266. | Type | Hint | Description |
  267. +================+===============================+=====================================+
  268. | **vec4** | hint_color | Used as color |
  269. +----------------+-------------------------------+-------------------------------------+
  270. | **int, float** | hint_range(min,max [,step] ) | Used as range (with min/max/step) |
  271. +----------------+-------------------------------+-------------------------------------+
  272. | **sampler2D** | hint_albedo | Used as albedo color, default white |
  273. +----------------+-------------------------------+-------------------------------------+
  274. | **sampler2D** | hint_black_albedo | Used as albedo color, default black |
  275. +----------------+-------------------------------+-------------------------------------+
  276. | **sampler2D** | hint_normal | Used as normalmap |
  277. +----------------+-------------------------------+-------------------------------------+
  278. | **sampler2D** | hint_white | As value, default to white. |
  279. +----------------+-------------------------------+-------------------------------------+
  280. | **sampler2D** | hint_black | As value, default to black |
  281. +----------------+-------------------------------+-------------------------------------+
  282. | **sampler2D** | hint_aniso | As flowmap, default to right. |
  283. +----------------+-------------------------------+-------------------------------------+
  284. GDScript uses different variable types than GLSL does, so when passing variables from GDScript
  285. to shaders, Godot converts the type automatically. Below is a table of the corresponding types:
  286. +-----------------+-----------+
  287. | GDScript type | GLSL type |
  288. +=================+===========+
  289. | **bool** | **bool** |
  290. +-----------------+-----------+
  291. | **int** | **int** |
  292. +-----------------+-----------+
  293. | **float** | **float** |
  294. +-----------------+-----------+
  295. | **Vector2** | **vec2** |
  296. +-----------------+-----------+
  297. | **Vector3** | **vec3** |
  298. +-----------------+-----------+
  299. | **Color** | **vec4** |
  300. +-----------------+-----------+
  301. | **Transform** | **mat4** |
  302. +-----------------+-----------+
  303. | **Transform2D** | **mat4** |
  304. +-----------------+-----------+
  305. .. note:: Be careful when setting shader uniforms from GDScript, no error will be thrown if the
  306. type does not match. Your shader will just exhibit undefined behaviour.
  307. As Godot's 3D engine renders in linear color space, it's important to understand that textures
  308. that are supplied as color (i.e. albedo) need to be specified as such for proper SRGB->linear
  309. conversion.
  310. Uniforms can also be assigned default values:
  311. .. code-block:: glsl
  312. shader_type spatial;
  313. uniform vec4 some_vector = vec4(0.0);
  314. uniform vec4 some_color : hint_color = vec4(1.0);
  315. Built-in functions
  316. ------------------
  317. A large number of built-in functions are supported, conforming mostly to GLSL ES 3.0.
  318. When vec_type (float), vec_int_type, vec_uint_type, vec_bool_type nomenclature is used, it can be scalar or vector.
  319. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  320. | Function | Description |
  321. +===============================================================================================+================================================+
  322. | vec_type **radians** ( vec_type ) | Convert degrees to radians |
  323. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  324. | vec_type **degrees** ( vec_type ) | Convert radians to degrees |
  325. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  326. | vec_type **sin** ( vec_type ) | Sine |
  327. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  328. | vec_type **cos** ( vec_type ) | Cosine |
  329. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  330. | vec_type **tan** ( vec_type ) | Tangent |
  331. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  332. | vec_type **asin** ( vec_type ) | Arc-Sine |
  333. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  334. | vec_type **acos** ( vec_type ) | Arc-Cosine |
  335. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  336. | vec_type **atan** ( vec_type ) | Arc-Tangent |
  337. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  338. | vec_type **atan** ( vec_type x, vec_type y ) | Arc-Tangent to convert vector to angle |
  339. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  340. | vec_type **sinh** ( vec_type ) | Hyperbolic-Sine |
  341. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  342. | vec_type **cosh** ( vec_type ) | Hyperbolic-Cosine |
  343. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  344. | vec_type **tanh** ( vec_type ) | Hyperbolic-Tangent |
  345. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  346. | vec_type **asinh** ( vec_type ) | Inverse-Hyperbolic-Sine |
  347. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  348. | vec_type **acosh** ( vec_type ) | Inverse-Hyperbolic-Cosine |
  349. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  350. | vec_type **atanh** ( vec_type ) | Inverse-Hyperbolic-Tangent |
  351. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  352. | vec_type **pow** ( vec_type, vec_type ) | Power |
  353. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  354. | vec_type **exp** ( vec_type ) | Base-e Exponential |
  355. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  356. | vec_type **exp2** ( vec_type ) | Base-2 Exponential |
  357. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  358. | vec_type **log** ( vec_type ) | Natural Logarithm |
  359. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  360. | vec_type **log2** ( vec_type ) | Base-2 Logarithm |
  361. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  362. | vec_type **sqrt** ( vec_type ) | Square Root |
  363. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  364. | vec_type **inversesqrt** ( vec_type ) | Inverse Square Root |
  365. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  366. | vec_type **abs** ( vec_type ) | Absolute |
  367. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  368. | vec_int_type **abs** ( vec_int_type ) | Absolute |
  369. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  370. | vec_type **sign** ( vec_type ) | Sign |
  371. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  372. | vec_int_type **sign** ( vec_int_type ) | Sign |
  373. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  374. | vec_type **floor** ( vec_type ) | Floor |
  375. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  376. | vec_type **round** ( vec_type ) | Round |
  377. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  378. | vec_type **roundEven** ( vec_type ) | Round nearest even |
  379. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  380. | vec_type **trunc** ( vec_type ) | Truncation |
  381. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  382. | vec_type **ceil** ( vec_type ) | Ceiling |
  383. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  384. | vec_type **fract** ( vec_type ) | Fractional |
  385. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  386. | vec_type **mod** ( vec_type, vec_type ) | Remainder |
  387. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  388. | vec_type **mod** ( vec_type, float ) | Remainder |
  389. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  390. | vec_type **modf** ( vec_type x, out vec_type i ) | Fractional of x, with i has integer part |
  391. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  392. | vec_scalar_type **min** ( vec_scalar_type a, vec_scalar_type b ) | Minimum |
  393. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  394. | vec_scalar_type **max** ( vec_scalar_type a, vec_scalar_type b ) | Maximum |
  395. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  396. | vec_scalar_type **clamp** ( vec_scalar_type value, vec_scalar_type min, vec_scalar_type max ) | Clamp to Min-Max |
  397. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  398. | vec_type **mix** ( vec_type a, vec_type b, float c ) | Linear Interpolate (Scalar Coef.) |
  399. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  400. | vec_type **mix** ( vec_type a, vec_type b, vec_type c ) | Linear Interpolate (Vector Coef.) |
  401. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  402. | vec_type **mix** ( vec_type a, vec_type b, bool c ) | Linear Interpolate (Bool Selection) |
  403. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  404. | vec_type **mix** ( vec_type a, vec_type b, vec_bool_type c ) | Linear Interpolate (Bool-Vector Selection) |
  405. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  406. | vec_type **step** ( vec_type a, vec_type b ) | \` b[i] < a[i] ? 0.0 : 1.0 \` |
  407. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  408. | vec_type **step** ( float a, vec_type b ) | \` b[i] < a ? 0.0 : 1.0 \` |
  409. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  410. | vec_type **smoothstep** ( vec_type a, vec_type b, vec_type c ) | Hermite Interpolate |
  411. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  412. | vec_type **smoothstep** ( float a, float b, vec_type c ) | Hermite Interpolate |
  413. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  414. | vec_bool_type **isnan** ( vec_type ) | Scalar, or vector component being nan |
  415. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  416. | vec_bool_type **isinf** ( vec_type ) | Scalar, or vector component being inf |
  417. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  418. | vec_int_type **floatBitsToInt** ( vec_type ) | Float->Int bit copying, no conversion |
  419. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  420. | vec_uint_type **floatBitsToUint** ( vec_type ) | Float->UInt bit copying, no conversion |
  421. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  422. | vec_type **intBitsToFloat** ( vec_int_type ) | Int->Float bit copying, no conversion |
  423. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  424. | vec_type **uintBitsToFloat** ( vec_uint_type ) | UInt->Float bit copying, no conversion |
  425. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  426. | float **length** ( vec_type ) | Vector Length |
  427. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  428. | float **distance** ( vec_type, vec_type ) | Distance between vector |
  429. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  430. | float **dot** ( vec_type, vec_type ) | Dot Product |
  431. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  432. | vec3 **cross** ( vec3, vec3 ) | Cross Product |
  433. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  434. | vec_type **normalize** ( vec_type ) | Normalize to unit length |
  435. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  436. | vec3 **reflect** ( vec3 I, vec3 N ) | Reflect |
  437. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  438. | vec3 **refract** ( vec3 I, vec3 N, float eta ) | Refract |
  439. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  440. | vec_type **faceforward** ( vec_type N, vec_type I, vec_type Nref ) | If dot(Nref, I) < 0 return N, otherwise –N |
  441. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  442. | mat_type **matrixCompMult** ( mat_type, mat_type ) | Matrix Component Multiplication |
  443. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  444. | mat_type **outerProduct** ( vec_type, vec_type ) | Matrix Outer Product |
  445. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  446. | mat_type **transpose** ( mat_type ) | Transpose Matrix |
  447. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  448. | float **determinant** ( mat_type ) | Matrix Determinant |
  449. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  450. | mat_type **inverse** ( mat_type ) | Inverse Matrix |
  451. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  452. | vec_bool_type **lessThan** ( vec_scalar_type, vec_scalar_type ) | Bool vector cmp on < int/uint/float vectors |
  453. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  454. | vec_bool_type **greaterThan** ( vec_scalar_type, vec_scalar_type ) | Bool vector cmp on > int/uint/float vectors |
  455. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  456. | vec_bool_type **lessThanEqual** ( vec_scalar_type, vec_scalar_type ) | Bool vector cmp on <= int/uint/float vectors |
  457. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  458. | vec_bool_type **greaterThanEqual** ( vec_scalar_type, vec_scalar_type ) | Bool vector cmp on >= int/uint/float vectors |
  459. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  460. | vec_bool_type **equal** ( vec_scalar_type, vec_scalar_type ) | Bool vector cmp on == int/uint/float vectors |
  461. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  462. | vec_bool_type **notEqual** ( vec_scalar_type, vec_scalar_type ) | Bool vector cmp on != int/uint/float vectors |
  463. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  464. | bool **any** ( vec_bool_type ) | Any component is true |
  465. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  466. | bool **all** ( vec_bool_type ) | All components are true |
  467. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  468. | bool **not** ( vec_bool_type ) | No components are true |
  469. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  470. | ivec2 **textureSize** ( sampler2D_type s, int lod ) | Get the size of a texture |
  471. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  472. | ivec2 **textureSize** ( samplerCube s, int lod ) | Get the size of a cubemap |
  473. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  474. | vec4_type **texture** ( sampler2D_type s, vec2 uv [, float bias] ) | Perform a 2D texture read |
  475. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  476. | vec4_type **texture** ( samplerCube s, vec3 uv [, float bias] ) | Perform a Cube texture read |
  477. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  478. | vec4_type **textureProj** ( sampler2D_type s, vec3 uv [, float bias] ) | Perform a texture read with projection |
  479. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  480. | vec4_type **textureProj** ( sampler2D_type s, vec4 uv [, float bias] ) | Perform a texture read with projection |
  481. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  482. | vec4_type **textureLod** ( sampler2D_type s, vec2 uv, float lod ) | Perform a 2D texture read at custom mipmap |
  483. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  484. | vec4_type **textureLod** ( samplerCube s, vec3 uv, float lod ) | Perform a Cube texture read at custom mipmap |
  485. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  486. | vec4_type **textureProjLod** ( sampler2D_type s, vec3 uv, float lod ) | Perform a texture read with projection/lod |
  487. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  488. | vec4_type **textureProjLod** ( sampler2D_type s, vec4 uv, float lod ) | Perform a texture read with projection/lod |
  489. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  490. | vec4_type **texelFetch** ( sampler2D_type s, ivec2 uv, int lod ) | Fetch a single texel using integer coords |
  491. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  492. | vec_type **dFdx** ( vec_type ) | Derivative in x using local differencing |
  493. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  494. | vec_type **dFdy** ( vec_type ) | Derivative in y using local differencing |
  495. +-----------------------------------------------------------------------------------------------+------------------------------------------------+
  496. | vec_type **fwidth** ( vec_type ) | Sum of absolute derivative in x and y |
  497. +-----------------------------------------------------------------------------------------------+------------------------------------------------+