mx_noise.js 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327
  1. // Three.js Transpiler
  2. // https://raw.githubusercontent.com/AcademySoftwareFoundation/MaterialX/main/libraries/stdlib/genglsl/lib/mx_noise.glsl
  3. import { int, uint, float, vec3, bool, uvec3, vec2, vec4, If, tslFn } from '../../shadernode/ShaderNode.js';
  4. import { cond } from '../../math/CondNode.js';
  5. import { sub, mul } from '../../math/OperatorNode.js';
  6. import { floor, abs, max, dot, min, sqrt } from '../../math/MathNode.js';
  7. import { overloadingFn } from '../../utils/FunctionOverloadingNode.js';
  8. import { loop } from '../../utils/LoopNode.js';
  9. export const mx_select = /*#__PURE__*/ tslFn( ( [ b_immutable, t_immutable, f_immutable ] ) => {
  10. const f = float( f_immutable ).toVar();
  11. const t = float( t_immutable ).toVar();
  12. const b = bool( b_immutable ).toVar();
  13. return cond( b, t, f );
  14. } ).setLayout( {
  15. name: 'mx_select',
  16. type: 'float',
  17. inputs: [
  18. { name: 'b', type: 'bool' },
  19. { name: 't', type: 'float' },
  20. { name: 'f', type: 'float' }
  21. ]
  22. } );
  23. export const mx_negate_if = /*#__PURE__*/ tslFn( ( [ val_immutable, b_immutable ] ) => {
  24. const b = bool( b_immutable ).toVar();
  25. const val = float( val_immutable ).toVar();
  26. return cond( b, val.negate(), val );
  27. } ).setLayout( {
  28. name: 'mx_negate_if',
  29. type: 'float',
  30. inputs: [
  31. { name: 'val', type: 'float' },
  32. { name: 'b', type: 'bool' }
  33. ]
  34. } );
  35. export const mx_floor = /*#__PURE__*/ tslFn( ( [ x_immutable ] ) => {
  36. const x = float( x_immutable ).toVar();
  37. return int( floor( x ) );
  38. } ).setLayout( {
  39. name: 'mx_floor',
  40. type: 'int',
  41. inputs: [
  42. { name: 'x', type: 'float' }
  43. ]
  44. } );
  45. export const mx_floorfrac = /*#__PURE__*/ tslFn( ( [ x_immutable, i ] ) => {
  46. const x = float( x_immutable ).toVar();
  47. i.assign( mx_floor( x ) );
  48. return x.sub( float( i ) );
  49. } );
  50. export const mx_bilerp_0 = /*#__PURE__*/ tslFn( ( [ v0_immutable, v1_immutable, v2_immutable, v3_immutable, s_immutable, t_immutable ] ) => {
  51. const t = float( t_immutable ).toVar();
  52. const s = float( s_immutable ).toVar();
  53. const v3 = float( v3_immutable ).toVar();
  54. const v2 = float( v2_immutable ).toVar();
  55. const v1 = float( v1_immutable ).toVar();
  56. const v0 = float( v0_immutable ).toVar();
  57. const s1 = float( sub( 1.0, s ) ).toVar();
  58. return sub( 1.0, t ).mul( v0.mul( s1 ).add( v1.mul( s ) ) ).add( t.mul( v2.mul( s1 ).add( v3.mul( s ) ) ) );
  59. } ).setLayout( {
  60. name: 'mx_bilerp_0',
  61. type: 'float',
  62. inputs: [
  63. { name: 'v0', type: 'float' },
  64. { name: 'v1', type: 'float' },
  65. { name: 'v2', type: 'float' },
  66. { name: 'v3', type: 'float' },
  67. { name: 's', type: 'float' },
  68. { name: 't', type: 'float' }
  69. ]
  70. } );
  71. export const mx_bilerp_1 = /*#__PURE__*/ tslFn( ( [ v0_immutable, v1_immutable, v2_immutable, v3_immutable, s_immutable, t_immutable ] ) => {
  72. const t = float( t_immutable ).toVar();
  73. const s = float( s_immutable ).toVar();
  74. const v3 = vec3( v3_immutable ).toVar();
  75. const v2 = vec3( v2_immutable ).toVar();
  76. const v1 = vec3( v1_immutable ).toVar();
  77. const v0 = vec3( v0_immutable ).toVar();
  78. const s1 = float( sub( 1.0, s ) ).toVar();
  79. return sub( 1.0, t ).mul( v0.mul( s1 ).add( v1.mul( s ) ) ).add( t.mul( v2.mul( s1 ).add( v3.mul( s ) ) ) );
  80. } ).setLayout( {
  81. name: 'mx_bilerp_1',
  82. type: 'vec3',
  83. inputs: [
  84. { name: 'v0', type: 'vec3' },
  85. { name: 'v1', type: 'vec3' },
  86. { name: 'v2', type: 'vec3' },
  87. { name: 'v3', type: 'vec3' },
  88. { name: 's', type: 'float' },
  89. { name: 't', type: 'float' }
  90. ]
  91. } );
  92. export const mx_bilerp = /*#__PURE__*/ overloadingFn( [ mx_bilerp_0, mx_bilerp_1 ] );
  93. export const mx_trilerp_0 = /*#__PURE__*/ tslFn( ( [ v0_immutable, v1_immutable, v2_immutable, v3_immutable, v4_immutable, v5_immutable, v6_immutable, v7_immutable, s_immutable, t_immutable, r_immutable ] ) => {
  94. const r = float( r_immutable ).toVar();
  95. const t = float( t_immutable ).toVar();
  96. const s = float( s_immutable ).toVar();
  97. const v7 = float( v7_immutable ).toVar();
  98. const v6 = float( v6_immutable ).toVar();
  99. const v5 = float( v5_immutable ).toVar();
  100. const v4 = float( v4_immutable ).toVar();
  101. const v3 = float( v3_immutable ).toVar();
  102. const v2 = float( v2_immutable ).toVar();
  103. const v1 = float( v1_immutable ).toVar();
  104. const v0 = float( v0_immutable ).toVar();
  105. const s1 = float( sub( 1.0, s ) ).toVar();
  106. const t1 = float( sub( 1.0, t ) ).toVar();
  107. const r1 = float( sub( 1.0, r ) ).toVar();
  108. return r1.mul( t1.mul( v0.mul( s1 ).add( v1.mul( s ) ) ).add( t.mul( v2.mul( s1 ).add( v3.mul( s ) ) ) ) ).add( r.mul( t1.mul( v4.mul( s1 ).add( v5.mul( s ) ) ).add( t.mul( v6.mul( s1 ).add( v7.mul( s ) ) ) ) ) );
  109. } ).setLayout( {
  110. name: 'mx_trilerp_0',
  111. type: 'float',
  112. inputs: [
  113. { name: 'v0', type: 'float' },
  114. { name: 'v1', type: 'float' },
  115. { name: 'v2', type: 'float' },
  116. { name: 'v3', type: 'float' },
  117. { name: 'v4', type: 'float' },
  118. { name: 'v5', type: 'float' },
  119. { name: 'v6', type: 'float' },
  120. { name: 'v7', type: 'float' },
  121. { name: 's', type: 'float' },
  122. { name: 't', type: 'float' },
  123. { name: 'r', type: 'float' }
  124. ]
  125. } );
  126. export const mx_trilerp_1 = /*#__PURE__*/ tslFn( ( [ v0_immutable, v1_immutable, v2_immutable, v3_immutable, v4_immutable, v5_immutable, v6_immutable, v7_immutable, s_immutable, t_immutable, r_immutable ] ) => {
  127. const r = float( r_immutable ).toVar();
  128. const t = float( t_immutable ).toVar();
  129. const s = float( s_immutable ).toVar();
  130. const v7 = vec3( v7_immutable ).toVar();
  131. const v6 = vec3( v6_immutable ).toVar();
  132. const v5 = vec3( v5_immutable ).toVar();
  133. const v4 = vec3( v4_immutable ).toVar();
  134. const v3 = vec3( v3_immutable ).toVar();
  135. const v2 = vec3( v2_immutable ).toVar();
  136. const v1 = vec3( v1_immutable ).toVar();
  137. const v0 = vec3( v0_immutable ).toVar();
  138. const s1 = float( sub( 1.0, s ) ).toVar();
  139. const t1 = float( sub( 1.0, t ) ).toVar();
  140. const r1 = float( sub( 1.0, r ) ).toVar();
  141. return r1.mul( t1.mul( v0.mul( s1 ).add( v1.mul( s ) ) ).add( t.mul( v2.mul( s1 ).add( v3.mul( s ) ) ) ) ).add( r.mul( t1.mul( v4.mul( s1 ).add( v5.mul( s ) ) ).add( t.mul( v6.mul( s1 ).add( v7.mul( s ) ) ) ) ) );
  142. } ).setLayout( {
  143. name: 'mx_trilerp_1',
  144. type: 'vec3',
  145. inputs: [
  146. { name: 'v0', type: 'vec3' },
  147. { name: 'v1', type: 'vec3' },
  148. { name: 'v2', type: 'vec3' },
  149. { name: 'v3', type: 'vec3' },
  150. { name: 'v4', type: 'vec3' },
  151. { name: 'v5', type: 'vec3' },
  152. { name: 'v6', type: 'vec3' },
  153. { name: 'v7', type: 'vec3' },
  154. { name: 's', type: 'float' },
  155. { name: 't', type: 'float' },
  156. { name: 'r', type: 'float' }
  157. ]
  158. } );
  159. export const mx_trilerp = /*#__PURE__*/ overloadingFn( [ mx_trilerp_0, mx_trilerp_1 ] );
  160. export const mx_gradient_float_0 = /*#__PURE__*/ tslFn( ( [ hash_immutable, x_immutable, y_immutable ] ) => {
  161. const y = float( y_immutable ).toVar();
  162. const x = float( x_immutable ).toVar();
  163. const hash = uint( hash_immutable ).toVar();
  164. const h = uint( hash.bitAnd( uint( 7 ) ) ).toVar();
  165. const u = float( mx_select( h.lessThan( uint( 4 ) ), x, y ) ).toVar();
  166. const v = float( mul( 2.0, mx_select( h.lessThan( uint( 4 ) ), y, x ) ) ).toVar();
  167. return mx_negate_if( u, bool( h.bitAnd( uint( 1 ) ) ) ).add( mx_negate_if( v, bool( h.bitAnd( uint( 2 ) ) ) ) );
  168. } ).setLayout( {
  169. name: 'mx_gradient_float_0',
  170. type: 'float',
  171. inputs: [
  172. { name: 'hash', type: 'uint' },
  173. { name: 'x', type: 'float' },
  174. { name: 'y', type: 'float' }
  175. ]
  176. } );
  177. export const mx_gradient_float_1 = /*#__PURE__*/ tslFn( ( [ hash_immutable, x_immutable, y_immutable, z_immutable ] ) => {
  178. const z = float( z_immutable ).toVar();
  179. const y = float( y_immutable ).toVar();
  180. const x = float( x_immutable ).toVar();
  181. const hash = uint( hash_immutable ).toVar();
  182. const h = uint( hash.bitAnd( uint( 15 ) ) ).toVar();
  183. const u = float( mx_select( h.lessThan( uint( 8 ) ), x, y ) ).toVar();
  184. const v = float( mx_select( h.lessThan( uint( 4 ) ), y, mx_select( h.equal( uint( 12 ) ).or( h.equal( uint( 14 ) ) ), x, z ) ) ).toVar();
  185. return mx_negate_if( u, bool( h.bitAnd( uint( 1 ) ) ) ).add( mx_negate_if( v, bool( h.bitAnd( uint( 2 ) ) ) ) );
  186. } ).setLayout( {
  187. name: 'mx_gradient_float_1',
  188. type: 'float',
  189. inputs: [
  190. { name: 'hash', type: 'uint' },
  191. { name: 'x', type: 'float' },
  192. { name: 'y', type: 'float' },
  193. { name: 'z', type: 'float' }
  194. ]
  195. } );
  196. export const mx_gradient_float = /*#__PURE__*/ overloadingFn( [ mx_gradient_float_0, mx_gradient_float_1 ] );
  197. export const mx_gradient_vec3_0 = /*#__PURE__*/ tslFn( ( [ hash_immutable, x_immutable, y_immutable ] ) => {
  198. const y = float( y_immutable ).toVar();
  199. const x = float( x_immutable ).toVar();
  200. const hash = uvec3( hash_immutable ).toVar();
  201. return vec3( mx_gradient_float( hash.x, x, y ), mx_gradient_float( hash.y, x, y ), mx_gradient_float( hash.z, x, y ) );
  202. } ).setLayout( {
  203. name: 'mx_gradient_vec3_0',
  204. type: 'vec3',
  205. inputs: [
  206. { name: 'hash', type: 'uvec3' },
  207. { name: 'x', type: 'float' },
  208. { name: 'y', type: 'float' }
  209. ]
  210. } );
  211. export const mx_gradient_vec3_1 = /*#__PURE__*/ tslFn( ( [ hash_immutable, x_immutable, y_immutable, z_immutable ] ) => {
  212. const z = float( z_immutable ).toVar();
  213. const y = float( y_immutable ).toVar();
  214. const x = float( x_immutable ).toVar();
  215. const hash = uvec3( hash_immutable ).toVar();
  216. return vec3( mx_gradient_float( hash.x, x, y, z ), mx_gradient_float( hash.y, x, y, z ), mx_gradient_float( hash.z, x, y, z ) );
  217. } ).setLayout( {
  218. name: 'mx_gradient_vec3_1',
  219. type: 'vec3',
  220. inputs: [
  221. { name: 'hash', type: 'uvec3' },
  222. { name: 'x', type: 'float' },
  223. { name: 'y', type: 'float' },
  224. { name: 'z', type: 'float' }
  225. ]
  226. } );
  227. export const mx_gradient_vec3 = /*#__PURE__*/ overloadingFn( [ mx_gradient_vec3_0, mx_gradient_vec3_1 ] );
  228. export const mx_gradient_scale2d_0 = /*#__PURE__*/ tslFn( ( [ v_immutable ] ) => {
  229. const v = float( v_immutable ).toVar();
  230. return mul( 0.6616, v );
  231. } ).setLayout( {
  232. name: 'mx_gradient_scale2d_0',
  233. type: 'float',
  234. inputs: [
  235. { name: 'v', type: 'float' }
  236. ]
  237. } );
  238. export const mx_gradient_scale3d_0 = /*#__PURE__*/ tslFn( ( [ v_immutable ] ) => {
  239. const v = float( v_immutable ).toVar();
  240. return mul( 0.9820, v );
  241. } ).setLayout( {
  242. name: 'mx_gradient_scale3d_0',
  243. type: 'float',
  244. inputs: [
  245. { name: 'v', type: 'float' }
  246. ]
  247. } );
  248. export const mx_gradient_scale2d_1 = /*#__PURE__*/ tslFn( ( [ v_immutable ] ) => {
  249. const v = vec3( v_immutable ).toVar();
  250. return mul( 0.6616, v );
  251. } ).setLayout( {
  252. name: 'mx_gradient_scale2d_1',
  253. type: 'vec3',
  254. inputs: [
  255. { name: 'v', type: 'vec3' }
  256. ]
  257. } );
  258. export const mx_gradient_scale2d = /*#__PURE__*/ overloadingFn( [ mx_gradient_scale2d_0, mx_gradient_scale2d_1 ] );
  259. export const mx_gradient_scale3d_1 = /*#__PURE__*/ tslFn( ( [ v_immutable ] ) => {
  260. const v = vec3( v_immutable ).toVar();
  261. return mul( 0.9820, v );
  262. } ).setLayout( {
  263. name: 'mx_gradient_scale3d_1',
  264. type: 'vec3',
  265. inputs: [
  266. { name: 'v', type: 'vec3' }
  267. ]
  268. } );
  269. export const mx_gradient_scale3d = /*#__PURE__*/ overloadingFn( [ mx_gradient_scale3d_0, mx_gradient_scale3d_1 ] );
  270. export const mx_rotl32 = /*#__PURE__*/ tslFn( ( [ x_immutable, k_immutable ] ) => {
  271. const k = int( k_immutable ).toVar();
  272. const x = uint( x_immutable ).toVar();
  273. return x.shiftLeft( k ).bitOr( x.shiftRight( int( 32 ).sub( k ) ) );
  274. } ).setLayout( {
  275. name: 'mx_rotl32',
  276. type: 'uint',
  277. inputs: [
  278. { name: 'x', type: 'uint' },
  279. { name: 'k', type: 'int' }
  280. ]
  281. } );
  282. export const mx_bjmix = /*#__PURE__*/ tslFn( ( [ a, b, c ] ) => {
  283. a.subAssign( c );
  284. a.bitXorAssign( mx_rotl32( c, int( 4 ) ) );
  285. c.addAssign( b );
  286. b.subAssign( a );
  287. b.bitXorAssign( mx_rotl32( a, int( 6 ) ) );
  288. a.addAssign( c );
  289. c.subAssign( b );
  290. c.bitXorAssign( mx_rotl32( b, int( 8 ) ) );
  291. b.addAssign( a );
  292. a.subAssign( c );
  293. a.bitXorAssign( mx_rotl32( c, int( 16 ) ) );
  294. c.addAssign( b );
  295. b.subAssign( a );
  296. b.bitXorAssign( mx_rotl32( a, int( 19 ) ) );
  297. a.addAssign( c );
  298. c.subAssign( b );
  299. c.bitXorAssign( mx_rotl32( b, int( 4 ) ) );
  300. b.addAssign( a );
  301. } );
  302. export const mx_bjfinal = /*#__PURE__*/ tslFn( ( [ a_immutable, b_immutable, c_immutable ] ) => {
  303. const c = uint( c_immutable ).toVar();
  304. const b = uint( b_immutable ).toVar();
  305. const a = uint( a_immutable ).toVar();
  306. c.bitXorAssign( b );
  307. c.subAssign( mx_rotl32( b, int( 14 ) ) );
  308. a.bitXorAssign( c );
  309. a.subAssign( mx_rotl32( c, int( 11 ) ) );
  310. b.bitXorAssign( a );
  311. b.subAssign( mx_rotl32( a, int( 25 ) ) );
  312. c.bitXorAssign( b );
  313. c.subAssign( mx_rotl32( b, int( 16 ) ) );
  314. a.bitXorAssign( c );
  315. a.subAssign( mx_rotl32( c, int( 4 ) ) );
  316. b.bitXorAssign( a );
  317. b.subAssign( mx_rotl32( a, int( 14 ) ) );
  318. c.bitXorAssign( b );
  319. c.subAssign( mx_rotl32( b, int( 24 ) ) );
  320. return c;
  321. } ).setLayout( {
  322. name: 'mx_bjfinal',
  323. type: 'uint',
  324. inputs: [
  325. { name: 'a', type: 'uint' },
  326. { name: 'b', type: 'uint' },
  327. { name: 'c', type: 'uint' }
  328. ]
  329. } );
  330. export const mx_bits_to_01 = /*#__PURE__*/ tslFn( ( [ bits_immutable ] ) => {
  331. const bits = uint( bits_immutable ).toVar();
  332. return float( bits ).div( float( uint( int( 0xffffffff ) ) ) );
  333. } ).setLayout( {
  334. name: 'mx_bits_to_01',
  335. type: 'float',
  336. inputs: [
  337. { name: 'bits', type: 'uint' }
  338. ]
  339. } );
  340. export const mx_fade = /*#__PURE__*/ tslFn( ( [ t_immutable ] ) => {
  341. const t = float( t_immutable ).toVar();
  342. return t.mul( t ).mul( t ).mul( t.mul( t.mul( 6.0 ).sub( 15.0 ) ).add( 10.0 ) );
  343. } ).setLayout( {
  344. name: 'mx_fade',
  345. type: 'float',
  346. inputs: [
  347. { name: 't', type: 'float' }
  348. ]
  349. } );
  350. export const mx_hash_int_0 = /*#__PURE__*/ tslFn( ( [ x_immutable ] ) => {
  351. const x = int( x_immutable ).toVar();
  352. const len = uint( uint( 1 ) ).toVar();
  353. const seed = uint( uint( int( 0xdeadbeef ) ).add( len.shiftLeft( uint( 2 ) ) ).add( uint( 13 ) ) ).toVar();
  354. return mx_bjfinal( seed.add( uint( x ) ), seed, seed );
  355. } ).setLayout( {
  356. name: 'mx_hash_int_0',
  357. type: 'uint',
  358. inputs: [
  359. { name: 'x', type: 'int' }
  360. ]
  361. } );
  362. export const mx_hash_int_1 = /*#__PURE__*/ tslFn( ( [ x_immutable, y_immutable ] ) => {
  363. const y = int( y_immutable ).toVar();
  364. const x = int( x_immutable ).toVar();
  365. const len = uint( uint( 2 ) ).toVar();
  366. const a = uint().toVar(), b = uint().toVar(), c = uint().toVar();
  367. a.assign( b.assign( c.assign( uint( int( 0xdeadbeef ) ).add( len.shiftLeft( uint( 2 ) ) ).add( uint( 13 ) ) ) ) );
  368. a.addAssign( uint( x ) );
  369. b.addAssign( uint( y ) );
  370. return mx_bjfinal( a, b, c );
  371. } ).setLayout( {
  372. name: 'mx_hash_int_1',
  373. type: 'uint',
  374. inputs: [
  375. { name: 'x', type: 'int' },
  376. { name: 'y', type: 'int' }
  377. ]
  378. } );
  379. export const mx_hash_int_2 = /*#__PURE__*/ tslFn( ( [ x_immutable, y_immutable, z_immutable ] ) => {
  380. const z = int( z_immutable ).toVar();
  381. const y = int( y_immutable ).toVar();
  382. const x = int( x_immutable ).toVar();
  383. const len = uint( uint( 3 ) ).toVar();
  384. const a = uint().toVar(), b = uint().toVar(), c = uint().toVar();
  385. a.assign( b.assign( c.assign( uint( int( 0xdeadbeef ) ).add( len.shiftLeft( uint( 2 ) ) ).add( uint( 13 ) ) ) ) );
  386. a.addAssign( uint( x ) );
  387. b.addAssign( uint( y ) );
  388. c.addAssign( uint( z ) );
  389. return mx_bjfinal( a, b, c );
  390. } ).setLayout( {
  391. name: 'mx_hash_int_2',
  392. type: 'uint',
  393. inputs: [
  394. { name: 'x', type: 'int' },
  395. { name: 'y', type: 'int' },
  396. { name: 'z', type: 'int' }
  397. ]
  398. } );
  399. export const mx_hash_int_3 = /*#__PURE__*/ tslFn( ( [ x_immutable, y_immutable, z_immutable, xx_immutable ] ) => {
  400. const xx = int( xx_immutable ).toVar();
  401. const z = int( z_immutable ).toVar();
  402. const y = int( y_immutable ).toVar();
  403. const x = int( x_immutable ).toVar();
  404. const len = uint( uint( 4 ) ).toVar();
  405. const a = uint().toVar(), b = uint().toVar(), c = uint().toVar();
  406. a.assign( b.assign( c.assign( uint( int( 0xdeadbeef ) ).add( len.shiftLeft( uint( 2 ) ) ).add( uint( 13 ) ) ) ) );
  407. a.addAssign( uint( x ) );
  408. b.addAssign( uint( y ) );
  409. c.addAssign( uint( z ) );
  410. mx_bjmix( a, b, c );
  411. a.addAssign( uint( xx ) );
  412. return mx_bjfinal( a, b, c );
  413. } ).setLayout( {
  414. name: 'mx_hash_int_3',
  415. type: 'uint',
  416. inputs: [
  417. { name: 'x', type: 'int' },
  418. { name: 'y', type: 'int' },
  419. { name: 'z', type: 'int' },
  420. { name: 'xx', type: 'int' }
  421. ]
  422. } );
  423. export const mx_hash_int_4 = /*#__PURE__*/ tslFn( ( [ x_immutable, y_immutable, z_immutable, xx_immutable, yy_immutable ] ) => {
  424. const yy = int( yy_immutable ).toVar();
  425. const xx = int( xx_immutable ).toVar();
  426. const z = int( z_immutable ).toVar();
  427. const y = int( y_immutable ).toVar();
  428. const x = int( x_immutable ).toVar();
  429. const len = uint( uint( 5 ) ).toVar();
  430. const a = uint().toVar(), b = uint().toVar(), c = uint().toVar();
  431. a.assign( b.assign( c.assign( uint( int( 0xdeadbeef ) ).add( len.shiftLeft( uint( 2 ) ) ).add( uint( 13 ) ) ) ) );
  432. a.addAssign( uint( x ) );
  433. b.addAssign( uint( y ) );
  434. c.addAssign( uint( z ) );
  435. mx_bjmix( a, b, c );
  436. a.addAssign( uint( xx ) );
  437. b.addAssign( uint( yy ) );
  438. return mx_bjfinal( a, b, c );
  439. } ).setLayout( {
  440. name: 'mx_hash_int_4',
  441. type: 'uint',
  442. inputs: [
  443. { name: 'x', type: 'int' },
  444. { name: 'y', type: 'int' },
  445. { name: 'z', type: 'int' },
  446. { name: 'xx', type: 'int' },
  447. { name: 'yy', type: 'int' }
  448. ]
  449. } );
  450. export const mx_hash_int = /*#__PURE__*/ overloadingFn( [ mx_hash_int_0, mx_hash_int_1, mx_hash_int_2, mx_hash_int_3, mx_hash_int_4 ] );
  451. export const mx_hash_vec3_0 = /*#__PURE__*/ tslFn( ( [ x_immutable, y_immutable ] ) => {
  452. const y = int( y_immutable ).toVar();
  453. const x = int( x_immutable ).toVar();
  454. const h = uint( mx_hash_int( x, y ) ).toVar();
  455. const result = uvec3().toVar();
  456. result.x.assign( h.bitAnd( int( 0xFF ) ) );
  457. result.y.assign( h.shiftRight( int( 8 ) ).bitAnd( int( 0xFF ) ) );
  458. result.z.assign( h.shiftRight( int( 16 ) ).bitAnd( int( 0xFF ) ) );
  459. return result;
  460. } ).setLayout( {
  461. name: 'mx_hash_vec3_0',
  462. type: 'uvec3',
  463. inputs: [
  464. { name: 'x', type: 'int' },
  465. { name: 'y', type: 'int' }
  466. ]
  467. } );
  468. export const mx_hash_vec3_1 = /*#__PURE__*/ tslFn( ( [ x_immutable, y_immutable, z_immutable ] ) => {
  469. const z = int( z_immutable ).toVar();
  470. const y = int( y_immutable ).toVar();
  471. const x = int( x_immutable ).toVar();
  472. const h = uint( mx_hash_int( x, y, z ) ).toVar();
  473. const result = uvec3().toVar();
  474. result.x.assign( h.bitAnd( int( 0xFF ) ) );
  475. result.y.assign( h.shiftRight( int( 8 ) ).bitAnd( int( 0xFF ) ) );
  476. result.z.assign( h.shiftRight( int( 16 ) ).bitAnd( int( 0xFF ) ) );
  477. return result;
  478. } ).setLayout( {
  479. name: 'mx_hash_vec3_1',
  480. type: 'uvec3',
  481. inputs: [
  482. { name: 'x', type: 'int' },
  483. { name: 'y', type: 'int' },
  484. { name: 'z', type: 'int' }
  485. ]
  486. } );
  487. export const mx_hash_vec3 = /*#__PURE__*/ overloadingFn( [ mx_hash_vec3_0, mx_hash_vec3_1 ] );
  488. export const mx_perlin_noise_float_0 = /*#__PURE__*/ tslFn( ( [ p_immutable ] ) => {
  489. const p = vec2( p_immutable ).toVar();
  490. const X = int().toVar(), Y = int().toVar();
  491. const fx = float( mx_floorfrac( p.x, X ) ).toVar();
  492. const fy = float( mx_floorfrac( p.y, Y ) ).toVar();
  493. const u = float( mx_fade( fx ) ).toVar();
  494. const v = float( mx_fade( fy ) ).toVar();
  495. const result = float( mx_bilerp( mx_gradient_float( mx_hash_int( X, Y ), fx, fy ), mx_gradient_float( mx_hash_int( X.add( int( 1 ) ), Y ), fx.sub( 1.0 ), fy ), mx_gradient_float( mx_hash_int( X, Y.add( int( 1 ) ) ), fx, fy.sub( 1.0 ) ), mx_gradient_float( mx_hash_int( X.add( int( 1 ) ), Y.add( int( 1 ) ) ), fx.sub( 1.0 ), fy.sub( 1.0 ) ), u, v ) ).toVar();
  496. return mx_gradient_scale2d( result );
  497. } ).setLayout( {
  498. name: 'mx_perlin_noise_float_0',
  499. type: 'float',
  500. inputs: [
  501. { name: 'p', type: 'vec2' }
  502. ]
  503. } );
  504. export const mx_perlin_noise_float_1 = /*#__PURE__*/ tslFn( ( [ p_immutable ] ) => {
  505. const p = vec3( p_immutable ).toVar();
  506. const X = int().toVar(), Y = int().toVar(), Z = int().toVar();
  507. const fx = float( mx_floorfrac( p.x, X ) ).toVar();
  508. const fy = float( mx_floorfrac( p.y, Y ) ).toVar();
  509. const fz = float( mx_floorfrac( p.z, Z ) ).toVar();
  510. const u = float( mx_fade( fx ) ).toVar();
  511. const v = float( mx_fade( fy ) ).toVar();
  512. const w = float( mx_fade( fz ) ).toVar();
  513. const result = float( mx_trilerp( mx_gradient_float( mx_hash_int( X, Y, Z ), fx, fy, fz ), mx_gradient_float( mx_hash_int( X.add( int( 1 ) ), Y, Z ), fx.sub( 1.0 ), fy, fz ), mx_gradient_float( mx_hash_int( X, Y.add( int( 1 ) ), Z ), fx, fy.sub( 1.0 ), fz ), mx_gradient_float( mx_hash_int( X.add( int( 1 ) ), Y.add( int( 1 ) ), Z ), fx.sub( 1.0 ), fy.sub( 1.0 ), fz ), mx_gradient_float( mx_hash_int( X, Y, Z.add( int( 1 ) ) ), fx, fy, fz.sub( 1.0 ) ), mx_gradient_float( mx_hash_int( X.add( int( 1 ) ), Y, Z.add( int( 1 ) ) ), fx.sub( 1.0 ), fy, fz.sub( 1.0 ) ), mx_gradient_float( mx_hash_int( X, Y.add( int( 1 ) ), Z.add( int( 1 ) ) ), fx, fy.sub( 1.0 ), fz.sub( 1.0 ) ), mx_gradient_float( mx_hash_int( X.add( int( 1 ) ), Y.add( int( 1 ) ), Z.add( int( 1 ) ) ), fx.sub( 1.0 ), fy.sub( 1.0 ), fz.sub( 1.0 ) ), u, v, w ) ).toVar();
  514. return mx_gradient_scale3d( result );
  515. } ).setLayout( {
  516. name: 'mx_perlin_noise_float_1',
  517. type: 'float',
  518. inputs: [
  519. { name: 'p', type: 'vec3' }
  520. ]
  521. } );
  522. export const mx_perlin_noise_float = /*#__PURE__*/ overloadingFn( [ mx_perlin_noise_float_0, mx_perlin_noise_float_1 ] );
  523. export const mx_perlin_noise_vec3_0 = /*#__PURE__*/ tslFn( ( [ p_immutable ] ) => {
  524. const p = vec2( p_immutable ).toVar();
  525. const X = int().toVar(), Y = int().toVar();
  526. const fx = float( mx_floorfrac( p.x, X ) ).toVar();
  527. const fy = float( mx_floorfrac( p.y, Y ) ).toVar();
  528. const u = float( mx_fade( fx ) ).toVar();
  529. const v = float( mx_fade( fy ) ).toVar();
  530. const result = vec3( mx_bilerp( mx_gradient_vec3( mx_hash_vec3( X, Y ), fx, fy ), mx_gradient_vec3( mx_hash_vec3( X.add( int( 1 ) ), Y ), fx.sub( 1.0 ), fy ), mx_gradient_vec3( mx_hash_vec3( X, Y.add( int( 1 ) ) ), fx, fy.sub( 1.0 ) ), mx_gradient_vec3( mx_hash_vec3( X.add( int( 1 ) ), Y.add( int( 1 ) ) ), fx.sub( 1.0 ), fy.sub( 1.0 ) ), u, v ) ).toVar();
  531. return mx_gradient_scale2d( result );
  532. } ).setLayout( {
  533. name: 'mx_perlin_noise_vec3_0',
  534. type: 'vec3',
  535. inputs: [
  536. { name: 'p', type: 'vec2' }
  537. ]
  538. } );
  539. export const mx_perlin_noise_vec3_1 = /*#__PURE__*/ tslFn( ( [ p_immutable ] ) => {
  540. const p = vec3( p_immutable ).toVar();
  541. const X = int().toVar(), Y = int().toVar(), Z = int().toVar();
  542. const fx = float( mx_floorfrac( p.x, X ) ).toVar();
  543. const fy = float( mx_floorfrac( p.y, Y ) ).toVar();
  544. const fz = float( mx_floorfrac( p.z, Z ) ).toVar();
  545. const u = float( mx_fade( fx ) ).toVar();
  546. const v = float( mx_fade( fy ) ).toVar();
  547. const w = float( mx_fade( fz ) ).toVar();
  548. const result = vec3( mx_trilerp( mx_gradient_vec3( mx_hash_vec3( X, Y, Z ), fx, fy, fz ), mx_gradient_vec3( mx_hash_vec3( X.add( int( 1 ) ), Y, Z ), fx.sub( 1.0 ), fy, fz ), mx_gradient_vec3( mx_hash_vec3( X, Y.add( int( 1 ) ), Z ), fx, fy.sub( 1.0 ), fz ), mx_gradient_vec3( mx_hash_vec3( X.add( int( 1 ) ), Y.add( int( 1 ) ), Z ), fx.sub( 1.0 ), fy.sub( 1.0 ), fz ), mx_gradient_vec3( mx_hash_vec3( X, Y, Z.add( int( 1 ) ) ), fx, fy, fz.sub( 1.0 ) ), mx_gradient_vec3( mx_hash_vec3( X.add( int( 1 ) ), Y, Z.add( int( 1 ) ) ), fx.sub( 1.0 ), fy, fz.sub( 1.0 ) ), mx_gradient_vec3( mx_hash_vec3( X, Y.add( int( 1 ) ), Z.add( int( 1 ) ) ), fx, fy.sub( 1.0 ), fz.sub( 1.0 ) ), mx_gradient_vec3( mx_hash_vec3( X.add( int( 1 ) ), Y.add( int( 1 ) ), Z.add( int( 1 ) ) ), fx.sub( 1.0 ), fy.sub( 1.0 ), fz.sub( 1.0 ) ), u, v, w ) ).toVar();
  549. return mx_gradient_scale3d( result );
  550. } ).setLayout( {
  551. name: 'mx_perlin_noise_vec3_1',
  552. type: 'vec3',
  553. inputs: [
  554. { name: 'p', type: 'vec3' }
  555. ]
  556. } );
  557. export const mx_perlin_noise_vec3 = /*#__PURE__*/ overloadingFn( [ mx_perlin_noise_vec3_0, mx_perlin_noise_vec3_1 ] );
  558. export const mx_cell_noise_float_0 = /*#__PURE__*/ tslFn( ( [ p_immutable ] ) => {
  559. const p = float( p_immutable ).toVar();
  560. const ix = int( mx_floor( p ) ).toVar();
  561. return mx_bits_to_01( mx_hash_int( ix ) );
  562. } ).setLayout( {
  563. name: 'mx_cell_noise_float_0',
  564. type: 'float',
  565. inputs: [
  566. { name: 'p', type: 'float' }
  567. ]
  568. } );
  569. export const mx_cell_noise_float_1 = /*#__PURE__*/ tslFn( ( [ p_immutable ] ) => {
  570. const p = vec2( p_immutable ).toVar();
  571. const ix = int( mx_floor( p.x ) ).toVar();
  572. const iy = int( mx_floor( p.y ) ).toVar();
  573. return mx_bits_to_01( mx_hash_int( ix, iy ) );
  574. } ).setLayout( {
  575. name: 'mx_cell_noise_float_1',
  576. type: 'float',
  577. inputs: [
  578. { name: 'p', type: 'vec2' }
  579. ]
  580. } );
  581. export const mx_cell_noise_float_2 = /*#__PURE__*/ tslFn( ( [ p_immutable ] ) => {
  582. const p = vec3( p_immutable ).toVar();
  583. const ix = int( mx_floor( p.x ) ).toVar();
  584. const iy = int( mx_floor( p.y ) ).toVar();
  585. const iz = int( mx_floor( p.z ) ).toVar();
  586. return mx_bits_to_01( mx_hash_int( ix, iy, iz ) );
  587. } ).setLayout( {
  588. name: 'mx_cell_noise_float_2',
  589. type: 'float',
  590. inputs: [
  591. { name: 'p', type: 'vec3' }
  592. ]
  593. } );
  594. export const mx_cell_noise_float_3 = /*#__PURE__*/ tslFn( ( [ p_immutable ] ) => {
  595. const p = vec4( p_immutable ).toVar();
  596. const ix = int( mx_floor( p.x ) ).toVar();
  597. const iy = int( mx_floor( p.y ) ).toVar();
  598. const iz = int( mx_floor( p.z ) ).toVar();
  599. const iw = int( mx_floor( p.w ) ).toVar();
  600. return mx_bits_to_01( mx_hash_int( ix, iy, iz, iw ) );
  601. } ).setLayout( {
  602. name: 'mx_cell_noise_float_3',
  603. type: 'float',
  604. inputs: [
  605. { name: 'p', type: 'vec4' }
  606. ]
  607. } );
  608. export const mx_cell_noise_float = /*#__PURE__*/ overloadingFn( [ mx_cell_noise_float_0, mx_cell_noise_float_1, mx_cell_noise_float_2, mx_cell_noise_float_3 ] );
  609. export const mx_cell_noise_vec3_0 = /*#__PURE__*/ tslFn( ( [ p_immutable ] ) => {
  610. const p = float( p_immutable ).toVar();
  611. const ix = int( mx_floor( p ) ).toVar();
  612. return vec3( mx_bits_to_01( mx_hash_int( ix, int( 0 ) ) ), mx_bits_to_01( mx_hash_int( ix, int( 1 ) ) ), mx_bits_to_01( mx_hash_int( ix, int( 2 ) ) ) );
  613. } ).setLayout( {
  614. name: 'mx_cell_noise_vec3_0',
  615. type: 'vec3',
  616. inputs: [
  617. { name: 'p', type: 'float' }
  618. ]
  619. } );
  620. export const mx_cell_noise_vec3_1 = /*#__PURE__*/ tslFn( ( [ p_immutable ] ) => {
  621. const p = vec2( p_immutable ).toVar();
  622. const ix = int( mx_floor( p.x ) ).toVar();
  623. const iy = int( mx_floor( p.y ) ).toVar();
  624. return vec3( mx_bits_to_01( mx_hash_int( ix, iy, int( 0 ) ) ), mx_bits_to_01( mx_hash_int( ix, iy, int( 1 ) ) ), mx_bits_to_01( mx_hash_int( ix, iy, int( 2 ) ) ) );
  625. } ).setLayout( {
  626. name: 'mx_cell_noise_vec3_1',
  627. type: 'vec3',
  628. inputs: [
  629. { name: 'p', type: 'vec2' }
  630. ]
  631. } );
  632. export const mx_cell_noise_vec3_2 = /*#__PURE__*/ tslFn( ( [ p_immutable ] ) => {
  633. const p = vec3( p_immutable ).toVar();
  634. const ix = int( mx_floor( p.x ) ).toVar();
  635. const iy = int( mx_floor( p.y ) ).toVar();
  636. const iz = int( mx_floor( p.z ) ).toVar();
  637. return vec3( mx_bits_to_01( mx_hash_int( ix, iy, iz, int( 0 ) ) ), mx_bits_to_01( mx_hash_int( ix, iy, iz, int( 1 ) ) ), mx_bits_to_01( mx_hash_int( ix, iy, iz, int( 2 ) ) ) );
  638. } ).setLayout( {
  639. name: 'mx_cell_noise_vec3_2',
  640. type: 'vec3',
  641. inputs: [
  642. { name: 'p', type: 'vec3' }
  643. ]
  644. } );
  645. export const mx_cell_noise_vec3_3 = /*#__PURE__*/ tslFn( ( [ p_immutable ] ) => {
  646. const p = vec4( p_immutable ).toVar();
  647. const ix = int( mx_floor( p.x ) ).toVar();
  648. const iy = int( mx_floor( p.y ) ).toVar();
  649. const iz = int( mx_floor( p.z ) ).toVar();
  650. const iw = int( mx_floor( p.w ) ).toVar();
  651. return vec3( mx_bits_to_01( mx_hash_int( ix, iy, iz, iw, int( 0 ) ) ), mx_bits_to_01( mx_hash_int( ix, iy, iz, iw, int( 1 ) ) ), mx_bits_to_01( mx_hash_int( ix, iy, iz, iw, int( 2 ) ) ) );
  652. } ).setLayout( {
  653. name: 'mx_cell_noise_vec3_3',
  654. type: 'vec3',
  655. inputs: [
  656. { name: 'p', type: 'vec4' }
  657. ]
  658. } );
  659. export const mx_cell_noise_vec3 = /*#__PURE__*/ overloadingFn( [ mx_cell_noise_vec3_0, mx_cell_noise_vec3_1, mx_cell_noise_vec3_2, mx_cell_noise_vec3_3 ] );
  660. export const mx_fractal_noise_float = /*#__PURE__*/ tslFn( ( [ p_immutable, octaves_immutable, lacunarity_immutable, diminish_immutable ] ) => {
  661. const diminish = float( diminish_immutable ).toVar();
  662. const lacunarity = float( lacunarity_immutable ).toVar();
  663. const octaves = int( octaves_immutable ).toVar();
  664. const p = vec3( p_immutable ).toVar();
  665. const result = float( 0.0 ).toVar();
  666. const amplitude = float( 1.0 ).toVar();
  667. loop( { start: int( 0 ), end: octaves }, ( { i } ) => {
  668. result.addAssign( amplitude.mul( mx_perlin_noise_float( p ) ) );
  669. amplitude.mulAssign( diminish );
  670. p.mulAssign( lacunarity );
  671. } );
  672. return result;
  673. } ).setLayout( {
  674. name: 'mx_fractal_noise_float',
  675. type: 'float',
  676. inputs: [
  677. { name: 'p', type: 'vec3' },
  678. { name: 'octaves', type: 'int' },
  679. { name: 'lacunarity', type: 'float' },
  680. { name: 'diminish', type: 'float' }
  681. ]
  682. } );
  683. export const mx_fractal_noise_vec3 = /*#__PURE__*/ tslFn( ( [ p_immutable, octaves_immutable, lacunarity_immutable, diminish_immutable ] ) => {
  684. const diminish = float( diminish_immutable ).toVar();
  685. const lacunarity = float( lacunarity_immutable ).toVar();
  686. const octaves = int( octaves_immutable ).toVar();
  687. const p = vec3( p_immutable ).toVar();
  688. const result = vec3( 0.0 ).toVar();
  689. const amplitude = float( 1.0 ).toVar();
  690. loop( { start: int( 0 ), end: octaves }, ( { i } ) => {
  691. result.addAssign( amplitude.mul( mx_perlin_noise_vec3( p ) ) );
  692. amplitude.mulAssign( diminish );
  693. p.mulAssign( lacunarity );
  694. } );
  695. return result;
  696. } ).setLayout( {
  697. name: 'mx_fractal_noise_vec3',
  698. type: 'vec3',
  699. inputs: [
  700. { name: 'p', type: 'vec3' },
  701. { name: 'octaves', type: 'int' },
  702. { name: 'lacunarity', type: 'float' },
  703. { name: 'diminish', type: 'float' }
  704. ]
  705. } );
  706. export const mx_fractal_noise_vec2 = /*#__PURE__*/ tslFn( ( [ p_immutable, octaves_immutable, lacunarity_immutable, diminish_immutable ] ) => {
  707. const diminish = float( diminish_immutable ).toVar();
  708. const lacunarity = float( lacunarity_immutable ).toVar();
  709. const octaves = int( octaves_immutable ).toVar();
  710. const p = vec3( p_immutable ).toVar();
  711. return vec2( mx_fractal_noise_float( p, octaves, lacunarity, diminish ), mx_fractal_noise_float( p.add( vec3( int( 19 ), int( 193 ), int( 17 ) ) ), octaves, lacunarity, diminish ) );
  712. } ).setLayout( {
  713. name: 'mx_fractal_noise_vec2',
  714. type: 'vec2',
  715. inputs: [
  716. { name: 'p', type: 'vec3' },
  717. { name: 'octaves', type: 'int' },
  718. { name: 'lacunarity', type: 'float' },
  719. { name: 'diminish', type: 'float' }
  720. ]
  721. } );
  722. export const mx_fractal_noise_vec4 = /*#__PURE__*/ tslFn( ( [ p_immutable, octaves_immutable, lacunarity_immutable, diminish_immutable ] ) => {
  723. const diminish = float( diminish_immutable ).toVar();
  724. const lacunarity = float( lacunarity_immutable ).toVar();
  725. const octaves = int( octaves_immutable ).toVar();
  726. const p = vec3( p_immutable ).toVar();
  727. const c = vec3( mx_fractal_noise_vec3( p, octaves, lacunarity, diminish ) ).toVar();
  728. const f = float( mx_fractal_noise_float( p.add( vec3( int( 19 ), int( 193 ), int( 17 ) ) ), octaves, lacunarity, diminish ) ).toVar();
  729. return vec4( c, f );
  730. } ).setLayout( {
  731. name: 'mx_fractal_noise_vec4',
  732. type: 'vec4',
  733. inputs: [
  734. { name: 'p', type: 'vec3' },
  735. { name: 'octaves', type: 'int' },
  736. { name: 'lacunarity', type: 'float' },
  737. { name: 'diminish', type: 'float' }
  738. ]
  739. } );
  740. export const mx_worley_distance_0 = /*#__PURE__*/ tslFn( ( [ p_immutable, x_immutable, y_immutable, xoff_immutable, yoff_immutable, jitter_immutable, metric_immutable ] ) => {
  741. const metric = int( metric_immutable ).toVar();
  742. const jitter = float( jitter_immutable ).toVar();
  743. const yoff = int( yoff_immutable ).toVar();
  744. const xoff = int( xoff_immutable ).toVar();
  745. const y = int( y_immutable ).toVar();
  746. const x = int( x_immutable ).toVar();
  747. const p = vec2( p_immutable ).toVar();
  748. const tmp = vec3( mx_cell_noise_vec3( vec2( x.add( xoff ), y.add( yoff ) ) ) ).toVar();
  749. const off = vec2( tmp.x, tmp.y ).toVar();
  750. off.subAssign( 0.5 );
  751. off.mulAssign( jitter );
  752. off.addAssign( 0.5 );
  753. const cellpos = vec2( vec2( float( x ), float( y ) ).add( off ) ).toVar();
  754. const diff = vec2( cellpos.sub( p ) ).toVar();
  755. If( metric.equal( int( 2 ) ), () => {
  756. return abs( diff.x ).add( abs( diff.y ) );
  757. } );
  758. If( metric.equal( int( 3 ) ), () => {
  759. return max( abs( diff.x ), abs( diff.y ) );
  760. } );
  761. return dot( diff, diff );
  762. } ).setLayout( {
  763. name: 'mx_worley_distance_0',
  764. type: 'float',
  765. inputs: [
  766. { name: 'p', type: 'vec2' },
  767. { name: 'x', type: 'int' },
  768. { name: 'y', type: 'int' },
  769. { name: 'xoff', type: 'int' },
  770. { name: 'yoff', type: 'int' },
  771. { name: 'jitter', type: 'float' },
  772. { name: 'metric', type: 'int' }
  773. ]
  774. } );
  775. export const mx_worley_distance_1 = /*#__PURE__*/ tslFn( ( [ p_immutable, x_immutable, y_immutable, z_immutable, xoff_immutable, yoff_immutable, zoff_immutable, jitter_immutable, metric_immutable ] ) => {
  776. const metric = int( metric_immutable ).toVar();
  777. const jitter = float( jitter_immutable ).toVar();
  778. const zoff = int( zoff_immutable ).toVar();
  779. const yoff = int( yoff_immutable ).toVar();
  780. const xoff = int( xoff_immutable ).toVar();
  781. const z = int( z_immutable ).toVar();
  782. const y = int( y_immutable ).toVar();
  783. const x = int( x_immutable ).toVar();
  784. const p = vec3( p_immutable ).toVar();
  785. const off = vec3( mx_cell_noise_vec3( vec3( x.add( xoff ), y.add( yoff ), z.add( zoff ) ) ) ).toVar();
  786. off.subAssign( 0.5 );
  787. off.mulAssign( jitter );
  788. off.addAssign( 0.5 );
  789. const cellpos = vec3( vec3( float( x ), float( y ), float( z ) ).add( off ) ).toVar();
  790. const diff = vec3( cellpos.sub( p ) ).toVar();
  791. If( metric.equal( int( 2 ) ), () => {
  792. return abs( diff.x ).add( abs( diff.y ) ).add( abs( diff.z ) );
  793. } );
  794. If( metric.equal( int( 3 ) ), () => {
  795. return max( max( abs( diff.x ), abs( diff.y ) ), abs( diff.z ) );
  796. } );
  797. return dot( diff, diff );
  798. } ).setLayout( {
  799. name: 'mx_worley_distance_1',
  800. type: 'float',
  801. inputs: [
  802. { name: 'p', type: 'vec3' },
  803. { name: 'x', type: 'int' },
  804. { name: 'y', type: 'int' },
  805. { name: 'z', type: 'int' },
  806. { name: 'xoff', type: 'int' },
  807. { name: 'yoff', type: 'int' },
  808. { name: 'zoff', type: 'int' },
  809. { name: 'jitter', type: 'float' },
  810. { name: 'metric', type: 'int' }
  811. ]
  812. } );
  813. export const mx_worley_distance = /*#__PURE__*/ overloadingFn( [ mx_worley_distance_0, mx_worley_distance_1 ] );
  814. export const mx_worley_noise_float_0 = /*#__PURE__*/ tslFn( ( [ p_immutable, jitter_immutable, metric_immutable ] ) => {
  815. const metric = int( metric_immutable ).toVar();
  816. const jitter = float( jitter_immutable ).toVar();
  817. const p = vec2( p_immutable ).toVar();
  818. const X = int().toVar(), Y = int().toVar();
  819. const localpos = vec2( mx_floorfrac( p.x, X ), mx_floorfrac( p.y, Y ) ).toVar();
  820. const sqdist = float( 1e6 ).toVar();
  821. loop( { start: - 1, end: int( 1 ), name: 'x', condition: '<=' }, ( { x } ) => {
  822. loop( { start: - 1, end: int( 1 ), name: 'y', condition: '<=' }, ( { y } ) => {
  823. const dist = float( mx_worley_distance( localpos, x, y, X, Y, jitter, metric ) ).toVar();
  824. sqdist.assign( min( sqdist, dist ) );
  825. } );
  826. } );
  827. If( metric.equal( int( 0 ) ), () => {
  828. sqdist.assign( sqrt( sqdist ) );
  829. } );
  830. return sqdist;
  831. } ).setLayout( {
  832. name: 'mx_worley_noise_float_0',
  833. type: 'float',
  834. inputs: [
  835. { name: 'p', type: 'vec2' },
  836. { name: 'jitter', type: 'float' },
  837. { name: 'metric', type: 'int' }
  838. ]
  839. } );
  840. export const mx_worley_noise_vec2_0 = /*#__PURE__*/ tslFn( ( [ p_immutable, jitter_immutable, metric_immutable ] ) => {
  841. const metric = int( metric_immutable ).toVar();
  842. const jitter = float( jitter_immutable ).toVar();
  843. const p = vec2( p_immutable ).toVar();
  844. const X = int().toVar(), Y = int().toVar();
  845. const localpos = vec2( mx_floorfrac( p.x, X ), mx_floorfrac( p.y, Y ) ).toVar();
  846. const sqdist = vec2( 1e6, 1e6 ).toVar();
  847. loop( { start: - 1, end: int( 1 ), name: 'x', condition: '<=' }, ( { x } ) => {
  848. loop( { start: - 1, end: int( 1 ), name: 'y', condition: '<=' }, ( { y } ) => {
  849. const dist = float( mx_worley_distance( localpos, x, y, X, Y, jitter, metric ) ).toVar();
  850. If( dist.lessThan( sqdist.x ), () => {
  851. sqdist.y.assign( sqdist.x );
  852. sqdist.x.assign( dist );
  853. } ).elseif( dist.lessThan( sqdist.y ), () => {
  854. sqdist.y.assign( dist );
  855. } );
  856. } );
  857. } );
  858. If( metric.equal( int( 0 ) ), () => {
  859. sqdist.assign( sqrt( sqdist ) );
  860. } );
  861. return sqdist;
  862. } ).setLayout( {
  863. name: 'mx_worley_noise_vec2_0',
  864. type: 'vec2',
  865. inputs: [
  866. { name: 'p', type: 'vec2' },
  867. { name: 'jitter', type: 'float' },
  868. { name: 'metric', type: 'int' }
  869. ]
  870. } );
  871. export const mx_worley_noise_vec3_0 = /*#__PURE__*/ tslFn( ( [ p_immutable, jitter_immutable, metric_immutable ] ) => {
  872. const metric = int( metric_immutable ).toVar();
  873. const jitter = float( jitter_immutable ).toVar();
  874. const p = vec2( p_immutable ).toVar();
  875. const X = int().toVar(), Y = int().toVar();
  876. const localpos = vec2( mx_floorfrac( p.x, X ), mx_floorfrac( p.y, Y ) ).toVar();
  877. const sqdist = vec3( 1e6, 1e6, 1e6 ).toVar();
  878. loop( { start: - 1, end: int( 1 ), name: 'x', condition: '<=' }, ( { x } ) => {
  879. loop( { start: - 1, end: int( 1 ), name: 'y', condition: '<=' }, ( { y } ) => {
  880. const dist = float( mx_worley_distance( localpos, x, y, X, Y, jitter, metric ) ).toVar();
  881. If( dist.lessThan( sqdist.x ), () => {
  882. sqdist.z.assign( sqdist.y );
  883. sqdist.y.assign( sqdist.x );
  884. sqdist.x.assign( dist );
  885. } ).elseif( dist.lessThan( sqdist.y ), () => {
  886. sqdist.z.assign( sqdist.y );
  887. sqdist.y.assign( dist );
  888. } ).elseif( dist.lessThan( sqdist.z ), () => {
  889. sqdist.z.assign( dist );
  890. } );
  891. } );
  892. } );
  893. If( metric.equal( int( 0 ) ), () => {
  894. sqdist.assign( sqrt( sqdist ) );
  895. } );
  896. return sqdist;
  897. } ).setLayout( {
  898. name: 'mx_worley_noise_vec3_0',
  899. type: 'vec3',
  900. inputs: [
  901. { name: 'p', type: 'vec2' },
  902. { name: 'jitter', type: 'float' },
  903. { name: 'metric', type: 'int' }
  904. ]
  905. } );
  906. export const mx_worley_noise_float_1 = /*#__PURE__*/ tslFn( ( [ p_immutable, jitter_immutable, metric_immutable ] ) => {
  907. const metric = int( metric_immutable ).toVar();
  908. const jitter = float( jitter_immutable ).toVar();
  909. const p = vec3( p_immutable ).toVar();
  910. const X = int().toVar(), Y = int().toVar(), Z = int().toVar();
  911. const localpos = vec3( mx_floorfrac( p.x, X ), mx_floorfrac( p.y, Y ), mx_floorfrac( p.z, Z ) ).toVar();
  912. const sqdist = float( 1e6 ).toVar();
  913. loop( { start: - 1, end: int( 1 ), name: 'x', condition: '<=' }, ( { x } ) => {
  914. loop( { start: - 1, end: int( 1 ), name: 'y', condition: '<=' }, ( { y } ) => {
  915. loop( { start: - 1, end: int( 1 ), name: 'z', condition: '<=' }, ( { z } ) => {
  916. const dist = float( mx_worley_distance( localpos, x, y, z, X, Y, Z, jitter, metric ) ).toVar();
  917. sqdist.assign( min( sqdist, dist ) );
  918. } );
  919. } );
  920. } );
  921. If( metric.equal( int( 0 ) ), () => {
  922. sqdist.assign( sqrt( sqdist ) );
  923. } );
  924. return sqdist;
  925. } ).setLayout( {
  926. name: 'mx_worley_noise_float_1',
  927. type: 'float',
  928. inputs: [
  929. { name: 'p', type: 'vec3' },
  930. { name: 'jitter', type: 'float' },
  931. { name: 'metric', type: 'int' }
  932. ]
  933. } );
  934. export const mx_worley_noise_float = /*#__PURE__*/ overloadingFn( [ mx_worley_noise_float_0, mx_worley_noise_float_1 ] );
  935. export const mx_worley_noise_vec2_1 = /*#__PURE__*/ tslFn( ( [ p_immutable, jitter_immutable, metric_immutable ] ) => {
  936. const metric = int( metric_immutable ).toVar();
  937. const jitter = float( jitter_immutable ).toVar();
  938. const p = vec3( p_immutable ).toVar();
  939. const X = int().toVar(), Y = int().toVar(), Z = int().toVar();
  940. const localpos = vec3( mx_floorfrac( p.x, X ), mx_floorfrac( p.y, Y ), mx_floorfrac( p.z, Z ) ).toVar();
  941. const sqdist = vec2( 1e6, 1e6 ).toVar();
  942. loop( { start: - 1, end: int( 1 ), name: 'x', condition: '<=' }, ( { x } ) => {
  943. loop( { start: - 1, end: int( 1 ), name: 'y', condition: '<=' }, ( { y } ) => {
  944. loop( { start: - 1, end: int( 1 ), name: 'z', condition: '<=' }, ( { z } ) => {
  945. const dist = float( mx_worley_distance( localpos, x, y, z, X, Y, Z, jitter, metric ) ).toVar();
  946. If( dist.lessThan( sqdist.x ), () => {
  947. sqdist.y.assign( sqdist.x );
  948. sqdist.x.assign( dist );
  949. } ).elseif( dist.lessThan( sqdist.y ), () => {
  950. sqdist.y.assign( dist );
  951. } );
  952. } );
  953. } );
  954. } );
  955. If( metric.equal( int( 0 ) ), () => {
  956. sqdist.assign( sqrt( sqdist ) );
  957. } );
  958. return sqdist;
  959. } ).setLayout( {
  960. name: 'mx_worley_noise_vec2_1',
  961. type: 'vec2',
  962. inputs: [
  963. { name: 'p', type: 'vec3' },
  964. { name: 'jitter', type: 'float' },
  965. { name: 'metric', type: 'int' }
  966. ]
  967. } );
  968. export const mx_worley_noise_vec2 = /*#__PURE__*/ overloadingFn( [ mx_worley_noise_vec2_0, mx_worley_noise_vec2_1 ] );
  969. export const mx_worley_noise_vec3_1 = /*#__PURE__*/ tslFn( ( [ p_immutable, jitter_immutable, metric_immutable ] ) => {
  970. const metric = int( metric_immutable ).toVar();
  971. const jitter = float( jitter_immutable ).toVar();
  972. const p = vec3( p_immutable ).toVar();
  973. const X = int().toVar(), Y = int().toVar(), Z = int().toVar();
  974. const localpos = vec3( mx_floorfrac( p.x, X ), mx_floorfrac( p.y, Y ), mx_floorfrac( p.z, Z ) ).toVar();
  975. const sqdist = vec3( 1e6, 1e6, 1e6 ).toVar();
  976. loop( { start: - 1, end: int( 1 ), name: 'x', condition: '<=' }, ( { x } ) => {
  977. loop( { start: - 1, end: int( 1 ), name: 'y', condition: '<=' }, ( { y } ) => {
  978. loop( { start: - 1, end: int( 1 ), name: 'z', condition: '<=' }, ( { z } ) => {
  979. const dist = float( mx_worley_distance( localpos, x, y, z, X, Y, Z, jitter, metric ) ).toVar();
  980. If( dist.lessThan( sqdist.x ), () => {
  981. sqdist.z.assign( sqdist.y );
  982. sqdist.y.assign( sqdist.x );
  983. sqdist.x.assign( dist );
  984. } ).elseif( dist.lessThan( sqdist.y ), () => {
  985. sqdist.z.assign( sqdist.y );
  986. sqdist.y.assign( dist );
  987. } ).elseif( dist.lessThan( sqdist.z ), () => {
  988. sqdist.z.assign( dist );
  989. } );
  990. } );
  991. } );
  992. } );
  993. If( metric.equal( int( 0 ) ), () => {
  994. sqdist.assign( sqrt( sqdist ) );
  995. } );
  996. return sqdist;
  997. } ).setLayout( {
  998. name: 'mx_worley_noise_vec3_1',
  999. type: 'vec3',
  1000. inputs: [
  1001. { name: 'p', type: 'vec3' },
  1002. { name: 'jitter', type: 'float' },
  1003. { name: 'metric', type: 'int' }
  1004. ]
  1005. } );
  1006. export const mx_worley_noise_vec3 = /*#__PURE__*/ overloadingFn( [ mx_worley_noise_vec3_0, mx_worley_noise_vec3_1 ] );