fastnoiselite-builder 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ANoiseBuilder-CexggqMu.js +2326 -0
- package/dist/index.js +924 -3226
- package/dist/tsl/builder/TSLNoiseBuilder2D.d.ts +19 -0
- package/dist/tsl/builder/TSLNoiseBuilder3D.d.ts +36 -0
- package/dist/tsl/builder/index.d.ts +2 -0
- package/dist/tsl/index.d.ts +3 -0
- package/dist/tsl/index.js +2998 -0
- package/dist/tsl/transform/transform3d.tsl.d.ts +6 -0
- package/dist/tsl/wgsl/constants.d.ts +16 -0
- package/dist/tsl/wgsl/fractal/fbm.wgsl.d.ts +10 -0
- package/dist/tsl/wgsl/fractal/index.d.ts +3 -0
- package/dist/tsl/wgsl/fractal/pingpong.wgsl.d.ts +10 -0
- package/dist/tsl/wgsl/fractal/ridged.wgsl.d.ts +10 -0
- package/dist/tsl/wgsl/helpers.d.ts +6 -0
- package/dist/tsl/wgsl/noise/cellular.wgsl.d.ts +28 -0
- package/dist/tsl/wgsl/noise/index.d.ts +6 -0
- package/dist/tsl/wgsl/noise/opensimplex2.wgsl.d.ts +24 -0
- package/dist/tsl/wgsl/noise/opensimplex2s.wgsl.d.ts +24 -0
- package/dist/tsl/wgsl/noise/perlin.wgsl.d.ts +23 -0
- package/dist/tsl/wgsl/noise/value-cubic.wgsl.d.ts +23 -0
- package/dist/tsl/wgsl/noise/value.wgsl.d.ts +23 -0
- package/dist/tsl/wgsl/warp/basic-grid.wgsl.d.ts +15 -0
- package/dist/tsl/wgsl/warp/index.d.ts +2 -0
- package/dist/tsl/wgsl/warp/opensimplex2.wgsl.d.ts +19 -0
- package/package.json +18 -3
|
@@ -0,0 +1,2998 @@
|
|
|
1
|
+
import { wgslFn as L } from "three/tsl";
|
|
2
|
+
import { P as A, b as G, c as X, G as Ne, i as Ie, R as Se, f as $e, C as M, e as C, A as fe, D as h, F as _, j as w, N as f, T as m } from "../ANoiseBuilder-CexggqMu.js";
|
|
3
|
+
import { k as ga } from "../ANoiseBuilder-CexggqMu.js";
|
|
4
|
+
function E() {
|
|
5
|
+
return `const PRIME_X: i32 = ${A};
|
|
6
|
+
const PRIME_Y: i32 = ${G};
|
|
7
|
+
const PRIME_Z: i32 = ${X};`;
|
|
8
|
+
}
|
|
9
|
+
function Y(d, e) {
|
|
10
|
+
const t = Array.from(e).map((i) => {
|
|
11
|
+
const a = i.toString();
|
|
12
|
+
return a.includes(".") || a.includes("e") ? a : a + ".0";
|
|
13
|
+
}).join(", ");
|
|
14
|
+
return `const ${d}: array<f32, ${e.length}> = array<f32, ${e.length}>(${t});`;
|
|
15
|
+
}
|
|
16
|
+
function W() {
|
|
17
|
+
return Y("GRADIENTS_2D", Ne);
|
|
18
|
+
}
|
|
19
|
+
function j() {
|
|
20
|
+
return Y("GRADIENTS_3D", Ie);
|
|
21
|
+
}
|
|
22
|
+
function ce() {
|
|
23
|
+
return Y("RAND_VECS_2D", Se);
|
|
24
|
+
}
|
|
25
|
+
function ue() {
|
|
26
|
+
return Y("RAND_VECS_3D", $e);
|
|
27
|
+
}
|
|
28
|
+
function N() {
|
|
29
|
+
return `fn imul(a: i32, b: i32) -> i32 {
|
|
30
|
+
return i32(u32(a) * u32(b));
|
|
31
|
+
}`;
|
|
32
|
+
}
|
|
33
|
+
function I() {
|
|
34
|
+
return `fn hashR2(seed: i32, xPrimed: i32, yPrimed: i32) -> i32 {
|
|
35
|
+
return i32(u32(seed ^ xPrimed ^ yPrimed) * 0x27d4eb2du);
|
|
36
|
+
}`;
|
|
37
|
+
}
|
|
38
|
+
function S() {
|
|
39
|
+
return `fn hashR3(seed: i32, xPrimed: i32, yPrimed: i32, zPrimed: i32) -> i32 {
|
|
40
|
+
return i32(u32(seed ^ xPrimed ^ yPrimed ^ zPrimed) * 0x27d4eb2du);
|
|
41
|
+
}`;
|
|
42
|
+
}
|
|
43
|
+
function O() {
|
|
44
|
+
return `fn valCoordR2(seed: i32, xPrimed: i32, yPrimed: i32) -> f32 {
|
|
45
|
+
var uh = u32(hashR2(seed, xPrimed, yPrimed));
|
|
46
|
+
uh = uh * uh;
|
|
47
|
+
uh = uh ^ (uh << 19u);
|
|
48
|
+
return f32(i32(uh)) * (1.0 / 2147483648.0);
|
|
49
|
+
}`;
|
|
50
|
+
}
|
|
51
|
+
function q() {
|
|
52
|
+
return `fn valCoordR3(seed: i32, xPrimed: i32, yPrimed: i32, zPrimed: i32) -> f32 {
|
|
53
|
+
var uh = u32(hashR3(seed, xPrimed, yPrimed, zPrimed));
|
|
54
|
+
uh = uh * uh;
|
|
55
|
+
uh = uh ^ (uh << 19u);
|
|
56
|
+
return f32(i32(uh)) * (1.0 / 2147483648.0);
|
|
57
|
+
}`;
|
|
58
|
+
}
|
|
59
|
+
function V() {
|
|
60
|
+
return `fn gradCoordR2(seed: i32, xPrimed: i32, yPrimed: i32, xd: f32, yd: f32) -> f32 {
|
|
61
|
+
var hash = hashR2(seed, xPrimed, yPrimed);
|
|
62
|
+
hash = hash ^ (hash >> 15u);
|
|
63
|
+
hash = hash & 254;
|
|
64
|
+
let xg = GRADIENTS_2D[hash];
|
|
65
|
+
let yg = GRADIENTS_2D[hash | 1];
|
|
66
|
+
return xd * xg + yd * yg;
|
|
67
|
+
}`;
|
|
68
|
+
}
|
|
69
|
+
function F() {
|
|
70
|
+
return `fn gradCoordR3(seed: i32, xPrimed: i32, yPrimed: i32, zPrimed: i32, xd: f32, yd: f32, zd: f32) -> f32 {
|
|
71
|
+
var hash = hashR3(seed, xPrimed, yPrimed, zPrimed);
|
|
72
|
+
hash = hash ^ (hash >> 15u);
|
|
73
|
+
hash = hash & 252;
|
|
74
|
+
let xg = GRADIENTS_3D[hash];
|
|
75
|
+
let yg = GRADIENTS_3D[hash | 1];
|
|
76
|
+
let zg = GRADIENTS_3D[hash | 2];
|
|
77
|
+
return xd * xg + yd * yg + zd * zg;
|
|
78
|
+
}`;
|
|
79
|
+
}
|
|
80
|
+
function J() {
|
|
81
|
+
return `fn interpHermite(t: f32) -> f32 {
|
|
82
|
+
return t * t * (3.0 - 2.0 * t);
|
|
83
|
+
}`;
|
|
84
|
+
}
|
|
85
|
+
function Q() {
|
|
86
|
+
return `fn interpQuintic(t: f32) -> f32 {
|
|
87
|
+
return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);
|
|
88
|
+
}`;
|
|
89
|
+
}
|
|
90
|
+
function U() {
|
|
91
|
+
return `fn cubicLerp(a: f32, b: f32, c: f32, d: f32, t: f32) -> f32 {
|
|
92
|
+
let p = d - c - (a - b);
|
|
93
|
+
return t * t * t * p + t * t * (a - b - p) + t * (c - a) + b;
|
|
94
|
+
}`;
|
|
95
|
+
}
|
|
96
|
+
function K() {
|
|
97
|
+
return `fn pingPong(t_in: f32) -> f32 {
|
|
98
|
+
var t = t_in - trunc(t_in * 0.5) * 2.0;
|
|
99
|
+
return select(2.0 - t, t, t < 1.0);
|
|
100
|
+
}`;
|
|
101
|
+
}
|
|
102
|
+
function ke() {
|
|
103
|
+
return `
|
|
104
|
+
${E()}
|
|
105
|
+
${I()}
|
|
106
|
+
${O()}
|
|
107
|
+
${J()}
|
|
108
|
+
|
|
109
|
+
fn value2d(seed: i32, x: f32, y: f32) -> f32 {
|
|
110
|
+
let x0i = i32(floor(x));
|
|
111
|
+
let y0i = i32(floor(y));
|
|
112
|
+
|
|
113
|
+
let xs = interpHermite(x - f32(x0i));
|
|
114
|
+
let ys = interpHermite(y - f32(y0i));
|
|
115
|
+
|
|
116
|
+
let x0 = x0i * PRIME_X;
|
|
117
|
+
let y0 = y0i * PRIME_Y;
|
|
118
|
+
let x1 = x0 + PRIME_X;
|
|
119
|
+
let y1 = y0 + PRIME_Y;
|
|
120
|
+
|
|
121
|
+
let xf0 = mix(valCoordR2(seed, x0, y0), valCoordR2(seed, x1, y0), xs);
|
|
122
|
+
let xf1 = mix(valCoordR2(seed, x0, y1), valCoordR2(seed, x1, y1), xs);
|
|
123
|
+
|
|
124
|
+
return mix(xf0, xf1, ys);
|
|
125
|
+
}
|
|
126
|
+
`;
|
|
127
|
+
}
|
|
128
|
+
function be() {
|
|
129
|
+
return `
|
|
130
|
+
${E()}
|
|
131
|
+
${S()}
|
|
132
|
+
${q()}
|
|
133
|
+
${J()}
|
|
134
|
+
|
|
135
|
+
fn value3d(seed: i32, x: f32, y: f32, z: f32) -> f32 {
|
|
136
|
+
let x0i = i32(floor(x));
|
|
137
|
+
let y0i = i32(floor(y));
|
|
138
|
+
let z0i = i32(floor(z));
|
|
139
|
+
|
|
140
|
+
let xs = interpHermite(x - f32(x0i));
|
|
141
|
+
let ys = interpHermite(y - f32(y0i));
|
|
142
|
+
let zs = interpHermite(z - f32(z0i));
|
|
143
|
+
|
|
144
|
+
let x0 = x0i * PRIME_X;
|
|
145
|
+
let y0 = y0i * PRIME_Y;
|
|
146
|
+
let z0 = z0i * PRIME_Z;
|
|
147
|
+
let x1 = x0 + PRIME_X;
|
|
148
|
+
let y1 = y0 + PRIME_Y;
|
|
149
|
+
let z1 = z0 + PRIME_Z;
|
|
150
|
+
|
|
151
|
+
let xf00 = mix(valCoordR3(seed, x0, y0, z0), valCoordR3(seed, x1, y0, z0), xs);
|
|
152
|
+
let xf10 = mix(valCoordR3(seed, x0, y1, z0), valCoordR3(seed, x1, y1, z0), xs);
|
|
153
|
+
let xf01 = mix(valCoordR3(seed, x0, y0, z1), valCoordR3(seed, x1, y0, z1), xs);
|
|
154
|
+
let xf11 = mix(valCoordR3(seed, x0, y1, z1), valCoordR3(seed, x1, y1, z1), xs);
|
|
155
|
+
|
|
156
|
+
let yf0 = mix(xf00, xf10, ys);
|
|
157
|
+
let yf1 = mix(xf01, xf11, ys);
|
|
158
|
+
|
|
159
|
+
return mix(yf0, yf1, zs);
|
|
160
|
+
}
|
|
161
|
+
`;
|
|
162
|
+
}
|
|
163
|
+
const Le = ["primes", "hashR2", "valCoordR2", "interpHermite"], we = ["primes", "hashR3", "valCoordR3", "interpHermite"];
|
|
164
|
+
function Ae() {
|
|
165
|
+
return `
|
|
166
|
+
fn value2d(seed: i32, x: f32, y: f32) -> f32 {
|
|
167
|
+
let x0i = i32(floor(x));
|
|
168
|
+
let y0i = i32(floor(y));
|
|
169
|
+
|
|
170
|
+
let xs = interpHermite(x - f32(x0i));
|
|
171
|
+
let ys = interpHermite(y - f32(y0i));
|
|
172
|
+
|
|
173
|
+
let x0 = x0i * PRIME_X;
|
|
174
|
+
let y0 = y0i * PRIME_Y;
|
|
175
|
+
let x1 = x0 + PRIME_X;
|
|
176
|
+
let y1 = y0 + PRIME_Y;
|
|
177
|
+
|
|
178
|
+
let xf0 = mix(valCoordR2(seed, x0, y0), valCoordR2(seed, x1, y0), xs);
|
|
179
|
+
let xf1 = mix(valCoordR2(seed, x0, y1), valCoordR2(seed, x1, y1), xs);
|
|
180
|
+
|
|
181
|
+
return mix(xf0, xf1, ys);
|
|
182
|
+
}
|
|
183
|
+
`;
|
|
184
|
+
}
|
|
185
|
+
function Ge() {
|
|
186
|
+
return `
|
|
187
|
+
fn value3d(seed: i32, x: f32, y: f32, z: f32) -> f32 {
|
|
188
|
+
let x0i = i32(floor(x));
|
|
189
|
+
let y0i = i32(floor(y));
|
|
190
|
+
let z0i = i32(floor(z));
|
|
191
|
+
|
|
192
|
+
let xs = interpHermite(x - f32(x0i));
|
|
193
|
+
let ys = interpHermite(y - f32(y0i));
|
|
194
|
+
let zs = interpHermite(z - f32(z0i));
|
|
195
|
+
|
|
196
|
+
let x0 = x0i * PRIME_X;
|
|
197
|
+
let y0 = y0i * PRIME_Y;
|
|
198
|
+
let z0 = z0i * PRIME_Z;
|
|
199
|
+
let x1 = x0 + PRIME_X;
|
|
200
|
+
let y1 = y0 + PRIME_Y;
|
|
201
|
+
let z1 = z0 + PRIME_Z;
|
|
202
|
+
|
|
203
|
+
let xf00 = mix(valCoordR3(seed, x0, y0, z0), valCoordR3(seed, x1, y0, z0), xs);
|
|
204
|
+
let xf10 = mix(valCoordR3(seed, x0, y1, z0), valCoordR3(seed, x1, y1, z0), xs);
|
|
205
|
+
let xf01 = mix(valCoordR3(seed, x0, y0, z1), valCoordR3(seed, x1, y0, z1), xs);
|
|
206
|
+
let xf11 = mix(valCoordR3(seed, x0, y1, z1), valCoordR3(seed, x1, y1, z1), xs);
|
|
207
|
+
|
|
208
|
+
let yf0 = mix(xf00, xf10, ys);
|
|
209
|
+
let yf1 = mix(xf01, xf11, ys);
|
|
210
|
+
|
|
211
|
+
return mix(yf0, yf1, zs);
|
|
212
|
+
}
|
|
213
|
+
`;
|
|
214
|
+
}
|
|
215
|
+
const Xe = ["primes", "gradients2D", "hashR2", "gradCoordR2", "interpQuintic"], Ye = ["primes", "gradients3D", "hashR3", "gradCoordR3", "interpQuintic"];
|
|
216
|
+
function We() {
|
|
217
|
+
return `
|
|
218
|
+
${E()}
|
|
219
|
+
${W()}
|
|
220
|
+
${I()}
|
|
221
|
+
${V()}
|
|
222
|
+
${Q()}
|
|
223
|
+
|
|
224
|
+
fn perlin2d(seed: i32, x: f32, y: f32) -> f32 {
|
|
225
|
+
let x0i = i32(floor(x));
|
|
226
|
+
let y0i = i32(floor(y));
|
|
227
|
+
|
|
228
|
+
let xd0 = x - f32(x0i);
|
|
229
|
+
let yd0 = y - f32(y0i);
|
|
230
|
+
let xd1 = xd0 - 1.0;
|
|
231
|
+
let yd1 = yd0 - 1.0;
|
|
232
|
+
|
|
233
|
+
let xs = interpQuintic(xd0);
|
|
234
|
+
let ys = interpQuintic(yd0);
|
|
235
|
+
|
|
236
|
+
let x0 = x0i * PRIME_X;
|
|
237
|
+
let y0 = y0i * PRIME_Y;
|
|
238
|
+
let x1 = x0 + PRIME_X;
|
|
239
|
+
let y1 = y0 + PRIME_Y;
|
|
240
|
+
|
|
241
|
+
let xf0 = mix(
|
|
242
|
+
gradCoordR2(seed, x0, y0, xd0, yd0),
|
|
243
|
+
gradCoordR2(seed, x1, y0, xd1, yd0),
|
|
244
|
+
xs
|
|
245
|
+
);
|
|
246
|
+
let xf1 = mix(
|
|
247
|
+
gradCoordR2(seed, x0, y1, xd0, yd1),
|
|
248
|
+
gradCoordR2(seed, x1, y1, xd1, yd1),
|
|
249
|
+
xs
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
return mix(xf0, xf1, ys) * 1.4247691104677813;
|
|
253
|
+
}
|
|
254
|
+
`;
|
|
255
|
+
}
|
|
256
|
+
function je() {
|
|
257
|
+
return `
|
|
258
|
+
${E()}
|
|
259
|
+
${j()}
|
|
260
|
+
${S()}
|
|
261
|
+
${F()}
|
|
262
|
+
${Q()}
|
|
263
|
+
|
|
264
|
+
fn perlin3d(seed: i32, x: f32, y: f32, z: f32) -> f32 {
|
|
265
|
+
let x0i = i32(floor(x));
|
|
266
|
+
let y0i = i32(floor(y));
|
|
267
|
+
let z0i = i32(floor(z));
|
|
268
|
+
|
|
269
|
+
let xd0 = x - f32(x0i);
|
|
270
|
+
let yd0 = y - f32(y0i);
|
|
271
|
+
let zd0 = z - f32(z0i);
|
|
272
|
+
let xd1 = xd0 - 1.0;
|
|
273
|
+
let yd1 = yd0 - 1.0;
|
|
274
|
+
let zd1 = zd0 - 1.0;
|
|
275
|
+
|
|
276
|
+
let xs = interpQuintic(xd0);
|
|
277
|
+
let ys = interpQuintic(yd0);
|
|
278
|
+
let zs = interpQuintic(zd0);
|
|
279
|
+
|
|
280
|
+
let x0 = x0i * PRIME_X;
|
|
281
|
+
let y0 = y0i * PRIME_Y;
|
|
282
|
+
let z0 = z0i * PRIME_Z;
|
|
283
|
+
let x1 = x0 + PRIME_X;
|
|
284
|
+
let y1 = y0 + PRIME_Y;
|
|
285
|
+
let z1 = z0 + PRIME_Z;
|
|
286
|
+
|
|
287
|
+
let xf00 = mix(
|
|
288
|
+
gradCoordR3(seed, x0, y0, z0, xd0, yd0, zd0),
|
|
289
|
+
gradCoordR3(seed, x1, y0, z0, xd1, yd0, zd0),
|
|
290
|
+
xs
|
|
291
|
+
);
|
|
292
|
+
let xf10 = mix(
|
|
293
|
+
gradCoordR3(seed, x0, y1, z0, xd0, yd1, zd0),
|
|
294
|
+
gradCoordR3(seed, x1, y1, z0, xd1, yd1, zd0),
|
|
295
|
+
xs
|
|
296
|
+
);
|
|
297
|
+
let xf01 = mix(
|
|
298
|
+
gradCoordR3(seed, x0, y0, z1, xd0, yd0, zd1),
|
|
299
|
+
gradCoordR3(seed, x1, y0, z1, xd1, yd0, zd1),
|
|
300
|
+
xs
|
|
301
|
+
);
|
|
302
|
+
let xf11 = mix(
|
|
303
|
+
gradCoordR3(seed, x0, y1, z1, xd0, yd1, zd1),
|
|
304
|
+
gradCoordR3(seed, x1, y1, z1, xd1, yd1, zd1),
|
|
305
|
+
xs
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
let yf0 = mix(xf00, xf10, ys);
|
|
309
|
+
let yf1 = mix(xf01, xf11, ys);
|
|
310
|
+
|
|
311
|
+
return mix(yf0, yf1, zs) * 0.964921414852142333984375;
|
|
312
|
+
}
|
|
313
|
+
`;
|
|
314
|
+
}
|
|
315
|
+
function Ve() {
|
|
316
|
+
return `fn perlin2d(seed: i32, x: f32, y: f32) -> f32 {
|
|
317
|
+
let x0i = i32(floor(x));
|
|
318
|
+
let y0i = i32(floor(y));
|
|
319
|
+
|
|
320
|
+
let xd0 = x - f32(x0i);
|
|
321
|
+
let yd0 = y - f32(y0i);
|
|
322
|
+
let xd1 = xd0 - 1.0;
|
|
323
|
+
let yd1 = yd0 - 1.0;
|
|
324
|
+
|
|
325
|
+
let xs = interpQuintic(xd0);
|
|
326
|
+
let ys = interpQuintic(yd0);
|
|
327
|
+
|
|
328
|
+
let x0 = x0i * PRIME_X;
|
|
329
|
+
let y0 = y0i * PRIME_Y;
|
|
330
|
+
let x1 = x0 + PRIME_X;
|
|
331
|
+
let y1 = y0 + PRIME_Y;
|
|
332
|
+
|
|
333
|
+
let xf0 = mix(
|
|
334
|
+
gradCoordR2(seed, x0, y0, xd0, yd0),
|
|
335
|
+
gradCoordR2(seed, x1, y0, xd1, yd0),
|
|
336
|
+
xs
|
|
337
|
+
);
|
|
338
|
+
let xf1 = mix(
|
|
339
|
+
gradCoordR2(seed, x0, y1, xd0, yd1),
|
|
340
|
+
gradCoordR2(seed, x1, y1, xd1, yd1),
|
|
341
|
+
xs
|
|
342
|
+
);
|
|
343
|
+
|
|
344
|
+
return mix(xf0, xf1, ys) * 1.4247691104677813;
|
|
345
|
+
}`;
|
|
346
|
+
}
|
|
347
|
+
function Fe() {
|
|
348
|
+
return `fn perlin3d(seed: i32, x: f32, y: f32, z: f32) -> f32 {
|
|
349
|
+
let x0i = i32(floor(x));
|
|
350
|
+
let y0i = i32(floor(y));
|
|
351
|
+
let z0i = i32(floor(z));
|
|
352
|
+
|
|
353
|
+
let xd0 = x - f32(x0i);
|
|
354
|
+
let yd0 = y - f32(y0i);
|
|
355
|
+
let zd0 = z - f32(z0i);
|
|
356
|
+
let xd1 = xd0 - 1.0;
|
|
357
|
+
let yd1 = yd0 - 1.0;
|
|
358
|
+
let zd1 = zd0 - 1.0;
|
|
359
|
+
|
|
360
|
+
let xs = interpQuintic(xd0);
|
|
361
|
+
let ys = interpQuintic(yd0);
|
|
362
|
+
let zs = interpQuintic(zd0);
|
|
363
|
+
|
|
364
|
+
let x0 = x0i * PRIME_X;
|
|
365
|
+
let y0 = y0i * PRIME_Y;
|
|
366
|
+
let z0 = z0i * PRIME_Z;
|
|
367
|
+
let x1 = x0 + PRIME_X;
|
|
368
|
+
let y1 = y0 + PRIME_Y;
|
|
369
|
+
let z1 = z0 + PRIME_Z;
|
|
370
|
+
|
|
371
|
+
let xf00 = mix(
|
|
372
|
+
gradCoordR3(seed, x0, y0, z0, xd0, yd0, zd0),
|
|
373
|
+
gradCoordR3(seed, x1, y0, z0, xd1, yd0, zd0),
|
|
374
|
+
xs
|
|
375
|
+
);
|
|
376
|
+
let xf10 = mix(
|
|
377
|
+
gradCoordR3(seed, x0, y1, z0, xd0, yd1, zd0),
|
|
378
|
+
gradCoordR3(seed, x1, y1, z0, xd1, yd1, zd0),
|
|
379
|
+
xs
|
|
380
|
+
);
|
|
381
|
+
let xf01 = mix(
|
|
382
|
+
gradCoordR3(seed, x0, y0, z1, xd0, yd0, zd1),
|
|
383
|
+
gradCoordR3(seed, x1, y0, z1, xd1, yd0, zd1),
|
|
384
|
+
xs
|
|
385
|
+
);
|
|
386
|
+
let xf11 = mix(
|
|
387
|
+
gradCoordR3(seed, x0, y1, z1, xd0, yd1, zd1),
|
|
388
|
+
gradCoordR3(seed, x1, y1, z1, xd1, yd1, zd1),
|
|
389
|
+
xs
|
|
390
|
+
);
|
|
391
|
+
|
|
392
|
+
let yf0 = mix(xf00, xf10, ys);
|
|
393
|
+
let yf1 = mix(xf01, xf11, ys);
|
|
394
|
+
|
|
395
|
+
return mix(yf0, yf1, zs) * 0.964921414852142333984375;
|
|
396
|
+
}`;
|
|
397
|
+
}
|
|
398
|
+
const Re = A << 1 | 0, _e = G << 1 | 0, Te = X << 1 | 0, Ze = ["primes", "primesDouble", "imul", "hashR2", "valCoordR2", "cubicLerp"], Be = ["primes", "primesDouble", "imul", "hashR3", "valCoordR3", "cubicLerp"];
|
|
399
|
+
function He() {
|
|
400
|
+
return `
|
|
401
|
+
${E()}
|
|
402
|
+
const PRIME_X_2: i32 = ${Re};
|
|
403
|
+
const PRIME_Y_2: i32 = ${_e};
|
|
404
|
+
${N()}
|
|
405
|
+
${I()}
|
|
406
|
+
${O()}
|
|
407
|
+
${U()}
|
|
408
|
+
|
|
409
|
+
fn valuecubic2d(seed: i32, x: f32, y: f32) -> f32 {
|
|
410
|
+
let fx1 = floor(x);
|
|
411
|
+
let fy1 = floor(y);
|
|
412
|
+
let x1i = i32(fx1);
|
|
413
|
+
let y1i = i32(fy1);
|
|
414
|
+
|
|
415
|
+
let xs = x - fx1;
|
|
416
|
+
let ys = y - fy1;
|
|
417
|
+
|
|
418
|
+
let x1 = imul(x1i, PRIME_X);
|
|
419
|
+
let y1 = imul(y1i, PRIME_Y);
|
|
420
|
+
let x0 = x1 - PRIME_X;
|
|
421
|
+
let y0 = y1 - PRIME_Y;
|
|
422
|
+
let x2 = x1 + PRIME_X;
|
|
423
|
+
let y2 = y1 + PRIME_Y;
|
|
424
|
+
let x3 = x1 + PRIME_X_2;
|
|
425
|
+
let y3 = y1 + PRIME_Y_2;
|
|
426
|
+
|
|
427
|
+
return cubicLerp(
|
|
428
|
+
cubicLerp(valCoordR2(seed, x0, y0), valCoordR2(seed, x1, y0), valCoordR2(seed, x2, y0), valCoordR2(seed, x3, y0), xs),
|
|
429
|
+
cubicLerp(valCoordR2(seed, x0, y1), valCoordR2(seed, x1, y1), valCoordR2(seed, x2, y1), valCoordR2(seed, x3, y1), xs),
|
|
430
|
+
cubicLerp(valCoordR2(seed, x0, y2), valCoordR2(seed, x1, y2), valCoordR2(seed, x2, y2), valCoordR2(seed, x3, y2), xs),
|
|
431
|
+
cubicLerp(valCoordR2(seed, x0, y3), valCoordR2(seed, x1, y3), valCoordR2(seed, x2, y3), valCoordR2(seed, x3, y3), xs),
|
|
432
|
+
ys
|
|
433
|
+
) * (1.0 / (1.5 * 1.5));
|
|
434
|
+
}
|
|
435
|
+
`;
|
|
436
|
+
}
|
|
437
|
+
function Oe() {
|
|
438
|
+
return `
|
|
439
|
+
${E()}
|
|
440
|
+
const PRIME_X_2: i32 = ${Re};
|
|
441
|
+
const PRIME_Y_2: i32 = ${_e};
|
|
442
|
+
const PRIME_Z_2: i32 = ${Te};
|
|
443
|
+
${N()}
|
|
444
|
+
${S()}
|
|
445
|
+
${q()}
|
|
446
|
+
${U()}
|
|
447
|
+
|
|
448
|
+
fn valuecubic3d(seed: i32, x: f32, y: f32, z: f32) -> f32 {
|
|
449
|
+
let fx1 = floor(x);
|
|
450
|
+
let fy1 = floor(y);
|
|
451
|
+
let fz1 = floor(z);
|
|
452
|
+
let x1i = i32(fx1);
|
|
453
|
+
let y1i = i32(fy1);
|
|
454
|
+
let z1i = i32(fz1);
|
|
455
|
+
|
|
456
|
+
let xs = x - fx1;
|
|
457
|
+
let ys = y - fy1;
|
|
458
|
+
let zs = z - fz1;
|
|
459
|
+
|
|
460
|
+
let x1 = imul(x1i, PRIME_X);
|
|
461
|
+
let y1 = imul(y1i, PRIME_Y);
|
|
462
|
+
let z1 = imul(z1i, PRIME_Z);
|
|
463
|
+
let x0 = x1 - PRIME_X;
|
|
464
|
+
let y0 = y1 - PRIME_Y;
|
|
465
|
+
let z0 = z1 - PRIME_Z;
|
|
466
|
+
let x2 = x1 + PRIME_X;
|
|
467
|
+
let y2 = y1 + PRIME_Y;
|
|
468
|
+
let z2 = z1 + PRIME_Z;
|
|
469
|
+
let x3 = x1 + PRIME_X_2;
|
|
470
|
+
let y3 = y1 + PRIME_Y_2;
|
|
471
|
+
let z3 = z1 + PRIME_Z_2;
|
|
472
|
+
|
|
473
|
+
return cubicLerp(
|
|
474
|
+
cubicLerp(
|
|
475
|
+
cubicLerp(valCoordR3(seed,x0,y0,z0), valCoordR3(seed,x1,y0,z0), valCoordR3(seed,x2,y0,z0), valCoordR3(seed,x3,y0,z0), xs),
|
|
476
|
+
cubicLerp(valCoordR3(seed,x0,y1,z0), valCoordR3(seed,x1,y1,z0), valCoordR3(seed,x2,y1,z0), valCoordR3(seed,x3,y1,z0), xs),
|
|
477
|
+
cubicLerp(valCoordR3(seed,x0,y2,z0), valCoordR3(seed,x1,y2,z0), valCoordR3(seed,x2,y2,z0), valCoordR3(seed,x3,y2,z0), xs),
|
|
478
|
+
cubicLerp(valCoordR3(seed,x0,y3,z0), valCoordR3(seed,x1,y3,z0), valCoordR3(seed,x2,y3,z0), valCoordR3(seed,x3,y3,z0), xs),
|
|
479
|
+
ys),
|
|
480
|
+
cubicLerp(
|
|
481
|
+
cubicLerp(valCoordR3(seed,x0,y0,z1), valCoordR3(seed,x1,y0,z1), valCoordR3(seed,x2,y0,z1), valCoordR3(seed,x3,y0,z1), xs),
|
|
482
|
+
cubicLerp(valCoordR3(seed,x0,y1,z1), valCoordR3(seed,x1,y1,z1), valCoordR3(seed,x2,y1,z1), valCoordR3(seed,x3,y1,z1), xs),
|
|
483
|
+
cubicLerp(valCoordR3(seed,x0,y2,z1), valCoordR3(seed,x1,y2,z1), valCoordR3(seed,x2,y2,z1), valCoordR3(seed,x3,y2,z1), xs),
|
|
484
|
+
cubicLerp(valCoordR3(seed,x0,y3,z1), valCoordR3(seed,x1,y3,z1), valCoordR3(seed,x2,y3,z1), valCoordR3(seed,x3,y3,z1), xs),
|
|
485
|
+
ys),
|
|
486
|
+
cubicLerp(
|
|
487
|
+
cubicLerp(valCoordR3(seed,x0,y0,z2), valCoordR3(seed,x1,y0,z2), valCoordR3(seed,x2,y0,z2), valCoordR3(seed,x3,y0,z2), xs),
|
|
488
|
+
cubicLerp(valCoordR3(seed,x0,y1,z2), valCoordR3(seed,x1,y1,z2), valCoordR3(seed,x2,y1,z2), valCoordR3(seed,x3,y1,z2), xs),
|
|
489
|
+
cubicLerp(valCoordR3(seed,x0,y2,z2), valCoordR3(seed,x1,y2,z2), valCoordR3(seed,x2,y2,z2), valCoordR3(seed,x3,y2,z2), xs),
|
|
490
|
+
cubicLerp(valCoordR3(seed,x0,y3,z2), valCoordR3(seed,x1,y3,z2), valCoordR3(seed,x2,y3,z2), valCoordR3(seed,x3,y3,z2), xs),
|
|
491
|
+
ys),
|
|
492
|
+
cubicLerp(
|
|
493
|
+
cubicLerp(valCoordR3(seed,x0,y0,z3), valCoordR3(seed,x1,y0,z3), valCoordR3(seed,x2,y0,z3), valCoordR3(seed,x3,y0,z3), xs),
|
|
494
|
+
cubicLerp(valCoordR3(seed,x0,y1,z3), valCoordR3(seed,x1,y1,z3), valCoordR3(seed,x2,y1,z3), valCoordR3(seed,x3,y1,z3), xs),
|
|
495
|
+
cubicLerp(valCoordR3(seed,x0,y2,z3), valCoordR3(seed,x1,y2,z3), valCoordR3(seed,x2,y2,z3), valCoordR3(seed,x3,y2,z3), xs),
|
|
496
|
+
cubicLerp(valCoordR3(seed,x0,y3,z3), valCoordR3(seed,x1,y3,z3), valCoordR3(seed,x2,y3,z3), valCoordR3(seed,x3,y3,z3), xs),
|
|
497
|
+
ys),
|
|
498
|
+
zs
|
|
499
|
+
) * (1.0 / (1.5 * 1.5 * 1.5));
|
|
500
|
+
}
|
|
501
|
+
`;
|
|
502
|
+
}
|
|
503
|
+
function qe() {
|
|
504
|
+
return `
|
|
505
|
+
fn valuecubic2d(seed: i32, x: f32, y: f32) -> f32 {
|
|
506
|
+
let fx1 = floor(x);
|
|
507
|
+
let fy1 = floor(y);
|
|
508
|
+
let x1i = i32(fx1);
|
|
509
|
+
let y1i = i32(fy1);
|
|
510
|
+
|
|
511
|
+
let xs = x - fx1;
|
|
512
|
+
let ys = y - fy1;
|
|
513
|
+
|
|
514
|
+
let x1 = imul(x1i, PRIME_X);
|
|
515
|
+
let y1 = imul(y1i, PRIME_Y);
|
|
516
|
+
let x0 = x1 - PRIME_X;
|
|
517
|
+
let y0 = y1 - PRIME_Y;
|
|
518
|
+
let x2 = x1 + PRIME_X;
|
|
519
|
+
let y2 = y1 + PRIME_Y;
|
|
520
|
+
let x3 = x1 + PRIME_X_2;
|
|
521
|
+
let y3 = y1 + PRIME_Y_2;
|
|
522
|
+
|
|
523
|
+
return cubicLerp(
|
|
524
|
+
cubicLerp(valCoordR2(seed, x0, y0), valCoordR2(seed, x1, y0), valCoordR2(seed, x2, y0), valCoordR2(seed, x3, y0), xs),
|
|
525
|
+
cubicLerp(valCoordR2(seed, x0, y1), valCoordR2(seed, x1, y1), valCoordR2(seed, x2, y1), valCoordR2(seed, x3, y1), xs),
|
|
526
|
+
cubicLerp(valCoordR2(seed, x0, y2), valCoordR2(seed, x1, y2), valCoordR2(seed, x2, y2), valCoordR2(seed, x3, y2), xs),
|
|
527
|
+
cubicLerp(valCoordR2(seed, x0, y3), valCoordR2(seed, x1, y3), valCoordR2(seed, x2, y3), valCoordR2(seed, x3, y3), xs),
|
|
528
|
+
ys
|
|
529
|
+
) * (1.0 / (1.5 * 1.5));
|
|
530
|
+
}
|
|
531
|
+
`;
|
|
532
|
+
}
|
|
533
|
+
function Je() {
|
|
534
|
+
return `
|
|
535
|
+
fn valuecubic3d(seed: i32, x: f32, y: f32, z: f32) -> f32 {
|
|
536
|
+
let fx1 = floor(x);
|
|
537
|
+
let fy1 = floor(y);
|
|
538
|
+
let fz1 = floor(z);
|
|
539
|
+
let x1i = i32(fx1);
|
|
540
|
+
let y1i = i32(fy1);
|
|
541
|
+
let z1i = i32(fz1);
|
|
542
|
+
|
|
543
|
+
let xs = x - fx1;
|
|
544
|
+
let ys = y - fy1;
|
|
545
|
+
let zs = z - fz1;
|
|
546
|
+
|
|
547
|
+
let x1 = imul(x1i, PRIME_X);
|
|
548
|
+
let y1 = imul(y1i, PRIME_Y);
|
|
549
|
+
let z1 = imul(z1i, PRIME_Z);
|
|
550
|
+
let x0 = x1 - PRIME_X;
|
|
551
|
+
let y0 = y1 - PRIME_Y;
|
|
552
|
+
let z0 = z1 - PRIME_Z;
|
|
553
|
+
let x2 = x1 + PRIME_X;
|
|
554
|
+
let y2 = y1 + PRIME_Y;
|
|
555
|
+
let z2 = z1 + PRIME_Z;
|
|
556
|
+
let x3 = x1 + PRIME_X_2;
|
|
557
|
+
let y3 = y1 + PRIME_Y_2;
|
|
558
|
+
let z3 = z1 + PRIME_Z_2;
|
|
559
|
+
|
|
560
|
+
return cubicLerp(
|
|
561
|
+
cubicLerp(
|
|
562
|
+
cubicLerp(valCoordR3(seed,x0,y0,z0), valCoordR3(seed,x1,y0,z0), valCoordR3(seed,x2,y0,z0), valCoordR3(seed,x3,y0,z0), xs),
|
|
563
|
+
cubicLerp(valCoordR3(seed,x0,y1,z0), valCoordR3(seed,x1,y1,z0), valCoordR3(seed,x2,y1,z0), valCoordR3(seed,x3,y1,z0), xs),
|
|
564
|
+
cubicLerp(valCoordR3(seed,x0,y2,z0), valCoordR3(seed,x1,y2,z0), valCoordR3(seed,x2,y2,z0), valCoordR3(seed,x3,y2,z0), xs),
|
|
565
|
+
cubicLerp(valCoordR3(seed,x0,y3,z0), valCoordR3(seed,x1,y3,z0), valCoordR3(seed,x2,y3,z0), valCoordR3(seed,x3,y3,z0), xs),
|
|
566
|
+
ys),
|
|
567
|
+
cubicLerp(
|
|
568
|
+
cubicLerp(valCoordR3(seed,x0,y0,z1), valCoordR3(seed,x1,y0,z1), valCoordR3(seed,x2,y0,z1), valCoordR3(seed,x3,y0,z1), xs),
|
|
569
|
+
cubicLerp(valCoordR3(seed,x0,y1,z1), valCoordR3(seed,x1,y1,z1), valCoordR3(seed,x2,y1,z1), valCoordR3(seed,x3,y1,z1), xs),
|
|
570
|
+
cubicLerp(valCoordR3(seed,x0,y2,z1), valCoordR3(seed,x1,y2,z1), valCoordR3(seed,x2,y2,z1), valCoordR3(seed,x3,y2,z1), xs),
|
|
571
|
+
cubicLerp(valCoordR3(seed,x0,y3,z1), valCoordR3(seed,x1,y3,z1), valCoordR3(seed,x2,y3,z1), valCoordR3(seed,x3,y3,z1), xs),
|
|
572
|
+
ys),
|
|
573
|
+
cubicLerp(
|
|
574
|
+
cubicLerp(valCoordR3(seed,x0,y0,z2), valCoordR3(seed,x1,y0,z2), valCoordR3(seed,x2,y0,z2), valCoordR3(seed,x3,y0,z2), xs),
|
|
575
|
+
cubicLerp(valCoordR3(seed,x0,y1,z2), valCoordR3(seed,x1,y1,z2), valCoordR3(seed,x2,y1,z2), valCoordR3(seed,x3,y1,z2), xs),
|
|
576
|
+
cubicLerp(valCoordR3(seed,x0,y2,z2), valCoordR3(seed,x1,y2,z2), valCoordR3(seed,x2,y2,z2), valCoordR3(seed,x3,y2,z2), xs),
|
|
577
|
+
cubicLerp(valCoordR3(seed,x0,y3,z2), valCoordR3(seed,x1,y3,z2), valCoordR3(seed,x2,y3,z2), valCoordR3(seed,x3,y3,z2), xs),
|
|
578
|
+
ys),
|
|
579
|
+
cubicLerp(
|
|
580
|
+
cubicLerp(valCoordR3(seed,x0,y0,z3), valCoordR3(seed,x1,y0,z3), valCoordR3(seed,x2,y0,z3), valCoordR3(seed,x3,y0,z3), xs),
|
|
581
|
+
cubicLerp(valCoordR3(seed,x0,y1,z3), valCoordR3(seed,x1,y1,z3), valCoordR3(seed,x2,y1,z3), valCoordR3(seed,x3,y1,z3), xs),
|
|
582
|
+
cubicLerp(valCoordR3(seed,x0,y2,z3), valCoordR3(seed,x1,y2,z3), valCoordR3(seed,x2,y2,z3), valCoordR3(seed,x3,y2,z3), xs),
|
|
583
|
+
cubicLerp(valCoordR3(seed,x0,y3,z3), valCoordR3(seed,x1,y3,z3), valCoordR3(seed,x2,y3,z3), valCoordR3(seed,x3,y3,z3), xs),
|
|
584
|
+
ys),
|
|
585
|
+
zs
|
|
586
|
+
) * (1.0 / (1.5 * 1.5 * 1.5));
|
|
587
|
+
}
|
|
588
|
+
`;
|
|
589
|
+
}
|
|
590
|
+
const ee = ["primes", "gradients2D", "imul", "hashR2", "gradCoordR2"], ae = ["primes", "gradients3D", "imul", "hashR3", "gradCoordR3"];
|
|
591
|
+
function ie() {
|
|
592
|
+
return `
|
|
593
|
+
${E()}
|
|
594
|
+
${W()}
|
|
595
|
+
${N()}
|
|
596
|
+
${I()}
|
|
597
|
+
${V()}
|
|
598
|
+
|
|
599
|
+
${B()}
|
|
600
|
+
`;
|
|
601
|
+
}
|
|
602
|
+
function re() {
|
|
603
|
+
return `
|
|
604
|
+
${E()}
|
|
605
|
+
${j()}
|
|
606
|
+
${N()}
|
|
607
|
+
${S()}
|
|
608
|
+
${F()}
|
|
609
|
+
|
|
610
|
+
${H()}
|
|
611
|
+
`;
|
|
612
|
+
}
|
|
613
|
+
function B() {
|
|
614
|
+
return `fn opensimplex2_2d(seed: i32, x: f32, y: f32) -> f32 {
|
|
615
|
+
let G2: f32 = 0.21132486540518713;
|
|
616
|
+
|
|
617
|
+
let fi = floor(x);
|
|
618
|
+
let fj = floor(y);
|
|
619
|
+
var i = i32(fi);
|
|
620
|
+
var j = i32(fj);
|
|
621
|
+
let xi = x - fi;
|
|
622
|
+
let yi = y - fj;
|
|
623
|
+
|
|
624
|
+
let t = (xi + yi) * G2;
|
|
625
|
+
let x0 = xi - t;
|
|
626
|
+
let y0 = yi - t;
|
|
627
|
+
|
|
628
|
+
i = imul(i, PRIME_X);
|
|
629
|
+
j = imul(j, PRIME_Y);
|
|
630
|
+
|
|
631
|
+
var n0: f32 = 0.0;
|
|
632
|
+
var n1: f32 = 0.0;
|
|
633
|
+
var n2: f32 = 0.0;
|
|
634
|
+
|
|
635
|
+
let a = 0.5 - x0 * x0 - y0 * y0;
|
|
636
|
+
if (a > 0.0) {
|
|
637
|
+
n0 = a * a * (a * a) * gradCoordR2(seed, i, j, x0, y0);
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
let c = 2.0 * (1.0 - 2.0 * G2) * (1.0 / G2 - 2.0) * t +
|
|
641
|
+
(-2.0 * (1.0 - 2.0 * G2) * (1.0 - 2.0 * G2) + a);
|
|
642
|
+
if (c > 0.0) {
|
|
643
|
+
let x2 = x0 + (2.0 * G2 - 1.0);
|
|
644
|
+
let y2 = y0 + (2.0 * G2 - 1.0);
|
|
645
|
+
n2 = c * c * (c * c) * gradCoordR2(seed, i + PRIME_X, j + PRIME_Y, x2, y2);
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
if (y0 > x0) {
|
|
649
|
+
let x1 = x0 + G2;
|
|
650
|
+
let y1 = y0 + (G2 - 1.0);
|
|
651
|
+
let b = 0.5 - x1 * x1 - y1 * y1;
|
|
652
|
+
if (b > 0.0) {
|
|
653
|
+
n1 = b * b * (b * b) * gradCoordR2(seed, i, j + PRIME_Y, x1, y1);
|
|
654
|
+
}
|
|
655
|
+
} else {
|
|
656
|
+
let x1 = x0 + (G2 - 1.0);
|
|
657
|
+
let y1 = y0 + G2;
|
|
658
|
+
let b = 0.5 - x1 * x1 - y1 * y1;
|
|
659
|
+
if (b > 0.0) {
|
|
660
|
+
n1 = b * b * (b * b) * gradCoordR2(seed, i + PRIME_X, j, x1, y1);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
return (n0 + n1 + n2) * 99.83685446303647;
|
|
665
|
+
}`;
|
|
666
|
+
}
|
|
667
|
+
function H() {
|
|
668
|
+
return `fn opensimplex2_3d(seed_in: i32, x: f32, y: f32, z: f32) -> f32 {
|
|
669
|
+
var seed = seed_in;
|
|
670
|
+
var i = i32(floor(x + 0.5));
|
|
671
|
+
var j = i32(floor(y + 0.5));
|
|
672
|
+
var k = i32(floor(z + 0.5));
|
|
673
|
+
var x0 = x - f32(i);
|
|
674
|
+
var y0 = y - f32(j);
|
|
675
|
+
var z0 = z - f32(k);
|
|
676
|
+
|
|
677
|
+
var xNSign = i32(-1.0 - x0) | 1;
|
|
678
|
+
var yNSign = i32(-1.0 - y0) | 1;
|
|
679
|
+
var zNSign = i32(-1.0 - z0) | 1;
|
|
680
|
+
|
|
681
|
+
var ax0 = f32(xNSign) * (-x0);
|
|
682
|
+
var ay0 = f32(yNSign) * (-y0);
|
|
683
|
+
var az0 = f32(zNSign) * (-z0);
|
|
684
|
+
|
|
685
|
+
i = imul(i, PRIME_X);
|
|
686
|
+
j = imul(j, PRIME_Y);
|
|
687
|
+
k = imul(k, PRIME_Z);
|
|
688
|
+
|
|
689
|
+
var value: f32 = 0.0;
|
|
690
|
+
var a = 0.6 - x0 * x0 - (y0 * y0 + z0 * z0);
|
|
691
|
+
|
|
692
|
+
for (var l: i32 = 0; l < 2; l++) {
|
|
693
|
+
if (a > 0.0) {
|
|
694
|
+
value += a * a * (a * a) * gradCoordR3(seed, i, j, k, x0, y0, z0);
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
if (ax0 >= ay0 && ax0 >= az0) {
|
|
698
|
+
var b = a + ax0 + ax0;
|
|
699
|
+
if (b > 1.0) {
|
|
700
|
+
b -= 1.0;
|
|
701
|
+
value += b * b * (b * b) * gradCoordR3(seed, i - xNSign * PRIME_X, j, k, x0 + f32(xNSign), y0, z0);
|
|
702
|
+
}
|
|
703
|
+
} else if (ay0 > ax0 && ay0 >= az0) {
|
|
704
|
+
var b = a + ay0 + ay0;
|
|
705
|
+
if (b > 1.0) {
|
|
706
|
+
b -= 1.0;
|
|
707
|
+
value += b * b * (b * b) * gradCoordR3(seed, i, j - yNSign * PRIME_Y, k, x0, y0 + f32(yNSign), z0);
|
|
708
|
+
}
|
|
709
|
+
} else {
|
|
710
|
+
var b = a + az0 + az0;
|
|
711
|
+
if (b > 1.0) {
|
|
712
|
+
b -= 1.0;
|
|
713
|
+
value += b * b * (b * b) * gradCoordR3(seed, i, j, k - zNSign * PRIME_Z, x0, y0, z0 + f32(zNSign));
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
if (l == 1) { break; }
|
|
718
|
+
|
|
719
|
+
ax0 = 0.5 - ax0;
|
|
720
|
+
ay0 = 0.5 - ay0;
|
|
721
|
+
az0 = 0.5 - az0;
|
|
722
|
+
|
|
723
|
+
x0 = f32(xNSign) * ax0;
|
|
724
|
+
y0 = f32(yNSign) * ay0;
|
|
725
|
+
z0 = f32(zNSign) * az0;
|
|
726
|
+
|
|
727
|
+
a += 0.75 - ax0 - (ay0 + az0);
|
|
728
|
+
|
|
729
|
+
i += (xNSign >> 1u) & PRIME_X;
|
|
730
|
+
j += (yNSign >> 1u) & PRIME_Y;
|
|
731
|
+
k += (zNSign >> 1u) & PRIME_Z;
|
|
732
|
+
|
|
733
|
+
xNSign = -xNSign;
|
|
734
|
+
yNSign = -yNSign;
|
|
735
|
+
zNSign = -zNSign;
|
|
736
|
+
|
|
737
|
+
seed = ~seed;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
return value * 32.69428253173828125;
|
|
741
|
+
}`;
|
|
742
|
+
}
|
|
743
|
+
const ve = A << 1 | 0, ze = G << 1 | 0, Qe = X << 1 | 0;
|
|
744
|
+
function Ue() {
|
|
745
|
+
return `
|
|
746
|
+
${E()}
|
|
747
|
+
const PRIME_X_2: i32 = ${ve};
|
|
748
|
+
const PRIME_Y_2: i32 = ${ze};
|
|
749
|
+
${W()}
|
|
750
|
+
${N()}
|
|
751
|
+
${I()}
|
|
752
|
+
${V()}
|
|
753
|
+
|
|
754
|
+
fn opensimplex2s_2d(seed_in: i32, x: f32, y: f32) -> f32 {
|
|
755
|
+
let seed = seed_in;
|
|
756
|
+
let G2: f32 = 0.21132486540518713;
|
|
757
|
+
|
|
758
|
+
let fi = floor(x);
|
|
759
|
+
let fj = floor(y);
|
|
760
|
+
var i = i32(fi);
|
|
761
|
+
var j = i32(fj);
|
|
762
|
+
let xi = x - fi;
|
|
763
|
+
let yi = y - fj;
|
|
764
|
+
|
|
765
|
+
i = imul(i, PRIME_X);
|
|
766
|
+
j = imul(j, PRIME_Y);
|
|
767
|
+
let i1 = i + PRIME_X;
|
|
768
|
+
let j1 = j + PRIME_Y;
|
|
769
|
+
|
|
770
|
+
let t = (xi + yi) * G2;
|
|
771
|
+
let x0 = xi - t;
|
|
772
|
+
let y0 = yi - t;
|
|
773
|
+
|
|
774
|
+
let a0 = 2.0 / 3.0 - x0 * x0 - y0 * y0;
|
|
775
|
+
var value = a0 * a0 * (a0 * a0) * gradCoordR2(seed, i, j, x0, y0);
|
|
776
|
+
|
|
777
|
+
let a1 = 2.0 * (1.0 - 2.0 * G2) * (1.0 / G2 - 2.0) * t +
|
|
778
|
+
(-2.0 * (1.0 - 2.0 * G2) * (1.0 - 2.0 * G2) + a0);
|
|
779
|
+
let x1 = x0 - (1.0 - 2.0 * G2);
|
|
780
|
+
let y1 = y0 - (1.0 - 2.0 * G2);
|
|
781
|
+
value += a1 * a1 * (a1 * a1) * gradCoordR2(seed, i1, j1, x1, y1);
|
|
782
|
+
|
|
783
|
+
let xmyi = xi - yi;
|
|
784
|
+
if (t > G2) {
|
|
785
|
+
if (xi + xmyi > 1.0) {
|
|
786
|
+
let x2 = x0 + (3.0 * G2 - 2.0);
|
|
787
|
+
let y2 = y0 + (3.0 * G2 - 1.0);
|
|
788
|
+
let a2 = 2.0 / 3.0 - x2 * x2 - y2 * y2;
|
|
789
|
+
if (a2 > 0.0) {
|
|
790
|
+
value += a2 * a2 * (a2 * a2) * gradCoordR2(seed, i + PRIME_X_2, j + PRIME_Y, x2, y2);
|
|
791
|
+
}
|
|
792
|
+
} else {
|
|
793
|
+
let x2 = x0 + G2;
|
|
794
|
+
let y2 = y0 + (G2 - 1.0);
|
|
795
|
+
let a2 = 2.0 / 3.0 - x2 * x2 - y2 * y2;
|
|
796
|
+
if (a2 > 0.0) {
|
|
797
|
+
value += a2 * a2 * (a2 * a2) * gradCoordR2(seed, i, j + PRIME_Y, x2, y2);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
if (yi - xmyi > 1.0) {
|
|
802
|
+
let x3 = x0 + (3.0 * G2 - 1.0);
|
|
803
|
+
let y3 = y0 + (3.0 * G2 - 2.0);
|
|
804
|
+
let a3 = 2.0 / 3.0 - x3 * x3 - y3 * y3;
|
|
805
|
+
if (a3 > 0.0) {
|
|
806
|
+
value += a3 * a3 * (a3 * a3) * gradCoordR2(seed, i + PRIME_X, j + PRIME_Y_2, x3, y3);
|
|
807
|
+
}
|
|
808
|
+
} else {
|
|
809
|
+
let x3 = x0 + (G2 - 1.0);
|
|
810
|
+
let y3 = y0 + G2;
|
|
811
|
+
let a3 = 2.0 / 3.0 - x3 * x3 - y3 * y3;
|
|
812
|
+
if (a3 > 0.0) {
|
|
813
|
+
value += a3 * a3 * (a3 * a3) * gradCoordR2(seed, i + PRIME_X, j, x3, y3);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
} else {
|
|
817
|
+
if (xi + xmyi < 0.0) {
|
|
818
|
+
let x2 = x0 + (1.0 - G2);
|
|
819
|
+
let y2 = y0 - G2;
|
|
820
|
+
let a2 = 2.0 / 3.0 - x2 * x2 - y2 * y2;
|
|
821
|
+
if (a2 > 0.0) {
|
|
822
|
+
value += a2 * a2 * (a2 * a2) * gradCoordR2(seed, i - PRIME_X, j, x2, y2);
|
|
823
|
+
}
|
|
824
|
+
} else {
|
|
825
|
+
let x2 = x0 + (G2 - 1.0);
|
|
826
|
+
let y2 = y0 + G2;
|
|
827
|
+
let a2 = 2.0 / 3.0 - x2 * x2 - y2 * y2;
|
|
828
|
+
if (a2 > 0.0) {
|
|
829
|
+
value += a2 * a2 * (a2 * a2) * gradCoordR2(seed, i + PRIME_X, j, x2, y2);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
if (yi < xmyi) {
|
|
834
|
+
let x2 = x0 - G2;
|
|
835
|
+
let y2 = y0 - (G2 - 1.0);
|
|
836
|
+
let a2 = 2.0 / 3.0 - x2 * x2 - y2 * y2;
|
|
837
|
+
if (a2 > 0.0) {
|
|
838
|
+
value += a2 * a2 * (a2 * a2) * gradCoordR2(seed, i, j - PRIME_Y, x2, y2);
|
|
839
|
+
}
|
|
840
|
+
} else {
|
|
841
|
+
let x2 = x0 + G2;
|
|
842
|
+
let y2 = y0 + (G2 - 1.0);
|
|
843
|
+
let a2 = 2.0 / 3.0 - x2 * x2 - y2 * y2;
|
|
844
|
+
if (a2 > 0.0) {
|
|
845
|
+
value += a2 * a2 * (a2 * a2) * gradCoordR2(seed, i, j + PRIME_Y, x2, y2);
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
return value * 18.24196194486065;
|
|
851
|
+
}
|
|
852
|
+
`;
|
|
853
|
+
}
|
|
854
|
+
function Ke() {
|
|
855
|
+
return `
|
|
856
|
+
${E()}
|
|
857
|
+
const PRIME_X_2: i32 = ${ve};
|
|
858
|
+
const PRIME_Y_2: i32 = ${ze};
|
|
859
|
+
const PRIME_Z_2: i32 = ${Qe};
|
|
860
|
+
${j()}
|
|
861
|
+
${N()}
|
|
862
|
+
${S()}
|
|
863
|
+
${F()}
|
|
864
|
+
|
|
865
|
+
fn opensimplex2s_3d(seed_in: i32, x: f32, y: f32, z: f32) -> f32 {
|
|
866
|
+
let seed = seed_in;
|
|
867
|
+
let seed2 = seed + 1293373;
|
|
868
|
+
|
|
869
|
+
let fi = floor(x);
|
|
870
|
+
let fj = floor(y);
|
|
871
|
+
let fk = floor(z);
|
|
872
|
+
var i = imul(i32(fi), PRIME_X);
|
|
873
|
+
var j = imul(i32(fj), PRIME_Y);
|
|
874
|
+
var k = imul(i32(fk), PRIME_Z);
|
|
875
|
+
|
|
876
|
+
let xi = x - fi;
|
|
877
|
+
let yi = y - fj;
|
|
878
|
+
let zi = z - fk;
|
|
879
|
+
|
|
880
|
+
// i32() truncates toward zero = Math.trunc (NOT floor)
|
|
881
|
+
let xNMask = i32(-0.5 - xi);
|
|
882
|
+
let yNMask = i32(-0.5 - yi);
|
|
883
|
+
let zNMask = i32(-0.5 - zi);
|
|
884
|
+
|
|
885
|
+
let x0 = xi + f32(xNMask);
|
|
886
|
+
let y0 = yi + f32(yNMask);
|
|
887
|
+
let z0 = zi + f32(zNMask);
|
|
888
|
+
var a0 = 0.75 - x0 * x0 - y0 * y0 - z0 * z0;
|
|
889
|
+
var value = a0 * a0 * (a0 * a0) * gradCoordR3(seed,
|
|
890
|
+
i + (xNMask & PRIME_X), j + (yNMask & PRIME_Y), k + (zNMask & PRIME_Z),
|
|
891
|
+
x0, y0, z0);
|
|
892
|
+
|
|
893
|
+
let x1 = xi - 0.5;
|
|
894
|
+
let y1 = yi - 0.5;
|
|
895
|
+
let z1 = zi - 0.5;
|
|
896
|
+
var a1 = 0.75 - x1 * x1 - y1 * y1 - z1 * z1;
|
|
897
|
+
value += a1 * a1 * (a1 * a1) * gradCoordR3(seed2,
|
|
898
|
+
i + PRIME_X, j + PRIME_Y, k + PRIME_Z, x1, y1, z1);
|
|
899
|
+
|
|
900
|
+
let xAFlipMask0 = f32((xNMask | 1) << 1u) * x1;
|
|
901
|
+
let yAFlipMask0 = f32((yNMask | 1) << 1u) * y1;
|
|
902
|
+
let zAFlipMask0 = f32((zNMask | 1) << 1u) * z1;
|
|
903
|
+
let xAFlipMask1 = f32(-2 - (xNMask << 2u)) * x1 - 1.0;
|
|
904
|
+
let yAFlipMask1 = f32(-2 - (yNMask << 2u)) * y1 - 1.0;
|
|
905
|
+
let zAFlipMask1 = f32(-2 - (zNMask << 2u)) * z1 - 1.0;
|
|
906
|
+
|
|
907
|
+
var skip5 = false;
|
|
908
|
+
var a2 = xAFlipMask0 + a0;
|
|
909
|
+
if (a2 > 0.0) {
|
|
910
|
+
let x2 = x0 - f32(xNMask | 1);
|
|
911
|
+
value += a2 * a2 * (a2 * a2) * gradCoordR3(seed,
|
|
912
|
+
i + (~xNMask & PRIME_X), j + (yNMask & PRIME_Y), k + (zNMask & PRIME_Z),
|
|
913
|
+
x2, y0, z0);
|
|
914
|
+
} else {
|
|
915
|
+
var a3 = yAFlipMask0 + zAFlipMask0 + a0;
|
|
916
|
+
if (a3 > 0.0) {
|
|
917
|
+
let y3 = y0 - f32(yNMask | 1);
|
|
918
|
+
let z3 = z0 - f32(zNMask | 1);
|
|
919
|
+
value += a3 * a3 * (a3 * a3) * gradCoordR3(seed,
|
|
920
|
+
i + (xNMask & PRIME_X), j + (~yNMask & PRIME_Y), k + (~zNMask & PRIME_Z),
|
|
921
|
+
x0, y3, z3);
|
|
922
|
+
}
|
|
923
|
+
var a4 = xAFlipMask1 + a1;
|
|
924
|
+
if (a4 > 0.0) {
|
|
925
|
+
let x4 = f32(xNMask | 1) + x1;
|
|
926
|
+
value += a4 * a4 * (a4 * a4) * gradCoordR3(seed2,
|
|
927
|
+
i + (xNMask & PRIME_X_2), j + PRIME_Y, k + PRIME_Z,
|
|
928
|
+
x4, y1, z1);
|
|
929
|
+
skip5 = true;
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
var skip9 = false;
|
|
934
|
+
var a6 = yAFlipMask0 + a0;
|
|
935
|
+
if (a6 > 0.0) {
|
|
936
|
+
let y6 = y0 - f32(yNMask | 1);
|
|
937
|
+
value += a6 * a6 * (a6 * a6) * gradCoordR3(seed,
|
|
938
|
+
i + (xNMask & PRIME_X), j + (~yNMask & PRIME_Y), k + (zNMask & PRIME_Z),
|
|
939
|
+
x0, y6, z0);
|
|
940
|
+
} else {
|
|
941
|
+
var a7 = xAFlipMask0 + zAFlipMask0 + a0;
|
|
942
|
+
if (a7 > 0.0) {
|
|
943
|
+
let x7 = x0 - f32(xNMask | 1);
|
|
944
|
+
let z7 = z0 - f32(zNMask | 1);
|
|
945
|
+
value += a7 * a7 * (a7 * a7) * gradCoordR3(seed,
|
|
946
|
+
i + (~xNMask & PRIME_X), j + (yNMask & PRIME_Y), k + (~zNMask & PRIME_Z),
|
|
947
|
+
x7, y0, z7);
|
|
948
|
+
}
|
|
949
|
+
var a8 = yAFlipMask1 + a1;
|
|
950
|
+
if (a8 > 0.0) {
|
|
951
|
+
let y8 = f32(yNMask | 1) + y1;
|
|
952
|
+
value += a8 * a8 * (a8 * a8) * gradCoordR3(seed2,
|
|
953
|
+
i + PRIME_X, j + (yNMask & PRIME_Y_2), k + PRIME_Z,
|
|
954
|
+
x1, y8, z1);
|
|
955
|
+
skip9 = true;
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
var skipD = false;
|
|
960
|
+
var aA = zAFlipMask0 + a0;
|
|
961
|
+
if (aA > 0.0) {
|
|
962
|
+
let zA = z0 - f32(zNMask | 1);
|
|
963
|
+
value += aA * aA * (aA * aA) * gradCoordR3(seed,
|
|
964
|
+
i + (xNMask & PRIME_X), j + (yNMask & PRIME_Y), k + (~zNMask & PRIME_Z),
|
|
965
|
+
x0, y0, zA);
|
|
966
|
+
} else {
|
|
967
|
+
var aB = xAFlipMask0 + yAFlipMask0 + a0;
|
|
968
|
+
if (aB > 0.0) {
|
|
969
|
+
let xB = x0 - f32(xNMask | 1);
|
|
970
|
+
let yB = y0 - f32(yNMask | 1);
|
|
971
|
+
value += aB * aB * (aB * aB) * gradCoordR3(seed,
|
|
972
|
+
i + (~xNMask & PRIME_X), j + (~yNMask & PRIME_Y), k + (zNMask & PRIME_Z),
|
|
973
|
+
xB, yB, z0);
|
|
974
|
+
}
|
|
975
|
+
var aC = zAFlipMask1 + a1;
|
|
976
|
+
if (aC > 0.0) {
|
|
977
|
+
let zC = f32(zNMask | 1) + z1;
|
|
978
|
+
value += aC * aC * (aC * aC) * gradCoordR3(seed2,
|
|
979
|
+
i + PRIME_X, j + PRIME_Y, k + (zNMask & PRIME_Z_2),
|
|
980
|
+
x1, y1, zC);
|
|
981
|
+
skipD = true;
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
if (!skip5) {
|
|
986
|
+
var a5 = yAFlipMask1 + zAFlipMask1 + a1;
|
|
987
|
+
if (a5 > 0.0) {
|
|
988
|
+
let y5 = f32(yNMask | 1) + y1;
|
|
989
|
+
let z5 = f32(zNMask | 1) + z1;
|
|
990
|
+
value += a5 * a5 * (a5 * a5) * gradCoordR3(seed2,
|
|
991
|
+
i + PRIME_X, j + (yNMask & PRIME_Y_2), k + (zNMask & PRIME_Z_2),
|
|
992
|
+
x1, y5, z5);
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
if (!skip9) {
|
|
997
|
+
var a9 = xAFlipMask1 + zAFlipMask1 + a1;
|
|
998
|
+
if (a9 > 0.0) {
|
|
999
|
+
let x9 = f32(xNMask | 1) + x1;
|
|
1000
|
+
let z9 = f32(zNMask | 1) + z1;
|
|
1001
|
+
value += a9 * a9 * (a9 * a9) * gradCoordR3(seed2,
|
|
1002
|
+
i + (xNMask & PRIME_X_2), j + PRIME_Y, k + (zNMask & PRIME_Z_2),
|
|
1003
|
+
x9, y1, z9);
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
if (!skipD) {
|
|
1008
|
+
var aD = xAFlipMask1 + yAFlipMask1 + a1;
|
|
1009
|
+
if (aD > 0.0) {
|
|
1010
|
+
let xD = f32(xNMask | 1) + x1;
|
|
1011
|
+
let yD = f32(yNMask | 1) + y1;
|
|
1012
|
+
value += aD * aD * (aD * aD) * gradCoordR3(seed2,
|
|
1013
|
+
i + (xNMask & PRIME_X_2), j + (yNMask & PRIME_Y_2), k + PRIME_Z,
|
|
1014
|
+
xD, yD, z1);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
return value * 9.046026385208288;
|
|
1019
|
+
}
|
|
1020
|
+
`;
|
|
1021
|
+
}
|
|
1022
|
+
const ea = ["primes", "primesDouble", "gradients2D", "imul", "hashR2", "gradCoordR2"], aa = ["primes", "primesDouble", "gradients3D", "imul", "hashR3", "gradCoordR3"];
|
|
1023
|
+
function ia() {
|
|
1024
|
+
return `
|
|
1025
|
+
fn opensimplex2s_2d(seed_in: i32, x: f32, y: f32) -> f32 {
|
|
1026
|
+
let seed = seed_in;
|
|
1027
|
+
let G2: f32 = 0.21132486540518713;
|
|
1028
|
+
|
|
1029
|
+
let fi = floor(x);
|
|
1030
|
+
let fj = floor(y);
|
|
1031
|
+
var i = i32(fi);
|
|
1032
|
+
var j = i32(fj);
|
|
1033
|
+
let xi = x - fi;
|
|
1034
|
+
let yi = y - fj;
|
|
1035
|
+
|
|
1036
|
+
i = imul(i, PRIME_X);
|
|
1037
|
+
j = imul(j, PRIME_Y);
|
|
1038
|
+
let i1 = i + PRIME_X;
|
|
1039
|
+
let j1 = j + PRIME_Y;
|
|
1040
|
+
|
|
1041
|
+
let t = (xi + yi) * G2;
|
|
1042
|
+
let x0 = xi - t;
|
|
1043
|
+
let y0 = yi - t;
|
|
1044
|
+
|
|
1045
|
+
let a0 = 2.0 / 3.0 - x0 * x0 - y0 * y0;
|
|
1046
|
+
var value = a0 * a0 * (a0 * a0) * gradCoordR2(seed, i, j, x0, y0);
|
|
1047
|
+
|
|
1048
|
+
let a1 = 2.0 * (1.0 - 2.0 * G2) * (1.0 / G2 - 2.0) * t +
|
|
1049
|
+
(-2.0 * (1.0 - 2.0 * G2) * (1.0 - 2.0 * G2) + a0);
|
|
1050
|
+
let x1 = x0 - (1.0 - 2.0 * G2);
|
|
1051
|
+
let y1 = y0 - (1.0 - 2.0 * G2);
|
|
1052
|
+
value += a1 * a1 * (a1 * a1) * gradCoordR2(seed, i1, j1, x1, y1);
|
|
1053
|
+
|
|
1054
|
+
let xmyi = xi - yi;
|
|
1055
|
+
if (t > G2) {
|
|
1056
|
+
if (xi + xmyi > 1.0) {
|
|
1057
|
+
let x2 = x0 + (3.0 * G2 - 2.0);
|
|
1058
|
+
let y2 = y0 + (3.0 * G2 - 1.0);
|
|
1059
|
+
let a2 = 2.0 / 3.0 - x2 * x2 - y2 * y2;
|
|
1060
|
+
if (a2 > 0.0) {
|
|
1061
|
+
value += a2 * a2 * (a2 * a2) * gradCoordR2(seed, i + PRIME_X_2, j + PRIME_Y, x2, y2);
|
|
1062
|
+
}
|
|
1063
|
+
} else {
|
|
1064
|
+
let x2 = x0 + G2;
|
|
1065
|
+
let y2 = y0 + (G2 - 1.0);
|
|
1066
|
+
let a2 = 2.0 / 3.0 - x2 * x2 - y2 * y2;
|
|
1067
|
+
if (a2 > 0.0) {
|
|
1068
|
+
value += a2 * a2 * (a2 * a2) * gradCoordR2(seed, i, j + PRIME_Y, x2, y2);
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
if (yi - xmyi > 1.0) {
|
|
1073
|
+
let x3 = x0 + (3.0 * G2 - 1.0);
|
|
1074
|
+
let y3 = y0 + (3.0 * G2 - 2.0);
|
|
1075
|
+
let a3 = 2.0 / 3.0 - x3 * x3 - y3 * y3;
|
|
1076
|
+
if (a3 > 0.0) {
|
|
1077
|
+
value += a3 * a3 * (a3 * a3) * gradCoordR2(seed, i + PRIME_X, j + PRIME_Y_2, x3, y3);
|
|
1078
|
+
}
|
|
1079
|
+
} else {
|
|
1080
|
+
let x3 = x0 + (G2 - 1.0);
|
|
1081
|
+
let y3 = y0 + G2;
|
|
1082
|
+
let a3 = 2.0 / 3.0 - x3 * x3 - y3 * y3;
|
|
1083
|
+
if (a3 > 0.0) {
|
|
1084
|
+
value += a3 * a3 * (a3 * a3) * gradCoordR2(seed, i + PRIME_X, j, x3, y3);
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
} else {
|
|
1088
|
+
if (xi + xmyi < 0.0) {
|
|
1089
|
+
let x2 = x0 + (1.0 - G2);
|
|
1090
|
+
let y2 = y0 - G2;
|
|
1091
|
+
let a2 = 2.0 / 3.0 - x2 * x2 - y2 * y2;
|
|
1092
|
+
if (a2 > 0.0) {
|
|
1093
|
+
value += a2 * a2 * (a2 * a2) * gradCoordR2(seed, i - PRIME_X, j, x2, y2);
|
|
1094
|
+
}
|
|
1095
|
+
} else {
|
|
1096
|
+
let x2 = x0 + (G2 - 1.0);
|
|
1097
|
+
let y2 = y0 + G2;
|
|
1098
|
+
let a2 = 2.0 / 3.0 - x2 * x2 - y2 * y2;
|
|
1099
|
+
if (a2 > 0.0) {
|
|
1100
|
+
value += a2 * a2 * (a2 * a2) * gradCoordR2(seed, i + PRIME_X, j, x2, y2);
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
if (yi < xmyi) {
|
|
1105
|
+
let x2 = x0 - G2;
|
|
1106
|
+
let y2 = y0 - (G2 - 1.0);
|
|
1107
|
+
let a2 = 2.0 / 3.0 - x2 * x2 - y2 * y2;
|
|
1108
|
+
if (a2 > 0.0) {
|
|
1109
|
+
value += a2 * a2 * (a2 * a2) * gradCoordR2(seed, i, j - PRIME_Y, x2, y2);
|
|
1110
|
+
}
|
|
1111
|
+
} else {
|
|
1112
|
+
let x2 = x0 + G2;
|
|
1113
|
+
let y2 = y0 + (G2 - 1.0);
|
|
1114
|
+
let a2 = 2.0 / 3.0 - x2 * x2 - y2 * y2;
|
|
1115
|
+
if (a2 > 0.0) {
|
|
1116
|
+
value += a2 * a2 * (a2 * a2) * gradCoordR2(seed, i, j + PRIME_Y, x2, y2);
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
return value * 18.24196194486065;
|
|
1122
|
+
}
|
|
1123
|
+
`;
|
|
1124
|
+
}
|
|
1125
|
+
function ra() {
|
|
1126
|
+
return `
|
|
1127
|
+
fn opensimplex2s_3d(seed_in: i32, x: f32, y: f32, z: f32) -> f32 {
|
|
1128
|
+
let seed = seed_in;
|
|
1129
|
+
let seed2 = seed + 1293373;
|
|
1130
|
+
|
|
1131
|
+
let fi = floor(x);
|
|
1132
|
+
let fj = floor(y);
|
|
1133
|
+
let fk = floor(z);
|
|
1134
|
+
var i = imul(i32(fi), PRIME_X);
|
|
1135
|
+
var j = imul(i32(fj), PRIME_Y);
|
|
1136
|
+
var k = imul(i32(fk), PRIME_Z);
|
|
1137
|
+
|
|
1138
|
+
let xi = x - fi;
|
|
1139
|
+
let yi = y - fj;
|
|
1140
|
+
let zi = z - fk;
|
|
1141
|
+
|
|
1142
|
+
// i32() truncates toward zero = Math.trunc (NOT floor)
|
|
1143
|
+
let xNMask = i32(-0.5 - xi);
|
|
1144
|
+
let yNMask = i32(-0.5 - yi);
|
|
1145
|
+
let zNMask = i32(-0.5 - zi);
|
|
1146
|
+
|
|
1147
|
+
let x0 = xi + f32(xNMask);
|
|
1148
|
+
let y0 = yi + f32(yNMask);
|
|
1149
|
+
let z0 = zi + f32(zNMask);
|
|
1150
|
+
var a0 = 0.75 - x0 * x0 - y0 * y0 - z0 * z0;
|
|
1151
|
+
var value = a0 * a0 * (a0 * a0) * gradCoordR3(seed,
|
|
1152
|
+
i + (xNMask & PRIME_X), j + (yNMask & PRIME_Y), k + (zNMask & PRIME_Z),
|
|
1153
|
+
x0, y0, z0);
|
|
1154
|
+
|
|
1155
|
+
let x1 = xi - 0.5;
|
|
1156
|
+
let y1 = yi - 0.5;
|
|
1157
|
+
let z1 = zi - 0.5;
|
|
1158
|
+
var a1 = 0.75 - x1 * x1 - y1 * y1 - z1 * z1;
|
|
1159
|
+
value += a1 * a1 * (a1 * a1) * gradCoordR3(seed2,
|
|
1160
|
+
i + PRIME_X, j + PRIME_Y, k + PRIME_Z, x1, y1, z1);
|
|
1161
|
+
|
|
1162
|
+
let xAFlipMask0 = f32((xNMask | 1) << 1u) * x1;
|
|
1163
|
+
let yAFlipMask0 = f32((yNMask | 1) << 1u) * y1;
|
|
1164
|
+
let zAFlipMask0 = f32((zNMask | 1) << 1u) * z1;
|
|
1165
|
+
let xAFlipMask1 = f32(-2 - (xNMask << 2u)) * x1 - 1.0;
|
|
1166
|
+
let yAFlipMask1 = f32(-2 - (yNMask << 2u)) * y1 - 1.0;
|
|
1167
|
+
let zAFlipMask1 = f32(-2 - (zNMask << 2u)) * z1 - 1.0;
|
|
1168
|
+
|
|
1169
|
+
var skip5 = false;
|
|
1170
|
+
var a2 = xAFlipMask0 + a0;
|
|
1171
|
+
if (a2 > 0.0) {
|
|
1172
|
+
let x2 = x0 - f32(xNMask | 1);
|
|
1173
|
+
value += a2 * a2 * (a2 * a2) * gradCoordR3(seed,
|
|
1174
|
+
i + (~xNMask & PRIME_X), j + (yNMask & PRIME_Y), k + (zNMask & PRIME_Z),
|
|
1175
|
+
x2, y0, z0);
|
|
1176
|
+
} else {
|
|
1177
|
+
var a3 = yAFlipMask0 + zAFlipMask0 + a0;
|
|
1178
|
+
if (a3 > 0.0) {
|
|
1179
|
+
let y3 = y0 - f32(yNMask | 1);
|
|
1180
|
+
let z3 = z0 - f32(zNMask | 1);
|
|
1181
|
+
value += a3 * a3 * (a3 * a3) * gradCoordR3(seed,
|
|
1182
|
+
i + (xNMask & PRIME_X), j + (~yNMask & PRIME_Y), k + (~zNMask & PRIME_Z),
|
|
1183
|
+
x0, y3, z3);
|
|
1184
|
+
}
|
|
1185
|
+
var a4 = xAFlipMask1 + a1;
|
|
1186
|
+
if (a4 > 0.0) {
|
|
1187
|
+
let x4 = f32(xNMask | 1) + x1;
|
|
1188
|
+
value += a4 * a4 * (a4 * a4) * gradCoordR3(seed2,
|
|
1189
|
+
i + (xNMask & PRIME_X_2), j + PRIME_Y, k + PRIME_Z,
|
|
1190
|
+
x4, y1, z1);
|
|
1191
|
+
skip5 = true;
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
var skip9 = false;
|
|
1196
|
+
var a6 = yAFlipMask0 + a0;
|
|
1197
|
+
if (a6 > 0.0) {
|
|
1198
|
+
let y6 = y0 - f32(yNMask | 1);
|
|
1199
|
+
value += a6 * a6 * (a6 * a6) * gradCoordR3(seed,
|
|
1200
|
+
i + (xNMask & PRIME_X), j + (~yNMask & PRIME_Y), k + (zNMask & PRIME_Z),
|
|
1201
|
+
x0, y6, z0);
|
|
1202
|
+
} else {
|
|
1203
|
+
var a7 = xAFlipMask0 + zAFlipMask0 + a0;
|
|
1204
|
+
if (a7 > 0.0) {
|
|
1205
|
+
let x7 = x0 - f32(xNMask | 1);
|
|
1206
|
+
let z7 = z0 - f32(zNMask | 1);
|
|
1207
|
+
value += a7 * a7 * (a7 * a7) * gradCoordR3(seed,
|
|
1208
|
+
i + (~xNMask & PRIME_X), j + (yNMask & PRIME_Y), k + (~zNMask & PRIME_Z),
|
|
1209
|
+
x7, y0, z7);
|
|
1210
|
+
}
|
|
1211
|
+
var a8 = yAFlipMask1 + a1;
|
|
1212
|
+
if (a8 > 0.0) {
|
|
1213
|
+
let y8 = f32(yNMask | 1) + y1;
|
|
1214
|
+
value += a8 * a8 * (a8 * a8) * gradCoordR3(seed2,
|
|
1215
|
+
i + PRIME_X, j + (yNMask & PRIME_Y_2), k + PRIME_Z,
|
|
1216
|
+
x1, y8, z1);
|
|
1217
|
+
skip9 = true;
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
var skipD = false;
|
|
1222
|
+
var aA = zAFlipMask0 + a0;
|
|
1223
|
+
if (aA > 0.0) {
|
|
1224
|
+
let zA = z0 - f32(zNMask | 1);
|
|
1225
|
+
value += aA * aA * (aA * aA) * gradCoordR3(seed,
|
|
1226
|
+
i + (xNMask & PRIME_X), j + (yNMask & PRIME_Y), k + (~zNMask & PRIME_Z),
|
|
1227
|
+
x0, y0, zA);
|
|
1228
|
+
} else {
|
|
1229
|
+
var aB = xAFlipMask0 + yAFlipMask0 + a0;
|
|
1230
|
+
if (aB > 0.0) {
|
|
1231
|
+
let xB = x0 - f32(xNMask | 1);
|
|
1232
|
+
let yB = y0 - f32(yNMask | 1);
|
|
1233
|
+
value += aB * aB * (aB * aB) * gradCoordR3(seed,
|
|
1234
|
+
i + (~xNMask & PRIME_X), j + (~yNMask & PRIME_Y), k + (zNMask & PRIME_Z),
|
|
1235
|
+
xB, yB, z0);
|
|
1236
|
+
}
|
|
1237
|
+
var aC = zAFlipMask1 + a1;
|
|
1238
|
+
if (aC > 0.0) {
|
|
1239
|
+
let zC = f32(zNMask | 1) + z1;
|
|
1240
|
+
value += aC * aC * (aC * aC) * gradCoordR3(seed2,
|
|
1241
|
+
i + PRIME_X, j + PRIME_Y, k + (zNMask & PRIME_Z_2),
|
|
1242
|
+
x1, y1, zC);
|
|
1243
|
+
skipD = true;
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
if (!skip5) {
|
|
1248
|
+
var a5 = yAFlipMask1 + zAFlipMask1 + a1;
|
|
1249
|
+
if (a5 > 0.0) {
|
|
1250
|
+
let y5 = f32(yNMask | 1) + y1;
|
|
1251
|
+
let z5 = f32(zNMask | 1) + z1;
|
|
1252
|
+
value += a5 * a5 * (a5 * a5) * gradCoordR3(seed2,
|
|
1253
|
+
i + PRIME_X, j + (yNMask & PRIME_Y_2), k + (zNMask & PRIME_Z_2),
|
|
1254
|
+
x1, y5, z5);
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
if (!skip9) {
|
|
1259
|
+
var a9 = xAFlipMask1 + zAFlipMask1 + a1;
|
|
1260
|
+
if (a9 > 0.0) {
|
|
1261
|
+
let x9 = f32(xNMask | 1) + x1;
|
|
1262
|
+
let z9 = f32(zNMask | 1) + z1;
|
|
1263
|
+
value += a9 * a9 * (a9 * a9) * gradCoordR3(seed2,
|
|
1264
|
+
i + (xNMask & PRIME_X_2), j + PRIME_Y, k + (zNMask & PRIME_Z_2),
|
|
1265
|
+
x9, y1, z9);
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
if (!skipD) {
|
|
1270
|
+
var aD = xAFlipMask1 + yAFlipMask1 + a1;
|
|
1271
|
+
if (aD > 0.0) {
|
|
1272
|
+
let xD = f32(xNMask | 1) + x1;
|
|
1273
|
+
let yD = f32(yNMask | 1) + y1;
|
|
1274
|
+
value += aD * aD * (aD * aD) * gradCoordR3(seed2,
|
|
1275
|
+
i + (xNMask & PRIME_X_2), j + (yNMask & PRIME_Y_2), k + PRIME_Z,
|
|
1276
|
+
xD, yD, z1);
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
return value * 9.046026385208288;
|
|
1281
|
+
}
|
|
1282
|
+
`;
|
|
1283
|
+
}
|
|
1284
|
+
const pe = 0.43701595, me = 0.39614353;
|
|
1285
|
+
function he(d) {
|
|
1286
|
+
switch (d) {
|
|
1287
|
+
case M.Euclidean:
|
|
1288
|
+
case M.EuclideanSq:
|
|
1289
|
+
return "return vecX * vecX + vecY * vecY;";
|
|
1290
|
+
case M.Manhattan:
|
|
1291
|
+
return "return abs(vecX) + abs(vecY);";
|
|
1292
|
+
case M.Hybrid:
|
|
1293
|
+
return "return abs(vecX) + abs(vecY) + vecX * vecX + vecY * vecY;";
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
function Ee(d) {
|
|
1297
|
+
switch (d) {
|
|
1298
|
+
case M.Euclidean:
|
|
1299
|
+
case M.EuclideanSq:
|
|
1300
|
+
return "return vecX * vecX + vecY * vecY + vecZ * vecZ;";
|
|
1301
|
+
case M.Manhattan:
|
|
1302
|
+
return "return abs(vecX) + abs(vecY) + abs(vecZ);";
|
|
1303
|
+
case M.Hybrid:
|
|
1304
|
+
return "return abs(vecX) + abs(vecY) + abs(vecZ) + vecX * vecX + vecY * vecY + vecZ * vecZ;";
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
function T(d) {
|
|
1308
|
+
switch (d) {
|
|
1309
|
+
case C.CellValue:
|
|
1310
|
+
return "return f32(closestHash) * (1.0 / 2147483648.0);";
|
|
1311
|
+
case C.Distance:
|
|
1312
|
+
return "return d0 - 1.0;";
|
|
1313
|
+
case C.Distance2:
|
|
1314
|
+
return "return d1 - 1.0;";
|
|
1315
|
+
case C.Distance2Add:
|
|
1316
|
+
return "return (d1 + d0) * 0.5 - 1.0;";
|
|
1317
|
+
case C.Distance2Sub:
|
|
1318
|
+
return "return d1 - d0 - 1.0;";
|
|
1319
|
+
case C.Distance2Mul:
|
|
1320
|
+
return "return d1 * d0 * 0.5 - 1.0;";
|
|
1321
|
+
case C.Distance2Div:
|
|
1322
|
+
return "return d0 / d1 - 1.0;";
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
function sa(d, e, t) {
|
|
1326
|
+
const i = pe * t, r = d === M.Euclidean && e !== C.CellValue ? `
|
|
1327
|
+
distance0 = sqrt(distance0);
|
|
1328
|
+
distance1 = sqrt(distance1);` : "";
|
|
1329
|
+
return `
|
|
1330
|
+
${E()}
|
|
1331
|
+
${N()}
|
|
1332
|
+
${I()}
|
|
1333
|
+
${ce()}
|
|
1334
|
+
|
|
1335
|
+
const CELL_JITTER_2D: f32 = ${i};
|
|
1336
|
+
|
|
1337
|
+
fn cellDist2d(vecX: f32, vecY: f32) -> f32 {
|
|
1338
|
+
${he(d)}
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
fn cellReturn2d(d0: f32, d1: f32, closestHash: i32) -> f32 {
|
|
1342
|
+
${T(e)}
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
fn cellular2d(seed: i32, x: f32, y: f32) -> f32 {
|
|
1346
|
+
let xr = i32(floor(x + 0.5));
|
|
1347
|
+
let yr = i32(floor(y + 0.5));
|
|
1348
|
+
|
|
1349
|
+
var distance0: f32 = 1e20;
|
|
1350
|
+
var distance1: f32 = 1e20;
|
|
1351
|
+
var closestHash: i32 = 0;
|
|
1352
|
+
|
|
1353
|
+
var xPrimed = imul(xr - 1, PRIME_X);
|
|
1354
|
+
let yPrimedBase = imul(yr - 1, PRIME_Y);
|
|
1355
|
+
|
|
1356
|
+
for (var xi: i32 = xr - 1; xi <= xr + 1; xi++) {
|
|
1357
|
+
var yPrimed = yPrimedBase;
|
|
1358
|
+
|
|
1359
|
+
for (var yi: i32 = yr - 1; yi <= yr + 1; yi++) {
|
|
1360
|
+
let hash = hashR2(seed, xPrimed, yPrimed);
|
|
1361
|
+
let idx = hash & (255 << 1u);
|
|
1362
|
+
|
|
1363
|
+
let vecX = f32(xi) - x + RAND_VECS_2D[idx] * CELL_JITTER_2D;
|
|
1364
|
+
let vecY = f32(yi) - y + RAND_VECS_2D[idx | 1] * CELL_JITTER_2D;
|
|
1365
|
+
|
|
1366
|
+
let newDist = cellDist2d(vecX, vecY);
|
|
1367
|
+
|
|
1368
|
+
distance1 = max(min(distance1, newDist), distance0);
|
|
1369
|
+
if (newDist < distance0) {
|
|
1370
|
+
distance0 = newDist;
|
|
1371
|
+
closestHash = hash;
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
yPrimed += PRIME_Y;
|
|
1375
|
+
}
|
|
1376
|
+
xPrimed += PRIME_X;
|
|
1377
|
+
}
|
|
1378
|
+
${r}
|
|
1379
|
+
return cellReturn2d(distance0, distance1, closestHash);
|
|
1380
|
+
}
|
|
1381
|
+
`;
|
|
1382
|
+
}
|
|
1383
|
+
function ta(d, e, t) {
|
|
1384
|
+
const i = me * t, r = d === M.Euclidean && e !== C.CellValue ? `
|
|
1385
|
+
distance0 = sqrt(distance0);
|
|
1386
|
+
distance1 = sqrt(distance1);` : "";
|
|
1387
|
+
return `
|
|
1388
|
+
${E()}
|
|
1389
|
+
${N()}
|
|
1390
|
+
${S()}
|
|
1391
|
+
${ue()}
|
|
1392
|
+
|
|
1393
|
+
const CELL_JITTER_3D: f32 = ${i};
|
|
1394
|
+
|
|
1395
|
+
fn cellDist3d(vecX: f32, vecY: f32, vecZ: f32) -> f32 {
|
|
1396
|
+
${Ee(d)}
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
fn cellReturn3d(d0: f32, d1: f32, closestHash: i32) -> f32 {
|
|
1400
|
+
${T(e)}
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
fn cellular3d(seed: i32, x: f32, y: f32, z: f32) -> f32 {
|
|
1404
|
+
let xr = i32(floor(x + 0.5));
|
|
1405
|
+
let yr = i32(floor(y + 0.5));
|
|
1406
|
+
let zr = i32(floor(z + 0.5));
|
|
1407
|
+
|
|
1408
|
+
var distance0: f32 = 1e20;
|
|
1409
|
+
var distance1: f32 = 1e20;
|
|
1410
|
+
var closestHash: i32 = 0;
|
|
1411
|
+
|
|
1412
|
+
var xPrimed = imul(xr - 1, PRIME_X);
|
|
1413
|
+
let yPrimedBase = imul(yr - 1, PRIME_Y);
|
|
1414
|
+
let zPrimedBase = imul(zr - 1, PRIME_Z);
|
|
1415
|
+
|
|
1416
|
+
for (var xi: i32 = xr - 1; xi <= xr + 1; xi++) {
|
|
1417
|
+
var yPrimed = yPrimedBase;
|
|
1418
|
+
|
|
1419
|
+
for (var yi: i32 = yr - 1; yi <= yr + 1; yi++) {
|
|
1420
|
+
var zPrimed = zPrimedBase;
|
|
1421
|
+
|
|
1422
|
+
for (var zi: i32 = zr - 1; zi <= zr + 1; zi++) {
|
|
1423
|
+
let hash = hashR3(seed, xPrimed, yPrimed, zPrimed);
|
|
1424
|
+
let idx = hash & (255 << 2u);
|
|
1425
|
+
|
|
1426
|
+
let vecX = f32(xi) - x + RAND_VECS_3D[idx] * CELL_JITTER_3D;
|
|
1427
|
+
let vecY = f32(yi) - y + RAND_VECS_3D[idx | 1] * CELL_JITTER_3D;
|
|
1428
|
+
let vecZ = f32(zi) - z + RAND_VECS_3D[idx | 2] * CELL_JITTER_3D;
|
|
1429
|
+
|
|
1430
|
+
let newDist = cellDist3d(vecX, vecY, vecZ);
|
|
1431
|
+
|
|
1432
|
+
distance1 = max(min(distance1, newDist), distance0);
|
|
1433
|
+
if (newDist < distance0) {
|
|
1434
|
+
distance0 = newDist;
|
|
1435
|
+
closestHash = hash;
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
zPrimed += PRIME_Z;
|
|
1439
|
+
}
|
|
1440
|
+
yPrimed += PRIME_Y;
|
|
1441
|
+
}
|
|
1442
|
+
xPrimed += PRIME_X;
|
|
1443
|
+
}
|
|
1444
|
+
${r}
|
|
1445
|
+
return cellReturn3d(distance0, distance1, closestHash);
|
|
1446
|
+
}
|
|
1447
|
+
`;
|
|
1448
|
+
}
|
|
1449
|
+
const la = ["primes", "imul", "hashR2", "randVecs2D"], da = ["primes", "imul", "hashR3", "randVecs3D"];
|
|
1450
|
+
function oa(d, e, t) {
|
|
1451
|
+
const i = pe * t, r = d === M.Euclidean && e !== C.CellValue ? `
|
|
1452
|
+
distance0 = sqrt(distance0);
|
|
1453
|
+
distance1 = sqrt(distance1);` : "";
|
|
1454
|
+
return `
|
|
1455
|
+
const CELL_JITTER_2D: f32 = ${i};
|
|
1456
|
+
|
|
1457
|
+
fn cellDist2d(vecX: f32, vecY: f32) -> f32 {
|
|
1458
|
+
${he(d)}
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
fn cellReturn2d(d0: f32, d1: f32, closestHash: i32) -> f32 {
|
|
1462
|
+
${T(e)}
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
fn cellular2d(seed: i32, x: f32, y: f32) -> f32 {
|
|
1466
|
+
let xr = i32(floor(x + 0.5));
|
|
1467
|
+
let yr = i32(floor(y + 0.5));
|
|
1468
|
+
|
|
1469
|
+
var distance0: f32 = 1e20;
|
|
1470
|
+
var distance1: f32 = 1e20;
|
|
1471
|
+
var closestHash: i32 = 0;
|
|
1472
|
+
|
|
1473
|
+
var xPrimed = imul(xr - 1, PRIME_X);
|
|
1474
|
+
let yPrimedBase = imul(yr - 1, PRIME_Y);
|
|
1475
|
+
|
|
1476
|
+
for (var xi: i32 = xr - 1; xi <= xr + 1; xi++) {
|
|
1477
|
+
var yPrimed = yPrimedBase;
|
|
1478
|
+
|
|
1479
|
+
for (var yi: i32 = yr - 1; yi <= yr + 1; yi++) {
|
|
1480
|
+
let hash = hashR2(seed, xPrimed, yPrimed);
|
|
1481
|
+
let idx = hash & (255 << 1u);
|
|
1482
|
+
|
|
1483
|
+
let vecX = f32(xi) - x + RAND_VECS_2D[idx] * CELL_JITTER_2D;
|
|
1484
|
+
let vecY = f32(yi) - y + RAND_VECS_2D[idx | 1] * CELL_JITTER_2D;
|
|
1485
|
+
|
|
1486
|
+
let newDist = cellDist2d(vecX, vecY);
|
|
1487
|
+
|
|
1488
|
+
distance1 = max(min(distance1, newDist), distance0);
|
|
1489
|
+
if (newDist < distance0) {
|
|
1490
|
+
distance0 = newDist;
|
|
1491
|
+
closestHash = hash;
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
yPrimed += PRIME_Y;
|
|
1495
|
+
}
|
|
1496
|
+
xPrimed += PRIME_X;
|
|
1497
|
+
}
|
|
1498
|
+
${r}
|
|
1499
|
+
return cellReturn2d(distance0, distance1, closestHash);
|
|
1500
|
+
}
|
|
1501
|
+
`;
|
|
1502
|
+
}
|
|
1503
|
+
function xa(d, e, t) {
|
|
1504
|
+
const i = me * t, r = d === M.Euclidean && e !== C.CellValue ? `
|
|
1505
|
+
distance0 = sqrt(distance0);
|
|
1506
|
+
distance1 = sqrt(distance1);` : "";
|
|
1507
|
+
return `
|
|
1508
|
+
const CELL_JITTER_3D: f32 = ${i};
|
|
1509
|
+
|
|
1510
|
+
fn cellDist3d(vecX: f32, vecY: f32, vecZ: f32) -> f32 {
|
|
1511
|
+
${Ee(d)}
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
fn cellReturn3d(d0: f32, d1: f32, closestHash: i32) -> f32 {
|
|
1515
|
+
${T(e)}
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
fn cellular3d(seed: i32, x: f32, y: f32, z: f32) -> f32 {
|
|
1519
|
+
let xr = i32(floor(x + 0.5));
|
|
1520
|
+
let yr = i32(floor(y + 0.5));
|
|
1521
|
+
let zr = i32(floor(z + 0.5));
|
|
1522
|
+
|
|
1523
|
+
var distance0: f32 = 1e20;
|
|
1524
|
+
var distance1: f32 = 1e20;
|
|
1525
|
+
var closestHash: i32 = 0;
|
|
1526
|
+
|
|
1527
|
+
var xPrimed = imul(xr - 1, PRIME_X);
|
|
1528
|
+
let yPrimedBase = imul(yr - 1, PRIME_Y);
|
|
1529
|
+
let zPrimedBase = imul(zr - 1, PRIME_Z);
|
|
1530
|
+
|
|
1531
|
+
for (var xi: i32 = xr - 1; xi <= xr + 1; xi++) {
|
|
1532
|
+
var yPrimed = yPrimedBase;
|
|
1533
|
+
|
|
1534
|
+
for (var yi: i32 = yr - 1; yi <= yr + 1; yi++) {
|
|
1535
|
+
var zPrimed = zPrimedBase;
|
|
1536
|
+
|
|
1537
|
+
for (var zi: i32 = zr - 1; zi <= zr + 1; zi++) {
|
|
1538
|
+
let hash = hashR3(seed, xPrimed, yPrimed, zPrimed);
|
|
1539
|
+
let idx = hash & (255 << 2u);
|
|
1540
|
+
|
|
1541
|
+
let vecX = f32(xi) - x + RAND_VECS_3D[idx] * CELL_JITTER_3D;
|
|
1542
|
+
let vecY = f32(yi) - y + RAND_VECS_3D[idx | 1] * CELL_JITTER_3D;
|
|
1543
|
+
let vecZ = f32(zi) - z + RAND_VECS_3D[idx | 2] * CELL_JITTER_3D;
|
|
1544
|
+
|
|
1545
|
+
let newDist = cellDist3d(vecX, vecY, vecZ);
|
|
1546
|
+
|
|
1547
|
+
distance1 = max(min(distance1, newDist), distance0);
|
|
1548
|
+
if (newDist < distance0) {
|
|
1549
|
+
distance0 = newDist;
|
|
1550
|
+
closestHash = hash;
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
zPrimed += PRIME_Z;
|
|
1554
|
+
}
|
|
1555
|
+
yPrimed += PRIME_Y;
|
|
1556
|
+
}
|
|
1557
|
+
xPrimed += PRIME_X;
|
|
1558
|
+
}
|
|
1559
|
+
${r}
|
|
1560
|
+
return cellReturn3d(distance0, distance1, closestHash);
|
|
1561
|
+
}
|
|
1562
|
+
`;
|
|
1563
|
+
}
|
|
1564
|
+
function k(d, e, t, i, a, r, s, l) {
|
|
1565
|
+
return `
|
|
1566
|
+
${d}
|
|
1567
|
+
|
|
1568
|
+
fn noise(x: f32, y: f32) -> f32 {
|
|
1569
|
+
var sum: f32 = 0.0;
|
|
1570
|
+
var amp: f32 = ${l};
|
|
1571
|
+
var px = x;
|
|
1572
|
+
var py = y;
|
|
1573
|
+
var s: i32 = ${t | 0};
|
|
1574
|
+
|
|
1575
|
+
for (var i: i32 = 0; i < ${i}; i++) {
|
|
1576
|
+
let n = ${e}(s, px, py);
|
|
1577
|
+
sum += n * amp;
|
|
1578
|
+
amp *= mix(1.0, min(n + 1.0, 2.0) * 0.5, ${s});
|
|
1579
|
+
|
|
1580
|
+
px *= ${a};
|
|
1581
|
+
py *= ${a};
|
|
1582
|
+
amp *= ${r};
|
|
1583
|
+
s += 1;
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1586
|
+
return sum;
|
|
1587
|
+
}
|
|
1588
|
+
`;
|
|
1589
|
+
}
|
|
1590
|
+
function b(d, e, t, i, a, r, s, l) {
|
|
1591
|
+
return `
|
|
1592
|
+
${d}
|
|
1593
|
+
|
|
1594
|
+
fn noise(x: f32, y: f32, z: f32) -> f32 {
|
|
1595
|
+
var sum: f32 = 0.0;
|
|
1596
|
+
var amp: f32 = ${l};
|
|
1597
|
+
var px = x;
|
|
1598
|
+
var py = y;
|
|
1599
|
+
var pz = z;
|
|
1600
|
+
var s: i32 = ${t | 0};
|
|
1601
|
+
|
|
1602
|
+
for (var i: i32 = 0; i < ${i}; i++) {
|
|
1603
|
+
let n = ${e}(s, px, py, pz);
|
|
1604
|
+
sum += n * amp;
|
|
1605
|
+
amp *= mix(1.0, min(n + 1.0, 2.0) * 0.5, ${s});
|
|
1606
|
+
|
|
1607
|
+
px *= ${a};
|
|
1608
|
+
py *= ${a};
|
|
1609
|
+
pz *= ${a};
|
|
1610
|
+
amp *= ${r};
|
|
1611
|
+
s += 1;
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
return sum;
|
|
1615
|
+
}
|
|
1616
|
+
`;
|
|
1617
|
+
}
|
|
1618
|
+
function se(d, e, t, i, a, r, s, l) {
|
|
1619
|
+
return `
|
|
1620
|
+
${d}
|
|
1621
|
+
|
|
1622
|
+
fn noise(x: f32, y: f32) -> f32 {
|
|
1623
|
+
var sum: f32 = 0.0;
|
|
1624
|
+
var amp: f32 = ${l};
|
|
1625
|
+
var px = x;
|
|
1626
|
+
var py = y;
|
|
1627
|
+
var s: i32 = ${t | 0};
|
|
1628
|
+
|
|
1629
|
+
for (var i: i32 = 0; i < ${i}; i++) {
|
|
1630
|
+
var n = ${e}(s, px, py);
|
|
1631
|
+
n = abs(n);
|
|
1632
|
+
sum += (n * -2.0 + 1.0) * amp;
|
|
1633
|
+
amp *= mix(1.0, 1.0 - n, ${s});
|
|
1634
|
+
|
|
1635
|
+
px *= ${a};
|
|
1636
|
+
py *= ${a};
|
|
1637
|
+
amp *= ${r};
|
|
1638
|
+
s += 1;
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1641
|
+
return sum;
|
|
1642
|
+
}
|
|
1643
|
+
`;
|
|
1644
|
+
}
|
|
1645
|
+
function te(d, e, t, i, a, r, s, l) {
|
|
1646
|
+
return `
|
|
1647
|
+
${d}
|
|
1648
|
+
|
|
1649
|
+
fn noise(x: f32, y: f32, z: f32) -> f32 {
|
|
1650
|
+
var sum: f32 = 0.0;
|
|
1651
|
+
var amp: f32 = ${l};
|
|
1652
|
+
var px = x;
|
|
1653
|
+
var py = y;
|
|
1654
|
+
var pz = z;
|
|
1655
|
+
var s: i32 = ${t | 0};
|
|
1656
|
+
|
|
1657
|
+
for (var i: i32 = 0; i < ${i}; i++) {
|
|
1658
|
+
var n = ${e}(s, px, py, pz);
|
|
1659
|
+
n = abs(n);
|
|
1660
|
+
sum += (n * -2.0 + 1.0) * amp;
|
|
1661
|
+
amp *= mix(1.0, 1.0 - n, ${s});
|
|
1662
|
+
|
|
1663
|
+
px *= ${a};
|
|
1664
|
+
py *= ${a};
|
|
1665
|
+
pz *= ${a};
|
|
1666
|
+
amp *= ${r};
|
|
1667
|
+
s += 1;
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1670
|
+
return sum;
|
|
1671
|
+
}
|
|
1672
|
+
`;
|
|
1673
|
+
}
|
|
1674
|
+
function na(d, e, t, i, a, r, s, l, o) {
|
|
1675
|
+
return `
|
|
1676
|
+
${d}
|
|
1677
|
+
${K()}
|
|
1678
|
+
|
|
1679
|
+
fn noise(x: f32, y: f32) -> f32 {
|
|
1680
|
+
var sum: f32 = 0.0;
|
|
1681
|
+
var amp: f32 = ${l};
|
|
1682
|
+
var px = x;
|
|
1683
|
+
var py = y;
|
|
1684
|
+
var s: i32 = ${t | 0};
|
|
1685
|
+
|
|
1686
|
+
for (var i: i32 = 0; i < ${i}; i++) {
|
|
1687
|
+
let n = pingPong((${e}(s, px, py) + 1.0) * ${o});
|
|
1688
|
+
sum += (n - 0.5) * 2.0 * amp;
|
|
1689
|
+
amp *= mix(1.0, n, ${s});
|
|
1690
|
+
|
|
1691
|
+
px *= ${a};
|
|
1692
|
+
py *= ${a};
|
|
1693
|
+
amp *= ${r};
|
|
1694
|
+
s += 1;
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
return sum;
|
|
1698
|
+
}
|
|
1699
|
+
`;
|
|
1700
|
+
}
|
|
1701
|
+
function ya(d, e, t, i, a, r, s, l, o) {
|
|
1702
|
+
return `
|
|
1703
|
+
${d}
|
|
1704
|
+
${K()}
|
|
1705
|
+
|
|
1706
|
+
fn noise(x: f32, y: f32, z: f32) -> f32 {
|
|
1707
|
+
var sum: f32 = 0.0;
|
|
1708
|
+
var amp: f32 = ${l};
|
|
1709
|
+
var px = x;
|
|
1710
|
+
var py = y;
|
|
1711
|
+
var pz = z;
|
|
1712
|
+
var s: i32 = ${t | 0};
|
|
1713
|
+
|
|
1714
|
+
for (var i: i32 = 0; i < ${i}; i++) {
|
|
1715
|
+
let n = pingPong((${e}(s, px, py, pz) + 1.0) * ${o});
|
|
1716
|
+
sum += (n - 0.5) * 2.0 * amp;
|
|
1717
|
+
amp *= mix(1.0, n, ${s});
|
|
1718
|
+
|
|
1719
|
+
px *= ${a};
|
|
1720
|
+
py *= ${a};
|
|
1721
|
+
pz *= ${a};
|
|
1722
|
+
amp *= ${r};
|
|
1723
|
+
s += 1;
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
return sum;
|
|
1727
|
+
}
|
|
1728
|
+
`;
|
|
1729
|
+
}
|
|
1730
|
+
const fa = {
|
|
1731
|
+
primes: E,
|
|
1732
|
+
primesDouble: () => `const PRIME_X_2: i32 = ${A << 1 | 0};
|
|
1733
|
+
const PRIME_Y_2: i32 = ${G << 1 | 0};
|
|
1734
|
+
const PRIME_Z_2: i32 = ${X << 1 | 0};`,
|
|
1735
|
+
imul: N,
|
|
1736
|
+
hashR2: I,
|
|
1737
|
+
hashR3: S,
|
|
1738
|
+
gradients2D: W,
|
|
1739
|
+
gradients3D: j,
|
|
1740
|
+
randVecs2D: ce,
|
|
1741
|
+
randVecs3D: ue,
|
|
1742
|
+
valCoordR2: O,
|
|
1743
|
+
valCoordR3: q,
|
|
1744
|
+
gradCoordR2: V,
|
|
1745
|
+
gradCoordR3: F,
|
|
1746
|
+
interpHermite: J,
|
|
1747
|
+
interpQuintic: Q,
|
|
1748
|
+
cubicLerp: U,
|
|
1749
|
+
pingPong: K
|
|
1750
|
+
}, ca = {
|
|
1751
|
+
primesDouble: ["primes"],
|
|
1752
|
+
hashR2: ["primes"],
|
|
1753
|
+
hashR3: ["primes"],
|
|
1754
|
+
valCoordR2: ["hashR2", "primes"],
|
|
1755
|
+
valCoordR3: ["hashR3", "primes"],
|
|
1756
|
+
gradCoordR2: ["hashR2", "primes", "gradients2D"],
|
|
1757
|
+
gradCoordR3: ["hashR3", "primes", "gradients3D"]
|
|
1758
|
+
};
|
|
1759
|
+
function Me(...d) {
|
|
1760
|
+
const e = /* @__PURE__ */ new Set();
|
|
1761
|
+
function t(a) {
|
|
1762
|
+
if (e.has(a)) return;
|
|
1763
|
+
const r = ca[a];
|
|
1764
|
+
if (r)
|
|
1765
|
+
for (const s of r) t(s);
|
|
1766
|
+
e.add(a);
|
|
1767
|
+
}
|
|
1768
|
+
for (const a of d)
|
|
1769
|
+
for (const r of a) t(r);
|
|
1770
|
+
const i = [];
|
|
1771
|
+
for (const a of e)
|
|
1772
|
+
i.push(fa[a]());
|
|
1773
|
+
return i.join(`
|
|
1774
|
+
`);
|
|
1775
|
+
}
|
|
1776
|
+
const le = [
|
|
1777
|
+
"primes",
|
|
1778
|
+
"imul",
|
|
1779
|
+
"hashR2",
|
|
1780
|
+
"randVecs2D",
|
|
1781
|
+
"interpHermite"
|
|
1782
|
+
], de = [
|
|
1783
|
+
"primes",
|
|
1784
|
+
"imul",
|
|
1785
|
+
"hashR3",
|
|
1786
|
+
"randVecs3D",
|
|
1787
|
+
"interpHermite"
|
|
1788
|
+
];
|
|
1789
|
+
function oe() {
|
|
1790
|
+
return `
|
|
1791
|
+
fn basicgrid_warp2d(seed: i32, x: f32, y: f32) -> vec2<f32> {
|
|
1792
|
+
let x0i = i32(floor(x));
|
|
1793
|
+
let y0i = i32(floor(y));
|
|
1794
|
+
|
|
1795
|
+
let xs = interpHermite(x - f32(x0i));
|
|
1796
|
+
let ys = interpHermite(y - f32(y0i));
|
|
1797
|
+
|
|
1798
|
+
let x0 = imul(x0i, PRIME_X);
|
|
1799
|
+
let y0 = imul(y0i, PRIME_Y);
|
|
1800
|
+
let x1 = x0 + PRIME_X;
|
|
1801
|
+
let y1 = y0 + PRIME_Y;
|
|
1802
|
+
|
|
1803
|
+
var hash0 = hashR2(seed, x0, y0) & (255 << 1u);
|
|
1804
|
+
var hash1 = hashR2(seed, x1, y0) & (255 << 1u);
|
|
1805
|
+
|
|
1806
|
+
let lx0x = mix(RAND_VECS_2D[hash0], RAND_VECS_2D[hash1], xs);
|
|
1807
|
+
let ly0x = mix(RAND_VECS_2D[hash0 | 1], RAND_VECS_2D[hash1 | 1], xs);
|
|
1808
|
+
|
|
1809
|
+
hash0 = hashR2(seed, x0, y1) & (255 << 1u);
|
|
1810
|
+
hash1 = hashR2(seed, x1, y1) & (255 << 1u);
|
|
1811
|
+
|
|
1812
|
+
let lx1x = mix(RAND_VECS_2D[hash0], RAND_VECS_2D[hash1], xs);
|
|
1813
|
+
let ly1x = mix(RAND_VECS_2D[hash0 | 1], RAND_VECS_2D[hash1 | 1], xs);
|
|
1814
|
+
|
|
1815
|
+
return vec2<f32>(
|
|
1816
|
+
mix(lx0x, lx1x, ys),
|
|
1817
|
+
mix(ly0x, ly1x, ys)
|
|
1818
|
+
);
|
|
1819
|
+
}`;
|
|
1820
|
+
}
|
|
1821
|
+
function xe() {
|
|
1822
|
+
return `
|
|
1823
|
+
fn basicgrid_warp3d(seed: i32, x: f32, y: f32, z: f32) -> vec3<f32> {
|
|
1824
|
+
let x0i = i32(floor(x));
|
|
1825
|
+
let y0i = i32(floor(y));
|
|
1826
|
+
let z0i = i32(floor(z));
|
|
1827
|
+
|
|
1828
|
+
let xs = interpHermite(x - f32(x0i));
|
|
1829
|
+
let ys = interpHermite(y - f32(y0i));
|
|
1830
|
+
let zs = interpHermite(z - f32(z0i));
|
|
1831
|
+
|
|
1832
|
+
let x0 = imul(x0i, PRIME_X);
|
|
1833
|
+
let y0 = imul(y0i, PRIME_Y);
|
|
1834
|
+
let z0 = imul(z0i, PRIME_Z);
|
|
1835
|
+
let x1 = x0 + PRIME_X;
|
|
1836
|
+
let y1 = y0 + PRIME_Y;
|
|
1837
|
+
let z1 = z0 + PRIME_Z;
|
|
1838
|
+
|
|
1839
|
+
// First layer (z0)
|
|
1840
|
+
var hash0 = hashR3(seed, x0, y0, z0) & (255 << 2u);
|
|
1841
|
+
var hash1 = hashR3(seed, x1, y0, z0) & (255 << 2u);
|
|
1842
|
+
|
|
1843
|
+
var lx0x = mix(RAND_VECS_3D[hash0], RAND_VECS_3D[hash1], xs);
|
|
1844
|
+
var ly0x = mix(RAND_VECS_3D[hash0 | 1], RAND_VECS_3D[hash1 | 1], xs);
|
|
1845
|
+
var lz0x = mix(RAND_VECS_3D[hash0 | 2], RAND_VECS_3D[hash1 | 2], xs);
|
|
1846
|
+
|
|
1847
|
+
hash0 = hashR3(seed, x0, y1, z0) & (255 << 2u);
|
|
1848
|
+
hash1 = hashR3(seed, x1, y1, z0) & (255 << 2u);
|
|
1849
|
+
|
|
1850
|
+
var lx1x = mix(RAND_VECS_3D[hash0], RAND_VECS_3D[hash1], xs);
|
|
1851
|
+
var ly1x = mix(RAND_VECS_3D[hash0 | 1], RAND_VECS_3D[hash1 | 1], xs);
|
|
1852
|
+
var lz1x = mix(RAND_VECS_3D[hash0 | 2], RAND_VECS_3D[hash1 | 2], xs);
|
|
1853
|
+
|
|
1854
|
+
let lx0y = mix(lx0x, lx1x, ys);
|
|
1855
|
+
let ly0y = mix(ly0x, ly1x, ys);
|
|
1856
|
+
let lz0y = mix(lz0x, lz1x, ys);
|
|
1857
|
+
|
|
1858
|
+
// Second layer (z1)
|
|
1859
|
+
hash0 = hashR3(seed, x0, y0, z1) & (255 << 2u);
|
|
1860
|
+
hash1 = hashR3(seed, x1, y0, z1) & (255 << 2u);
|
|
1861
|
+
|
|
1862
|
+
lx0x = mix(RAND_VECS_3D[hash0], RAND_VECS_3D[hash1], xs);
|
|
1863
|
+
ly0x = mix(RAND_VECS_3D[hash0 | 1], RAND_VECS_3D[hash1 | 1], xs);
|
|
1864
|
+
lz0x = mix(RAND_VECS_3D[hash0 | 2], RAND_VECS_3D[hash1 | 2], xs);
|
|
1865
|
+
|
|
1866
|
+
hash0 = hashR3(seed, x0, y1, z1) & (255 << 2u);
|
|
1867
|
+
hash1 = hashR3(seed, x1, y1, z1) & (255 << 2u);
|
|
1868
|
+
|
|
1869
|
+
lx1x = mix(RAND_VECS_3D[hash0], RAND_VECS_3D[hash1], xs);
|
|
1870
|
+
ly1x = mix(RAND_VECS_3D[hash0 | 1], RAND_VECS_3D[hash1 | 1], xs);
|
|
1871
|
+
lz1x = mix(RAND_VECS_3D[hash0 | 2], RAND_VECS_3D[hash1 | 2], xs);
|
|
1872
|
+
|
|
1873
|
+
return vec3<f32>(
|
|
1874
|
+
mix(lx0y, mix(lx0x, lx1x, ys), zs),
|
|
1875
|
+
mix(ly0y, mix(ly0x, ly1x, ys), zs),
|
|
1876
|
+
mix(lz0y, mix(lz0x, lz1x, ys), zs)
|
|
1877
|
+
);
|
|
1878
|
+
}`;
|
|
1879
|
+
}
|
|
1880
|
+
const Pe = 1.7320508075688772, ua = 0.5 * (Pe - 1), P = (3 - Pe) / 6, Ra = [
|
|
1881
|
+
"primes",
|
|
1882
|
+
"imul",
|
|
1883
|
+
"hashR2",
|
|
1884
|
+
"randVecs2D"
|
|
1885
|
+
], _a = [
|
|
1886
|
+
"primes",
|
|
1887
|
+
"imul",
|
|
1888
|
+
"hashR2",
|
|
1889
|
+
"randVecs2D",
|
|
1890
|
+
"gradients2D"
|
|
1891
|
+
], va = [
|
|
1892
|
+
"primes",
|
|
1893
|
+
"imul",
|
|
1894
|
+
"hashR3",
|
|
1895
|
+
"randVecs3D"
|
|
1896
|
+
], za = [
|
|
1897
|
+
"primes",
|
|
1898
|
+
"imul",
|
|
1899
|
+
"hashR3",
|
|
1900
|
+
"randVecs3D",
|
|
1901
|
+
"gradients3D"
|
|
1902
|
+
];
|
|
1903
|
+
function ne(d, e) {
|
|
1904
|
+
return `
|
|
1905
|
+
fn os2_warp2d_contrib(seed: i32, ip: i32, jp: i32, dx: f32, dy: f32, a_in: f32) -> vec3<f32> {
|
|
1906
|
+
if (a_in <= 0.0) { return vec3<f32>(0.0, 0.0, 0.0); }
|
|
1907
|
+
let aaaa = a_in * a_in * (a_in * a_in);
|
|
1908
|
+
var xo: f32;
|
|
1909
|
+
var yo: f32;${e ? `
|
|
1910
|
+
let rh = hashR2(seed, ip, jp) & (255 << 1u);
|
|
1911
|
+
xo = RAND_VECS_2D[rh];
|
|
1912
|
+
yo = RAND_VECS_2D[rh | 1];` : `
|
|
1913
|
+
let rh = hashR2(seed, ip, jp);
|
|
1914
|
+
let idx1 = rh & (127 << 1u);
|
|
1915
|
+
let idx2 = (rh >> 7u) & (255 << 1u);
|
|
1916
|
+
let xg = GRADIENTS_2D[idx1];
|
|
1917
|
+
let yg = GRADIENTS_2D[idx1 | 1];
|
|
1918
|
+
let val = dx * xg + dy * yg;
|
|
1919
|
+
xo = val * RAND_VECS_2D[idx2];
|
|
1920
|
+
yo = val * RAND_VECS_2D[idx2 | 1];`}
|
|
1921
|
+
return vec3<f32>(aaaa * xo, aaaa * yo, 0.0);
|
|
1922
|
+
}
|
|
1923
|
+
|
|
1924
|
+
fn os2_warp2d(seed: i32, cx: f32, cy: f32) -> vec2<f32> {
|
|
1925
|
+
let t0 = (cx + cy) * ${ua};
|
|
1926
|
+
let x = (cx + t0) * ${d};
|
|
1927
|
+
let y = (cy + t0) * ${d};
|
|
1928
|
+
|
|
1929
|
+
let i = i32(floor(x));
|
|
1930
|
+
let j = i32(floor(y));
|
|
1931
|
+
let xi = x - f32(i);
|
|
1932
|
+
let yi = y - f32(j);
|
|
1933
|
+
|
|
1934
|
+
let t = (xi + yi) * ${P};
|
|
1935
|
+
let x0 = xi - t;
|
|
1936
|
+
let y0 = yi - t;
|
|
1937
|
+
|
|
1938
|
+
let iPrimed = imul(i, PRIME_X);
|
|
1939
|
+
let jPrimed = imul(j, PRIME_Y);
|
|
1940
|
+
|
|
1941
|
+
let a0 = 0.5 - x0 * x0 - y0 * y0;
|
|
1942
|
+
|
|
1943
|
+
// First contribution
|
|
1944
|
+
let c0 = os2_warp2d_contrib(seed, iPrimed, jPrimed, x0, y0, a0);
|
|
1945
|
+
|
|
1946
|
+
// Second contribution (center)
|
|
1947
|
+
let c_val = 2.0 * (1.0 - 2.0 * ${P}) * (1.0 / ${P} - 2.0) * t + (-2.0 * (1.0 - 2.0 * ${P}) * (1.0 - 2.0 * ${P}) + a0);
|
|
1948
|
+
let x2 = x0 + (2.0 * ${P} - 1.0);
|
|
1949
|
+
let y2 = y0 + (2.0 * ${P} - 1.0);
|
|
1950
|
+
let c1 = os2_warp2d_contrib(seed, iPrimed + PRIME_X, jPrimed + PRIME_Y, x2, y2, c_val);
|
|
1951
|
+
|
|
1952
|
+
// Third contribution (depends on simplex half)
|
|
1953
|
+
var c2 = vec3<f32>(0.0, 0.0, 0.0);
|
|
1954
|
+
if (y0 > x0) {
|
|
1955
|
+
let x1 = x0 + ${P};
|
|
1956
|
+
let y1 = y0 + (${P} - 1.0);
|
|
1957
|
+
let b = 0.5 - x1 * x1 - y1 * y1;
|
|
1958
|
+
c2 = os2_warp2d_contrib(seed, iPrimed, jPrimed + PRIME_Y, x1, y1, b);
|
|
1959
|
+
} else {
|
|
1960
|
+
let x1 = x0 + (${P} - 1.0);
|
|
1961
|
+
let y1 = y0 + ${P};
|
|
1962
|
+
let b = 0.5 - x1 * x1 - y1 * y1;
|
|
1963
|
+
c2 = os2_warp2d_contrib(seed, iPrimed + PRIME_X, jPrimed, x1, y1, b);
|
|
1964
|
+
}
|
|
1965
|
+
|
|
1966
|
+
return vec2<f32>(
|
|
1967
|
+
c0.x + c1.x + c2.x,
|
|
1968
|
+
c0.y + c1.y + c2.y
|
|
1969
|
+
);
|
|
1970
|
+
}`;
|
|
1971
|
+
}
|
|
1972
|
+
function ye(d) {
|
|
1973
|
+
return `
|
|
1974
|
+
fn os2_warp3d_contrib(s: i32, ip: i32, jp: i32, kp: i32, dx: f32, dy: f32, dz: f32, a_in: f32) -> vec3<f32> {
|
|
1975
|
+
if (a_in <= 0.0) { return vec3<f32>(0.0, 0.0, 0.0); }
|
|
1976
|
+
let aaaa = a_in * a_in * (a_in * a_in);
|
|
1977
|
+
var xo: f32;
|
|
1978
|
+
var yo: f32;
|
|
1979
|
+
var zo: f32;${d ? `
|
|
1980
|
+
let rh = hashR3(s, ip, jp, kp) & (255 << 2u);
|
|
1981
|
+
xo = RAND_VECS_3D[rh];
|
|
1982
|
+
yo = RAND_VECS_3D[rh | 1];
|
|
1983
|
+
zo = RAND_VECS_3D[rh | 2];` : `
|
|
1984
|
+
let rh = hashR3(s, ip, jp, kp);
|
|
1985
|
+
let idx1 = rh & (63 << 2u);
|
|
1986
|
+
let idx2 = (rh >> 6u) & (255 << 2u);
|
|
1987
|
+
let xg = GRADIENTS_3D[idx1];
|
|
1988
|
+
let yg = GRADIENTS_3D[idx1 | 1];
|
|
1989
|
+
let zg = GRADIENTS_3D[idx1 | 2];
|
|
1990
|
+
let val = dx * xg + dy * yg + dz * zg;
|
|
1991
|
+
xo = val * RAND_VECS_3D[idx2];
|
|
1992
|
+
yo = val * RAND_VECS_3D[idx2 | 1];
|
|
1993
|
+
zo = val * RAND_VECS_3D[idx2 | 2];`}
|
|
1994
|
+
return vec3<f32>(aaaa * xo, aaaa * yo, aaaa * zo);
|
|
1995
|
+
}
|
|
1996
|
+
|
|
1997
|
+
fn os2_warp3d(seed_in: i32, x_in: f32, y_in: f32, z_in: f32) -> vec3<f32> {
|
|
1998
|
+
var seed = seed_in;
|
|
1999
|
+
var i = i32(round(x_in));
|
|
2000
|
+
var j = i32(round(y_in));
|
|
2001
|
+
var k = i32(round(z_in));
|
|
2002
|
+
var x0 = x_in - f32(i);
|
|
2003
|
+
var y0 = y_in - f32(j);
|
|
2004
|
+
var z0 = z_in - f32(k);
|
|
2005
|
+
|
|
2006
|
+
var xNSign = i32((-x0 - 1.0)) | 1;
|
|
2007
|
+
var yNSign = i32((-y0 - 1.0)) | 1;
|
|
2008
|
+
var zNSign = i32((-z0 - 1.0)) | 1;
|
|
2009
|
+
|
|
2010
|
+
var ax0 = f32(xNSign) * -x0;
|
|
2011
|
+
var ay0 = f32(yNSign) * -y0;
|
|
2012
|
+
var az0 = f32(zNSign) * -z0;
|
|
2013
|
+
|
|
2014
|
+
i = imul(i, PRIME_X);
|
|
2015
|
+
j = imul(j, PRIME_Y);
|
|
2016
|
+
k = imul(k, PRIME_Z);
|
|
2017
|
+
|
|
2018
|
+
var vx: f32 = 0.0;
|
|
2019
|
+
var vy: f32 = 0.0;
|
|
2020
|
+
var vz: f32 = 0.0;
|
|
2021
|
+
|
|
2022
|
+
var a = 0.6 - x0 * x0 - (y0 * y0 + z0 * z0);
|
|
2023
|
+
|
|
2024
|
+
for (var l: i32 = 0; l < 2; l++) {
|
|
2025
|
+
// First contribution
|
|
2026
|
+
let c0 = os2_warp3d_contrib(seed, i, j, k, x0, y0, z0, a);
|
|
2027
|
+
vx += c0.x;
|
|
2028
|
+
vy += c0.y;
|
|
2029
|
+
vz += c0.z;
|
|
2030
|
+
|
|
2031
|
+
// Additional contribution based on largest axis
|
|
2032
|
+
var b = a;
|
|
2033
|
+
var i1 = i;
|
|
2034
|
+
var j1 = j;
|
|
2035
|
+
var k1 = k;
|
|
2036
|
+
var x1 = x0;
|
|
2037
|
+
var y1 = y0;
|
|
2038
|
+
var z1 = z0;
|
|
2039
|
+
|
|
2040
|
+
if (ax0 >= ay0 && ax0 >= az0) {
|
|
2041
|
+
x1 += f32(xNSign);
|
|
2042
|
+
b = b + ax0 + ax0;
|
|
2043
|
+
i1 -= xNSign * PRIME_X;
|
|
2044
|
+
} else if (ay0 > ax0 && ay0 >= az0) {
|
|
2045
|
+
y1 += f32(yNSign);
|
|
2046
|
+
b = b + ay0 + ay0;
|
|
2047
|
+
j1 -= yNSign * PRIME_Y;
|
|
2048
|
+
} else {
|
|
2049
|
+
z1 += f32(zNSign);
|
|
2050
|
+
b = b + az0 + az0;
|
|
2051
|
+
k1 -= zNSign * PRIME_Z;
|
|
2052
|
+
}
|
|
2053
|
+
|
|
2054
|
+
if (b > 1.0) {
|
|
2055
|
+
let bv = b - 1.0;
|
|
2056
|
+
let c1 = os2_warp3d_contrib(seed, i1, j1, k1, x1, y1, z1, bv);
|
|
2057
|
+
vx += c1.x;
|
|
2058
|
+
vy += c1.y;
|
|
2059
|
+
vz += c1.z;
|
|
2060
|
+
}
|
|
2061
|
+
|
|
2062
|
+
if (l == 0) {
|
|
2063
|
+
ax0 = 0.5 - ax0;
|
|
2064
|
+
ay0 = 0.5 - ay0;
|
|
2065
|
+
az0 = 0.5 - az0;
|
|
2066
|
+
|
|
2067
|
+
x0 = f32(xNSign) * ax0;
|
|
2068
|
+
y0 = f32(yNSign) * ay0;
|
|
2069
|
+
z0 = f32(zNSign) * az0;
|
|
2070
|
+
|
|
2071
|
+
a += 0.75 - ax0 - (ay0 + az0);
|
|
2072
|
+
|
|
2073
|
+
i += (xNSign >> 1u) & PRIME_X;
|
|
2074
|
+
j += (yNSign >> 1u) & PRIME_Y;
|
|
2075
|
+
k += (zNSign >> 1u) & PRIME_Z;
|
|
2076
|
+
|
|
2077
|
+
xNSign = -xNSign;
|
|
2078
|
+
yNSign = -yNSign;
|
|
2079
|
+
zNSign = -zNSign;
|
|
2080
|
+
|
|
2081
|
+
seed += 1293373;
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2084
|
+
|
|
2085
|
+
return vec3<f32>(vx, vy, vz);
|
|
2086
|
+
}`;
|
|
2087
|
+
}
|
|
2088
|
+
class Ea extends fe {
|
|
2089
|
+
buildTSL2D() {
|
|
2090
|
+
const { domainWarpType: e } = this.config;
|
|
2091
|
+
return e === h.None ? this.buildNoWarp2D() : this.buildWithWarp2D();
|
|
2092
|
+
}
|
|
2093
|
+
/**
|
|
2094
|
+
* Original path: no domain warp
|
|
2095
|
+
*/
|
|
2096
|
+
buildNoWarp2D() {
|
|
2097
|
+
const { seed: e, fractalType: t } = this.config, i = this.getBaseNoiseWGSL2D();
|
|
2098
|
+
let a, r;
|
|
2099
|
+
i.needsSkew ? (a = `${i.wgsl}
|
|
2100
|
+
|
|
2101
|
+
fn ${i.fnName}_skewed(seed: i32, x: f32, y: f32) -> f32 {
|
|
2102
|
+
let F2: f32 = 0.36602540378443864;
|
|
2103
|
+
let t = (x + y) * F2;
|
|
2104
|
+
return ${i.fnName}(seed, x + t, y + t);
|
|
2105
|
+
}`, r = `${i.fnName}_skewed`) : (a = i.wgsl, r = i.fnName);
|
|
2106
|
+
let s, l;
|
|
2107
|
+
if (t === _.None)
|
|
2108
|
+
l = `${r}_entry_core`, s = `${a}
|
|
2109
|
+
|
|
2110
|
+
fn ${l}(x: f32, y: f32) -> f32 {
|
|
2111
|
+
return ${r}(${e | 0}, x, y);
|
|
2112
|
+
}`;
|
|
2113
|
+
else {
|
|
2114
|
+
const x = this.calculateFractalBounding();
|
|
2115
|
+
switch (t) {
|
|
2116
|
+
case _.FBm:
|
|
2117
|
+
s = k(
|
|
2118
|
+
a,
|
|
2119
|
+
r,
|
|
2120
|
+
e,
|
|
2121
|
+
this.config.fractalOctaves,
|
|
2122
|
+
this.config.fractalLacunarity,
|
|
2123
|
+
this.config.fractalGain,
|
|
2124
|
+
this.config.fractalWeightedStrength,
|
|
2125
|
+
x
|
|
2126
|
+
);
|
|
2127
|
+
break;
|
|
2128
|
+
case _.Ridged:
|
|
2129
|
+
s = se(
|
|
2130
|
+
a,
|
|
2131
|
+
r,
|
|
2132
|
+
e,
|
|
2133
|
+
this.config.fractalOctaves,
|
|
2134
|
+
this.config.fractalLacunarity,
|
|
2135
|
+
this.config.fractalGain,
|
|
2136
|
+
this.config.fractalWeightedStrength,
|
|
2137
|
+
x
|
|
2138
|
+
);
|
|
2139
|
+
break;
|
|
2140
|
+
case _.PingPong:
|
|
2141
|
+
s = na(
|
|
2142
|
+
a,
|
|
2143
|
+
r,
|
|
2144
|
+
e,
|
|
2145
|
+
this.config.fractalOctaves,
|
|
2146
|
+
this.config.fractalLacunarity,
|
|
2147
|
+
this.config.fractalGain,
|
|
2148
|
+
this.config.fractalWeightedStrength,
|
|
2149
|
+
x,
|
|
2150
|
+
this.config.fractalPingPongStrength
|
|
2151
|
+
);
|
|
2152
|
+
break;
|
|
2153
|
+
default:
|
|
2154
|
+
s = k(
|
|
2155
|
+
a,
|
|
2156
|
+
r,
|
|
2157
|
+
e,
|
|
2158
|
+
this.config.fractalOctaves,
|
|
2159
|
+
this.config.fractalLacunarity,
|
|
2160
|
+
this.config.fractalGain,
|
|
2161
|
+
this.config.fractalWeightedStrength,
|
|
2162
|
+
x
|
|
2163
|
+
);
|
|
2164
|
+
}
|
|
2165
|
+
l = "noise";
|
|
2166
|
+
}
|
|
2167
|
+
const o = `fn noise_entry(x_in: f32, y_in: f32) -> f32 {
|
|
2168
|
+
return ${l}(x_in * ${this.config.frequency}, y_in * ${this.config.frequency});
|
|
2169
|
+
}
|
|
2170
|
+
${s}`;
|
|
2171
|
+
return L(o);
|
|
2172
|
+
}
|
|
2173
|
+
/**
|
|
2174
|
+
* Warp-enabled path: single wgslFn with deduplicated helpers
|
|
2175
|
+
*/
|
|
2176
|
+
buildWithWarp2D() {
|
|
2177
|
+
const {
|
|
2178
|
+
seed: e,
|
|
2179
|
+
fractalType: t,
|
|
2180
|
+
frequency: i,
|
|
2181
|
+
domainWarpFrequency: a,
|
|
2182
|
+
domainWarpFractalType: r,
|
|
2183
|
+
domainWarpFractalOctaves: s,
|
|
2184
|
+
domainWarpFractalLacunarity: l,
|
|
2185
|
+
domainWarpFractalGain: o
|
|
2186
|
+
} = this.config, x = this.calculateWarpFractalBounding(), z = this.config.domainWarpAmplitude * x, n = this.getWarpAmplitudeMultiplier(), y = this.getBaseNoiseWGSLCore2D(), c = this.getWarpWGSL2D(), p = [y.helpers, c.helpers];
|
|
2187
|
+
t === _.PingPong && p.push(["pingPong"]);
|
|
2188
|
+
const R = Me(...p);
|
|
2189
|
+
let v = y.fnName, u = y.core;
|
|
2190
|
+
y.needsSkew && (u += `
|
|
2191
|
+
|
|
2192
|
+
fn ${y.fnName}_skewed(seed: i32, x: f32, y: f32) -> f32 {
|
|
2193
|
+
let F2: f32 = 0.36602540378443864;
|
|
2194
|
+
let t = (x + y) * F2;
|
|
2195
|
+
return ${y.fnName}(seed, x + t, y + t);
|
|
2196
|
+
}`, v = `${y.fnName}_skewed`);
|
|
2197
|
+
const D = this.buildNoiseFractal2DCore(
|
|
2198
|
+
u,
|
|
2199
|
+
v,
|
|
2200
|
+
e,
|
|
2201
|
+
t
|
|
2202
|
+
), $ = `fn noise_entry(x_in: f32, y_in: f32) -> f32 {
|
|
2203
|
+
var x = x_in;
|
|
2204
|
+
var y = y_in;
|
|
2205
|
+
${this.buildWarpDispatch2D(
|
|
2206
|
+
e,
|
|
2207
|
+
a,
|
|
2208
|
+
r,
|
|
2209
|
+
s,
|
|
2210
|
+
l,
|
|
2211
|
+
o,
|
|
2212
|
+
z,
|
|
2213
|
+
n,
|
|
2214
|
+
c.fnName
|
|
2215
|
+
)}
|
|
2216
|
+
return ${D.fnName}(x * ${i}, y * ${i});
|
|
2217
|
+
}
|
|
2218
|
+
${R}
|
|
2219
|
+
${c.core}
|
|
2220
|
+
${D.wgsl}`;
|
|
2221
|
+
return L($);
|
|
2222
|
+
}
|
|
2223
|
+
buildWarpDispatch2D(e, t, i, a, r, s, l, o, x) {
|
|
2224
|
+
if (i === w.None) {
|
|
2225
|
+
const y = l * o;
|
|
2226
|
+
return ` // Domain warp
|
|
2227
|
+
{
|
|
2228
|
+
let warp_d = ${x}(${e | 0}, x, y);
|
|
2229
|
+
x += warp_d.x * ${y};
|
|
2230
|
+
y += warp_d.y * ${y};
|
|
2231
|
+
}`;
|
|
2232
|
+
}
|
|
2233
|
+
const z = i === w.Progressive;
|
|
2234
|
+
let n = ` // Fractal domain warp
|
|
2235
|
+
`;
|
|
2236
|
+
if (z) {
|
|
2237
|
+
let y = l;
|
|
2238
|
+
for (let c = 0; c < a; c++) {
|
|
2239
|
+
const p = e + c | 0, R = y * o;
|
|
2240
|
+
n += ` {
|
|
2241
|
+
let wd${c} = ${x}(${p}, x, y);
|
|
2242
|
+
x += wd${c}.x * ${R};
|
|
2243
|
+
y += wd${c}.y * ${R};
|
|
2244
|
+
}
|
|
2245
|
+
`, y *= s;
|
|
2246
|
+
}
|
|
2247
|
+
} else {
|
|
2248
|
+
n += ` var dx: f32 = 0.0;
|
|
2249
|
+
var dy: f32 = 0.0;
|
|
2250
|
+
`;
|
|
2251
|
+
let y = l;
|
|
2252
|
+
for (let c = 0; c < a; c++) {
|
|
2253
|
+
const p = e + c | 0, R = y * o;
|
|
2254
|
+
n += ` {
|
|
2255
|
+
let wd${c} = ${x}(${p}, x_in, y_in);
|
|
2256
|
+
dx += wd${c}.x * ${R};
|
|
2257
|
+
dy += wd${c}.y * ${R};
|
|
2258
|
+
}
|
|
2259
|
+
`, y *= s;
|
|
2260
|
+
}
|
|
2261
|
+
n += ` x += dx;
|
|
2262
|
+
y += dy;
|
|
2263
|
+
`;
|
|
2264
|
+
}
|
|
2265
|
+
return n;
|
|
2266
|
+
}
|
|
2267
|
+
buildNoiseFractal2DCore(e, t, i, a) {
|
|
2268
|
+
if (a === _.None) {
|
|
2269
|
+
const y = `${t}_entry_core`;
|
|
2270
|
+
return { wgsl: `${e}
|
|
2271
|
+
|
|
2272
|
+
fn ${y}(x: f32, y: f32) -> f32 {
|
|
2273
|
+
return ${t}(${i | 0}, x, y);
|
|
2274
|
+
}`, fnName: y };
|
|
2275
|
+
}
|
|
2276
|
+
const r = this.calculateFractalBounding(), {
|
|
2277
|
+
fractalOctaves: s,
|
|
2278
|
+
fractalLacunarity: l,
|
|
2279
|
+
fractalGain: o,
|
|
2280
|
+
fractalWeightedStrength: x,
|
|
2281
|
+
fractalPingPongStrength: z
|
|
2282
|
+
} = this.config;
|
|
2283
|
+
let n;
|
|
2284
|
+
switch (a) {
|
|
2285
|
+
case _.FBm:
|
|
2286
|
+
n = k(
|
|
2287
|
+
e,
|
|
2288
|
+
t,
|
|
2289
|
+
i,
|
|
2290
|
+
s,
|
|
2291
|
+
l,
|
|
2292
|
+
o,
|
|
2293
|
+
x,
|
|
2294
|
+
r
|
|
2295
|
+
);
|
|
2296
|
+
break;
|
|
2297
|
+
case _.Ridged:
|
|
2298
|
+
n = se(
|
|
2299
|
+
e,
|
|
2300
|
+
t,
|
|
2301
|
+
i,
|
|
2302
|
+
s,
|
|
2303
|
+
l,
|
|
2304
|
+
o,
|
|
2305
|
+
x,
|
|
2306
|
+
r
|
|
2307
|
+
);
|
|
2308
|
+
break;
|
|
2309
|
+
case _.PingPong:
|
|
2310
|
+
n = `${e}
|
|
2311
|
+
|
|
2312
|
+
fn noise(x: f32, y: f32) -> f32 {
|
|
2313
|
+
var sum: f32 = 0.0;
|
|
2314
|
+
var amp: f32 = ${r};
|
|
2315
|
+
var px = x;
|
|
2316
|
+
var py = y;
|
|
2317
|
+
var s: i32 = ${i | 0};
|
|
2318
|
+
|
|
2319
|
+
for (var i: i32 = 0; i < ${s}; i++) {
|
|
2320
|
+
let n = pingPong((${t}(s, px, py) + 1.0) * ${z});
|
|
2321
|
+
sum += (n - 0.5) * 2.0 * amp;
|
|
2322
|
+
amp *= mix(1.0, n, ${x});
|
|
2323
|
+
|
|
2324
|
+
px *= ${l};
|
|
2325
|
+
py *= ${l};
|
|
2326
|
+
amp *= ${o};
|
|
2327
|
+
s += 1;
|
|
2328
|
+
}
|
|
2329
|
+
|
|
2330
|
+
return sum;
|
|
2331
|
+
}`;
|
|
2332
|
+
break;
|
|
2333
|
+
default:
|
|
2334
|
+
n = k(
|
|
2335
|
+
e,
|
|
2336
|
+
t,
|
|
2337
|
+
i,
|
|
2338
|
+
s,
|
|
2339
|
+
l,
|
|
2340
|
+
o,
|
|
2341
|
+
x,
|
|
2342
|
+
r
|
|
2343
|
+
);
|
|
2344
|
+
}
|
|
2345
|
+
return { wgsl: n, fnName: "noise" };
|
|
2346
|
+
}
|
|
2347
|
+
getWarpWGSL2D() {
|
|
2348
|
+
switch (this.config.domainWarpType) {
|
|
2349
|
+
case h.BasicGrid:
|
|
2350
|
+
return {
|
|
2351
|
+
core: oe(),
|
|
2352
|
+
fnName: "basicgrid_warp2d",
|
|
2353
|
+
helpers: le
|
|
2354
|
+
};
|
|
2355
|
+
case h.OpenSimplex2:
|
|
2356
|
+
return {
|
|
2357
|
+
core: ne(
|
|
2358
|
+
this.config.domainWarpFrequency,
|
|
2359
|
+
!1
|
|
2360
|
+
),
|
|
2361
|
+
fnName: "os2_warp2d",
|
|
2362
|
+
helpers: _a
|
|
2363
|
+
};
|
|
2364
|
+
case h.OpenSimplex2Reduced:
|
|
2365
|
+
return {
|
|
2366
|
+
core: ne(
|
|
2367
|
+
this.config.domainWarpFrequency,
|
|
2368
|
+
!0
|
|
2369
|
+
),
|
|
2370
|
+
fnName: "os2_warp2d",
|
|
2371
|
+
helpers: Ra
|
|
2372
|
+
};
|
|
2373
|
+
default:
|
|
2374
|
+
return {
|
|
2375
|
+
core: oe(),
|
|
2376
|
+
fnName: "basicgrid_warp2d",
|
|
2377
|
+
helpers: le
|
|
2378
|
+
};
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
2381
|
+
getBaseNoiseWGSLCore2D() {
|
|
2382
|
+
switch (this.config.noiseType) {
|
|
2383
|
+
case f.Value:
|
|
2384
|
+
return {
|
|
2385
|
+
core: Ae(),
|
|
2386
|
+
fnName: "value2d",
|
|
2387
|
+
helpers: Le,
|
|
2388
|
+
needsSkew: !1
|
|
2389
|
+
};
|
|
2390
|
+
case f.Perlin:
|
|
2391
|
+
return {
|
|
2392
|
+
core: Ve(),
|
|
2393
|
+
fnName: "perlin2d",
|
|
2394
|
+
helpers: Xe,
|
|
2395
|
+
needsSkew: !1
|
|
2396
|
+
};
|
|
2397
|
+
case f.ValueCubic:
|
|
2398
|
+
return {
|
|
2399
|
+
core: qe(),
|
|
2400
|
+
fnName: "valuecubic2d",
|
|
2401
|
+
helpers: Ze,
|
|
2402
|
+
needsSkew: !1
|
|
2403
|
+
};
|
|
2404
|
+
case f.OpenSimplex2:
|
|
2405
|
+
return {
|
|
2406
|
+
core: B(),
|
|
2407
|
+
fnName: "opensimplex2_2d",
|
|
2408
|
+
helpers: ee,
|
|
2409
|
+
needsSkew: !0
|
|
2410
|
+
};
|
|
2411
|
+
case f.OpenSimplex2S:
|
|
2412
|
+
return {
|
|
2413
|
+
core: ia(),
|
|
2414
|
+
fnName: "opensimplex2s_2d",
|
|
2415
|
+
helpers: ea,
|
|
2416
|
+
needsSkew: !0
|
|
2417
|
+
};
|
|
2418
|
+
case f.Cellular:
|
|
2419
|
+
return {
|
|
2420
|
+
core: oa(
|
|
2421
|
+
this.config.cellularDistanceFunction,
|
|
2422
|
+
this.config.cellularReturnType,
|
|
2423
|
+
this.config.cellularJitter
|
|
2424
|
+
),
|
|
2425
|
+
fnName: "cellular2d",
|
|
2426
|
+
helpers: la,
|
|
2427
|
+
needsSkew: !1
|
|
2428
|
+
};
|
|
2429
|
+
default:
|
|
2430
|
+
return {
|
|
2431
|
+
core: B(),
|
|
2432
|
+
fnName: "opensimplex2_2d",
|
|
2433
|
+
helpers: ee,
|
|
2434
|
+
needsSkew: !0
|
|
2435
|
+
};
|
|
2436
|
+
}
|
|
2437
|
+
}
|
|
2438
|
+
getBaseNoiseWGSL2D() {
|
|
2439
|
+
switch (this.config.noiseType) {
|
|
2440
|
+
case f.Value:
|
|
2441
|
+
return {
|
|
2442
|
+
wgsl: ke(),
|
|
2443
|
+
fnName: "value2d",
|
|
2444
|
+
needsSkew: !1
|
|
2445
|
+
};
|
|
2446
|
+
case f.Perlin:
|
|
2447
|
+
return {
|
|
2448
|
+
wgsl: We(),
|
|
2449
|
+
fnName: "perlin2d",
|
|
2450
|
+
needsSkew: !1
|
|
2451
|
+
};
|
|
2452
|
+
case f.ValueCubic:
|
|
2453
|
+
return {
|
|
2454
|
+
wgsl: He(),
|
|
2455
|
+
fnName: "valuecubic2d",
|
|
2456
|
+
needsSkew: !1
|
|
2457
|
+
};
|
|
2458
|
+
case f.OpenSimplex2:
|
|
2459
|
+
return {
|
|
2460
|
+
wgsl: ie(),
|
|
2461
|
+
fnName: "opensimplex2_2d",
|
|
2462
|
+
needsSkew: !0
|
|
2463
|
+
};
|
|
2464
|
+
case f.OpenSimplex2S:
|
|
2465
|
+
return {
|
|
2466
|
+
wgsl: Ue(),
|
|
2467
|
+
fnName: "opensimplex2s_2d",
|
|
2468
|
+
needsSkew: !0
|
|
2469
|
+
};
|
|
2470
|
+
case f.Cellular:
|
|
2471
|
+
return {
|
|
2472
|
+
wgsl: sa(
|
|
2473
|
+
this.config.cellularDistanceFunction,
|
|
2474
|
+
this.config.cellularReturnType,
|
|
2475
|
+
this.config.cellularJitter
|
|
2476
|
+
),
|
|
2477
|
+
fnName: "cellular2d",
|
|
2478
|
+
needsSkew: !1
|
|
2479
|
+
};
|
|
2480
|
+
default:
|
|
2481
|
+
return {
|
|
2482
|
+
wgsl: ie(),
|
|
2483
|
+
fnName: "opensimplex2_2d",
|
|
2484
|
+
needsSkew: !0
|
|
2485
|
+
};
|
|
2486
|
+
}
|
|
2487
|
+
}
|
|
2488
|
+
}
|
|
2489
|
+
function Z(d) {
|
|
2490
|
+
switch (d) {
|
|
2491
|
+
case m.ImproveXYPlanes:
|
|
2492
|
+
return `{
|
|
2493
|
+
let xy = x + y;
|
|
2494
|
+
let s2 = xy * -0.211324865405187;
|
|
2495
|
+
let zt = z * 0.577350269189626;
|
|
2496
|
+
x = x + s2 - zt;
|
|
2497
|
+
y = y + s2 - zt;
|
|
2498
|
+
z = zt + xy * 0.577350269189626;
|
|
2499
|
+
}`;
|
|
2500
|
+
case m.ImproveXZPlanes:
|
|
2501
|
+
return `{
|
|
2502
|
+
let xz = x + z;
|
|
2503
|
+
let s2 = xz * -0.211324865405187;
|
|
2504
|
+
let yt = y * 0.577350269189626;
|
|
2505
|
+
x = x + s2 - yt;
|
|
2506
|
+
z = z + s2 - yt;
|
|
2507
|
+
y = yt + xz * 0.577350269189626;
|
|
2508
|
+
}`;
|
|
2509
|
+
case m.DefaultOpenSimplex2:
|
|
2510
|
+
return `{
|
|
2511
|
+
let r = (x + y + z) * (2.0 / 3.0);
|
|
2512
|
+
x = r - x;
|
|
2513
|
+
y = r - y;
|
|
2514
|
+
z = r - z;
|
|
2515
|
+
}`;
|
|
2516
|
+
default:
|
|
2517
|
+
return "";
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2520
|
+
class Ma extends fe {
|
|
2521
|
+
buildTSL3D() {
|
|
2522
|
+
const {
|
|
2523
|
+
seed: e,
|
|
2524
|
+
noiseType: t,
|
|
2525
|
+
fractalType: i,
|
|
2526
|
+
frequency: a,
|
|
2527
|
+
rotationType3D: r,
|
|
2528
|
+
domainWarpType: s
|
|
2529
|
+
} = this.config;
|
|
2530
|
+
let l, o;
|
|
2531
|
+
switch (r) {
|
|
2532
|
+
case m.ImproveXYPlanes:
|
|
2533
|
+
l = m.ImproveXYPlanes, o = m.ImproveXYPlanes;
|
|
2534
|
+
break;
|
|
2535
|
+
case m.ImproveXZPlanes:
|
|
2536
|
+
l = m.ImproveXZPlanes, o = m.ImproveXZPlanes;
|
|
2537
|
+
break;
|
|
2538
|
+
default:
|
|
2539
|
+
switch (t) {
|
|
2540
|
+
case f.OpenSimplex2:
|
|
2541
|
+
case f.OpenSimplex2S:
|
|
2542
|
+
l = m.DefaultOpenSimplex2;
|
|
2543
|
+
break;
|
|
2544
|
+
default:
|
|
2545
|
+
l = m.None;
|
|
2546
|
+
}
|
|
2547
|
+
switch (s) {
|
|
2548
|
+
case h.OpenSimplex2:
|
|
2549
|
+
case h.OpenSimplex2Reduced:
|
|
2550
|
+
o = m.DefaultOpenSimplex2;
|
|
2551
|
+
break;
|
|
2552
|
+
default:
|
|
2553
|
+
o = m.None;
|
|
2554
|
+
}
|
|
2555
|
+
}
|
|
2556
|
+
return s === h.None ? this.buildNoWarp3D(
|
|
2557
|
+
e,
|
|
2558
|
+
t,
|
|
2559
|
+
i,
|
|
2560
|
+
a,
|
|
2561
|
+
l
|
|
2562
|
+
) : this.buildWithWarp3D(
|
|
2563
|
+
e,
|
|
2564
|
+
t,
|
|
2565
|
+
i,
|
|
2566
|
+
a,
|
|
2567
|
+
l,
|
|
2568
|
+
o
|
|
2569
|
+
);
|
|
2570
|
+
}
|
|
2571
|
+
/**
|
|
2572
|
+
* Original path: no domain warp, unchanged from before
|
|
2573
|
+
*/
|
|
2574
|
+
buildNoWarp3D(e, t, i, a, r) {
|
|
2575
|
+
const s = this.getBaseNoiseWGSL3D(), l = Z(r);
|
|
2576
|
+
let o, x;
|
|
2577
|
+
if (i === _.None)
|
|
2578
|
+
o = s.wgsl, x = s.fnName, o += `
|
|
2579
|
+
|
|
2580
|
+
fn noise_core(x: f32, y: f32, z: f32) -> f32 {
|
|
2581
|
+
return ${x}(${e | 0}, x, y, z);
|
|
2582
|
+
}`, x = "noise_core";
|
|
2583
|
+
else {
|
|
2584
|
+
const n = this.calculateFractalBounding();
|
|
2585
|
+
switch (i) {
|
|
2586
|
+
case _.FBm:
|
|
2587
|
+
o = b(
|
|
2588
|
+
s.wgsl,
|
|
2589
|
+
s.fnName,
|
|
2590
|
+
e,
|
|
2591
|
+
this.config.fractalOctaves,
|
|
2592
|
+
this.config.fractalLacunarity,
|
|
2593
|
+
this.config.fractalGain,
|
|
2594
|
+
this.config.fractalWeightedStrength,
|
|
2595
|
+
n
|
|
2596
|
+
);
|
|
2597
|
+
break;
|
|
2598
|
+
case _.Ridged:
|
|
2599
|
+
o = te(
|
|
2600
|
+
s.wgsl,
|
|
2601
|
+
s.fnName,
|
|
2602
|
+
e,
|
|
2603
|
+
this.config.fractalOctaves,
|
|
2604
|
+
this.config.fractalLacunarity,
|
|
2605
|
+
this.config.fractalGain,
|
|
2606
|
+
this.config.fractalWeightedStrength,
|
|
2607
|
+
n
|
|
2608
|
+
);
|
|
2609
|
+
break;
|
|
2610
|
+
case _.PingPong:
|
|
2611
|
+
o = ya(
|
|
2612
|
+
s.wgsl,
|
|
2613
|
+
s.fnName,
|
|
2614
|
+
e,
|
|
2615
|
+
this.config.fractalOctaves,
|
|
2616
|
+
this.config.fractalLacunarity,
|
|
2617
|
+
this.config.fractalGain,
|
|
2618
|
+
this.config.fractalWeightedStrength,
|
|
2619
|
+
n,
|
|
2620
|
+
this.config.fractalPingPongStrength
|
|
2621
|
+
);
|
|
2622
|
+
break;
|
|
2623
|
+
default:
|
|
2624
|
+
o = b(
|
|
2625
|
+
s.wgsl,
|
|
2626
|
+
s.fnName,
|
|
2627
|
+
e,
|
|
2628
|
+
this.config.fractalOctaves,
|
|
2629
|
+
this.config.fractalLacunarity,
|
|
2630
|
+
this.config.fractalGain,
|
|
2631
|
+
this.config.fractalWeightedStrength,
|
|
2632
|
+
n
|
|
2633
|
+
);
|
|
2634
|
+
}
|
|
2635
|
+
x = "noise";
|
|
2636
|
+
}
|
|
2637
|
+
const z = `fn noise_entry(x_in: f32, y_in: f32, z_in: f32) -> f32 {
|
|
2638
|
+
var x = x_in * ${a};
|
|
2639
|
+
var y = y_in * ${a};
|
|
2640
|
+
var z = z_in * ${a};
|
|
2641
|
+
${l}
|
|
2642
|
+
return ${x}(x, y, z);
|
|
2643
|
+
}
|
|
2644
|
+
${o}`;
|
|
2645
|
+
return L(z);
|
|
2646
|
+
}
|
|
2647
|
+
/**
|
|
2648
|
+
* Warp-enabled path: single wgslFn with deduplicated helpers
|
|
2649
|
+
*/
|
|
2650
|
+
buildWithWarp3D(e, t, i, a, r, s) {
|
|
2651
|
+
const {
|
|
2652
|
+
domainWarpType: l,
|
|
2653
|
+
domainWarpFrequency: o,
|
|
2654
|
+
domainWarpFractalType: x,
|
|
2655
|
+
domainWarpFractalOctaves: z,
|
|
2656
|
+
domainWarpFractalLacunarity: n,
|
|
2657
|
+
domainWarpFractalGain: y
|
|
2658
|
+
} = this.config, c = this.calculateWarpFractalBounding(), p = this.config.domainWarpAmplitude * c, R = this.getWarpAmplitudeMultiplier3D(), v = this.getBaseNoiseWGSLCore3D(), u = this.getWarpWGSL3D(), D = [v.helpers, u.helpers];
|
|
2659
|
+
i === _.PingPong && D.push(["pingPong"]);
|
|
2660
|
+
const g = Me(...D), $ = this.buildNoiseFractal3DCore(
|
|
2661
|
+
v.core,
|
|
2662
|
+
v.fnName,
|
|
2663
|
+
e,
|
|
2664
|
+
i
|
|
2665
|
+
), Ce = Z(s), ge = Z(r), De = `fn noise_entry(x_in: f32, y_in: f32, z_in: f32) -> f32 {
|
|
2666
|
+
var x = x_in;
|
|
2667
|
+
var y = y_in;
|
|
2668
|
+
var z = z_in;
|
|
2669
|
+
${this.buildWarpDispatch3D(
|
|
2670
|
+
e,
|
|
2671
|
+
l,
|
|
2672
|
+
o,
|
|
2673
|
+
x,
|
|
2674
|
+
z,
|
|
2675
|
+
n,
|
|
2676
|
+
y,
|
|
2677
|
+
p,
|
|
2678
|
+
R,
|
|
2679
|
+
Ce,
|
|
2680
|
+
u.fnName
|
|
2681
|
+
)}
|
|
2682
|
+
x *= ${a};
|
|
2683
|
+
y *= ${a};
|
|
2684
|
+
z *= ${a};
|
|
2685
|
+
${ge}
|
|
2686
|
+
return ${$.fnName}(x, y, z);
|
|
2687
|
+
}
|
|
2688
|
+
${g}
|
|
2689
|
+
${u.core}
|
|
2690
|
+
${$.wgsl}`;
|
|
2691
|
+
return L(De);
|
|
2692
|
+
}
|
|
2693
|
+
/**
|
|
2694
|
+
* Build warp dispatch code for the entry function.
|
|
2695
|
+
* Warp functions return unit displacement; amplitude is applied here.
|
|
2696
|
+
*/
|
|
2697
|
+
buildWarpDispatch3D(e, t, i, a, r, s, l, o, x, z, n) {
|
|
2698
|
+
const y = z ? z.replace(/\bx\b/g, "wx").replace(/\by\b/g, "wy").replace(/\bz\b/g, "wz") : "";
|
|
2699
|
+
if (a === w.None) {
|
|
2700
|
+
const R = o * x;
|
|
2701
|
+
return ` // Domain warp
|
|
2702
|
+
{
|
|
2703
|
+
var wx = x;
|
|
2704
|
+
var wy = y;
|
|
2705
|
+
var wz = z;
|
|
2706
|
+
${y}
|
|
2707
|
+
wx *= ${i};
|
|
2708
|
+
wy *= ${i};
|
|
2709
|
+
wz *= ${i};
|
|
2710
|
+
let warp_d = ${n}(${e | 0}, wx, wy, wz);
|
|
2711
|
+
x += warp_d.x * ${R};
|
|
2712
|
+
y += warp_d.y * ${R};
|
|
2713
|
+
z += warp_d.z * ${R};
|
|
2714
|
+
}`;
|
|
2715
|
+
}
|
|
2716
|
+
const c = a === w.Progressive;
|
|
2717
|
+
let p = ` // Fractal domain warp
|
|
2718
|
+
`;
|
|
2719
|
+
if (c) {
|
|
2720
|
+
let R = o, v = i;
|
|
2721
|
+
for (let u = 0; u < r; u++) {
|
|
2722
|
+
const D = e + u | 0, g = R * x;
|
|
2723
|
+
p += ` {
|
|
2724
|
+
var wx = x;
|
|
2725
|
+
var wy = y;
|
|
2726
|
+
var wz = z;
|
|
2727
|
+
${y}
|
|
2728
|
+
wx *= ${v};
|
|
2729
|
+
wy *= ${v};
|
|
2730
|
+
wz *= ${v};
|
|
2731
|
+
let wd${u} = ${n}(${D}, wx, wy, wz);
|
|
2732
|
+
x += wd${u}.x * ${g};
|
|
2733
|
+
y += wd${u}.y * ${g};
|
|
2734
|
+
z += wd${u}.z * ${g};
|
|
2735
|
+
}
|
|
2736
|
+
`, R *= l, v *= s;
|
|
2737
|
+
}
|
|
2738
|
+
} else {
|
|
2739
|
+
p += ` var dx: f32 = 0.0;
|
|
2740
|
+
var dy: f32 = 0.0;
|
|
2741
|
+
var dz: f32 = 0.0;
|
|
2742
|
+
`;
|
|
2743
|
+
let R = o, v = i;
|
|
2744
|
+
for (let u = 0; u < r; u++) {
|
|
2745
|
+
const D = e + u | 0, g = R * x;
|
|
2746
|
+
p += ` {
|
|
2747
|
+
var wx = x_in;
|
|
2748
|
+
var wy = y_in;
|
|
2749
|
+
var wz = z_in;
|
|
2750
|
+
${y}
|
|
2751
|
+
wx *= ${v};
|
|
2752
|
+
wy *= ${v};
|
|
2753
|
+
wz *= ${v};
|
|
2754
|
+
let wd${u} = ${n}(${D}, wx, wy, wz);
|
|
2755
|
+
dx += wd${u}.x * ${g};
|
|
2756
|
+
dy += wd${u}.y * ${g};
|
|
2757
|
+
dz += wd${u}.z * ${g};
|
|
2758
|
+
}
|
|
2759
|
+
`, R *= l, v *= s;
|
|
2760
|
+
}
|
|
2761
|
+
p += ` x += dx;
|
|
2762
|
+
y += dy;
|
|
2763
|
+
z += dz;
|
|
2764
|
+
`;
|
|
2765
|
+
}
|
|
2766
|
+
return p;
|
|
2767
|
+
}
|
|
2768
|
+
/**
|
|
2769
|
+
* Build noise + fractal WGSL from core-only noise (no helpers)
|
|
2770
|
+
*/
|
|
2771
|
+
buildNoiseFractal3DCore(e, t, i, a) {
|
|
2772
|
+
if (a === _.None)
|
|
2773
|
+
return { wgsl: `${e}
|
|
2774
|
+
|
|
2775
|
+
fn noise_core(x: f32, y: f32, z: f32) -> f32 {
|
|
2776
|
+
return ${t}(${i | 0}, x, y, z);
|
|
2777
|
+
}`, fnName: "noise_core" };
|
|
2778
|
+
const r = this.calculateFractalBounding(), {
|
|
2779
|
+
fractalOctaves: s,
|
|
2780
|
+
fractalLacunarity: l,
|
|
2781
|
+
fractalGain: o,
|
|
2782
|
+
fractalWeightedStrength: x,
|
|
2783
|
+
fractalPingPongStrength: z
|
|
2784
|
+
} = this.config;
|
|
2785
|
+
let n;
|
|
2786
|
+
switch (a) {
|
|
2787
|
+
case _.FBm:
|
|
2788
|
+
n = b(
|
|
2789
|
+
e,
|
|
2790
|
+
t,
|
|
2791
|
+
i,
|
|
2792
|
+
s,
|
|
2793
|
+
l,
|
|
2794
|
+
o,
|
|
2795
|
+
x,
|
|
2796
|
+
r
|
|
2797
|
+
);
|
|
2798
|
+
break;
|
|
2799
|
+
case _.Ridged:
|
|
2800
|
+
n = te(
|
|
2801
|
+
e,
|
|
2802
|
+
t,
|
|
2803
|
+
i,
|
|
2804
|
+
s,
|
|
2805
|
+
l,
|
|
2806
|
+
o,
|
|
2807
|
+
x,
|
|
2808
|
+
r
|
|
2809
|
+
);
|
|
2810
|
+
break;
|
|
2811
|
+
case _.PingPong:
|
|
2812
|
+
n = `${e}
|
|
2813
|
+
|
|
2814
|
+
fn noise(x: f32, y: f32, z: f32) -> f32 {
|
|
2815
|
+
var sum: f32 = 0.0;
|
|
2816
|
+
var amp: f32 = ${r};
|
|
2817
|
+
var px = x;
|
|
2818
|
+
var py = y;
|
|
2819
|
+
var pz = z;
|
|
2820
|
+
var s: i32 = ${i | 0};
|
|
2821
|
+
|
|
2822
|
+
for (var i: i32 = 0; i < ${s}; i++) {
|
|
2823
|
+
let n = pingPong((${t}(s, px, py, pz) + 1.0) * ${z});
|
|
2824
|
+
sum += (n - 0.5) * 2.0 * amp;
|
|
2825
|
+
amp *= mix(1.0, n, ${x});
|
|
2826
|
+
|
|
2827
|
+
px *= ${l};
|
|
2828
|
+
py *= ${l};
|
|
2829
|
+
pz *= ${l};
|
|
2830
|
+
amp *= ${o};
|
|
2831
|
+
s += 1;
|
|
2832
|
+
}
|
|
2833
|
+
|
|
2834
|
+
return sum;
|
|
2835
|
+
}`;
|
|
2836
|
+
break;
|
|
2837
|
+
default:
|
|
2838
|
+
n = b(
|
|
2839
|
+
e,
|
|
2840
|
+
t,
|
|
2841
|
+
i,
|
|
2842
|
+
s,
|
|
2843
|
+
l,
|
|
2844
|
+
o,
|
|
2845
|
+
x,
|
|
2846
|
+
r
|
|
2847
|
+
);
|
|
2848
|
+
}
|
|
2849
|
+
return { wgsl: n, fnName: "noise" };
|
|
2850
|
+
}
|
|
2851
|
+
/**
|
|
2852
|
+
* Get warp WGSL core function and its helper requirements
|
|
2853
|
+
*/
|
|
2854
|
+
getWarpWGSL3D() {
|
|
2855
|
+
switch (this.config.domainWarpType) {
|
|
2856
|
+
case h.BasicGrid:
|
|
2857
|
+
return {
|
|
2858
|
+
core: xe(),
|
|
2859
|
+
fnName: "basicgrid_warp3d",
|
|
2860
|
+
helpers: de
|
|
2861
|
+
};
|
|
2862
|
+
case h.OpenSimplex2:
|
|
2863
|
+
return {
|
|
2864
|
+
core: ye(!1),
|
|
2865
|
+
fnName: "os2_warp3d",
|
|
2866
|
+
helpers: za
|
|
2867
|
+
};
|
|
2868
|
+
case h.OpenSimplex2Reduced:
|
|
2869
|
+
return {
|
|
2870
|
+
core: ye(!0),
|
|
2871
|
+
fnName: "os2_warp3d",
|
|
2872
|
+
helpers: va
|
|
2873
|
+
};
|
|
2874
|
+
default:
|
|
2875
|
+
return {
|
|
2876
|
+
core: xe(),
|
|
2877
|
+
fnName: "basicgrid_warp3d",
|
|
2878
|
+
helpers: de
|
|
2879
|
+
};
|
|
2880
|
+
}
|
|
2881
|
+
}
|
|
2882
|
+
/**
|
|
2883
|
+
* Get noise WGSL core function (no helpers) and its helper requirements
|
|
2884
|
+
*/
|
|
2885
|
+
getBaseNoiseWGSLCore3D() {
|
|
2886
|
+
switch (this.config.noiseType) {
|
|
2887
|
+
case f.Value:
|
|
2888
|
+
return {
|
|
2889
|
+
core: Ge(),
|
|
2890
|
+
fnName: "value3d",
|
|
2891
|
+
helpers: we
|
|
2892
|
+
};
|
|
2893
|
+
case f.Perlin:
|
|
2894
|
+
return {
|
|
2895
|
+
core: Fe(),
|
|
2896
|
+
fnName: "perlin3d",
|
|
2897
|
+
helpers: Ye
|
|
2898
|
+
};
|
|
2899
|
+
case f.ValueCubic:
|
|
2900
|
+
return {
|
|
2901
|
+
core: Je(),
|
|
2902
|
+
fnName: "valuecubic3d",
|
|
2903
|
+
helpers: Be
|
|
2904
|
+
};
|
|
2905
|
+
case f.OpenSimplex2:
|
|
2906
|
+
return {
|
|
2907
|
+
core: H(),
|
|
2908
|
+
fnName: "opensimplex2_3d",
|
|
2909
|
+
helpers: ae
|
|
2910
|
+
};
|
|
2911
|
+
case f.OpenSimplex2S:
|
|
2912
|
+
return {
|
|
2913
|
+
core: ra(),
|
|
2914
|
+
fnName: "opensimplex2s_3d",
|
|
2915
|
+
helpers: aa
|
|
2916
|
+
};
|
|
2917
|
+
case f.Cellular:
|
|
2918
|
+
return {
|
|
2919
|
+
core: xa(
|
|
2920
|
+
this.config.cellularDistanceFunction,
|
|
2921
|
+
this.config.cellularReturnType,
|
|
2922
|
+
this.config.cellularJitter
|
|
2923
|
+
),
|
|
2924
|
+
fnName: "cellular3d",
|
|
2925
|
+
helpers: da
|
|
2926
|
+
};
|
|
2927
|
+
default:
|
|
2928
|
+
return {
|
|
2929
|
+
core: H(),
|
|
2930
|
+
fnName: "opensimplex2_3d",
|
|
2931
|
+
helpers: ae
|
|
2932
|
+
};
|
|
2933
|
+
}
|
|
2934
|
+
}
|
|
2935
|
+
/**
|
|
2936
|
+
* Get amplitude multiplier for 3D domain warp (type-specific)
|
|
2937
|
+
*/
|
|
2938
|
+
getWarpAmplitudeMultiplier3D() {
|
|
2939
|
+
switch (this.config.domainWarpType) {
|
|
2940
|
+
case h.OpenSimplex2:
|
|
2941
|
+
return 32.69428253173828;
|
|
2942
|
+
case h.OpenSimplex2Reduced:
|
|
2943
|
+
return 7.71604938271605;
|
|
2944
|
+
case h.BasicGrid:
|
|
2945
|
+
default:
|
|
2946
|
+
return 1;
|
|
2947
|
+
}
|
|
2948
|
+
}
|
|
2949
|
+
getBaseNoiseWGSL3D() {
|
|
2950
|
+
switch (this.config.noiseType) {
|
|
2951
|
+
case f.Value:
|
|
2952
|
+
return { wgsl: be(), fnName: "value3d" };
|
|
2953
|
+
case f.Perlin:
|
|
2954
|
+
return { wgsl: je(), fnName: "perlin3d" };
|
|
2955
|
+
case f.ValueCubic:
|
|
2956
|
+
return {
|
|
2957
|
+
wgsl: Oe(),
|
|
2958
|
+
fnName: "valuecubic3d"
|
|
2959
|
+
};
|
|
2960
|
+
case f.OpenSimplex2:
|
|
2961
|
+
return {
|
|
2962
|
+
wgsl: re(),
|
|
2963
|
+
fnName: "opensimplex2_3d"
|
|
2964
|
+
};
|
|
2965
|
+
case f.OpenSimplex2S:
|
|
2966
|
+
return {
|
|
2967
|
+
wgsl: Ke(),
|
|
2968
|
+
fnName: "opensimplex2s_3d"
|
|
2969
|
+
};
|
|
2970
|
+
case f.Cellular:
|
|
2971
|
+
return {
|
|
2972
|
+
wgsl: ta(
|
|
2973
|
+
this.config.cellularDistanceFunction,
|
|
2974
|
+
this.config.cellularReturnType,
|
|
2975
|
+
this.config.cellularJitter
|
|
2976
|
+
),
|
|
2977
|
+
fnName: "cellular3d"
|
|
2978
|
+
};
|
|
2979
|
+
default:
|
|
2980
|
+
return {
|
|
2981
|
+
wgsl: re(),
|
|
2982
|
+
fnName: "opensimplex2_3d"
|
|
2983
|
+
};
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
}
|
|
2987
|
+
export {
|
|
2988
|
+
M as CellularDistanceFunction,
|
|
2989
|
+
C as CellularReturnType,
|
|
2990
|
+
w as DomainWarpFractalType,
|
|
2991
|
+
h as DomainWarpType,
|
|
2992
|
+
_ as FractalType,
|
|
2993
|
+
f as NoiseType,
|
|
2994
|
+
ga as RotationType3D,
|
|
2995
|
+
Ea as TSLNoiseBuilder2D,
|
|
2996
|
+
Ma as TSLNoiseBuilder3D,
|
|
2997
|
+
m as TransformType3D
|
|
2998
|
+
};
|