mx_noise.js 41 KB

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