noisy_bevy 0.14.0

Procedural noise primitives for Bevy
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
use bevy::math::{
    Vec2, Vec2Swizzles, Vec3, Vec3Swizzles, Vec4, Vec4Swizzles, bvec3, vec2, vec3, vec4,
};

fn permute_3(x: Vec3) -> Vec3 {
    (((x * 34.) + 1.) * x) % Vec3::splat(289.)
}

// MIT License. © Ian McEwan, Stefan Gustavson, Munrocket, Johan Helsing
/// Simplex noise in two dimensions
pub fn simplex_noise_2d(v: Vec2) -> f32 {
    const C: Vec4 = vec4(
        0.211_324_87,  // (3.0 - sqrt(3.0)) / 6.0
        0.366_025_42,  // 0.5 * (sqrt(3.0) - 1.0)
        -0.577_350_26, // -1.0 + 2.0 * C.x
        1. / 41.,
    );
    let mut i: Vec2 = (v + Vec2::dot(v, C.yy())).floor();
    let x0 = v - i + Vec2::dot(i, C.xx());
    let i1: Vec2 = if x0.x > x0.y {
        vec2(1., 0.)
    } else {
        vec2(0., 1.)
    };
    let x12: Vec4 = x0.xyxy() + C.xxzz() - vec4(i1.x, i1.y, 0., 0.);
    i %= Vec2::splat(289.);
    let p = permute_3(permute_3(i.y + vec3(0., i1.y, 1.)) + i.x + vec3(0., i1.x, 1.));
    let mut m = Vec3::max(
        0.5 - vec3(
            Vec2::dot(x0, x0),
            Vec2::dot(x12.xy(), x12.xy()),
            Vec2::dot(x12.zw(), x12.zw()),
        ),
        Vec3::splat(0.),
    );
    m *= m;
    m *= m;
    let x = 2. * (p * C.www()).fract() - 1.;
    let h = x.abs() - 0.5;
    let ox = (x + 0.5).floor();
    let a0 = x - ox;
    m *= 1.792_842_9 - 0.853_734_73 * (a0 * a0 + h * h);
    let g = vec3(
        a0.x * x0.x + h.x * x0.y,
        a0.y * x12.x + h.y * x12.y,
        a0.z * x12.z + h.z * x12.w,
    );
    130. * Vec3::dot(m, g)
}

// MIT License. © Ian McEwan, Stefan Gustavson, Munrocket, Johan Helsing
/// Simplex noise in two dimensions
pub fn simplex_noise_2d_seeded(v: Vec2, seed: f32) -> f32 {
    const C: Vec4 = vec4(
        0.211_324_87,  // (3.0 - sqrt(3.0)) / 6.0
        0.366_025_42,  // 0.5 * (sqrt(3.0) - 1.0)
        -0.577_350_26, // -1.0 + 2.0 * C.x
        1. / 41.,
    );

    // first corner
    let mut i: Vec2 = (v + Vec2::dot(v, C.yy())).floor();
    let x0 = v - i + Vec2::dot(i, C.xx());

    // other corners
    let i1: Vec2 = if x0.x > x0.y {
        vec2(1., 0.)
    } else {
        vec2(0., 1.)
    };
    let x12: Vec4 = x0.xyxy() + C.xxzz() - vec4(i1.x, i1.y, 0., 0.);

    // permutations
    i %= Vec2::splat(289.);

    let mut p = permute_3(permute_3(i.y + vec3(0., i1.y, 1.)) + i.x + vec3(0., i1.x, 1.));
    p = permute_3(p + Vec3::splat(seed));

    let mut m = Vec3::max(
        0.5 - vec3(
            Vec2::dot(x0, x0),
            Vec2::dot(x12.xy(), x12.xy()),
            Vec2::dot(x12.zw(), x12.zw()),
        ),
        Vec3::splat(0.),
    );
    m *= m;
    m *= m;

    // gradients: 41 points uniformly over a line, mapped onto a diamond
    // the ring size, 17*17 = 289, is close to a multiple of 41 (41*7 = 287)
    let x = 2. * (p * C.www()).fract() - 1.;
    let h = x.abs() - 0.5;
    let ox = (x + 0.5).floor();
    let a0 = x - ox;

    // normalize gradients implicitly by scaling m
    // approximation of: m *= inversesqrt(a0 * a0 + h * h);
    m *= 1.792_842_9 - 0.853_734_73 * (a0 * a0 + h * h);
    let g = vec3(
        a0.x * x0.x + h.x * x0.y,
        a0.y * x12.x + h.y * x12.y,
        a0.z * x12.z + h.z * x12.w,
    );

    // compute final noise value at P
    130. * Vec3::dot(m, g)
}

fn permute_4(x: Vec4) -> Vec4 {
    ((x * 34. + 1.) * x) % Vec4::splat(289.)
}

fn taylor_inv_sqrt_4(r: Vec4) -> Vec4 {
    1.792_842_9 - 0.853_734_73 * r
}

#[inline]
fn step_4(edge: Vec4, x: Vec4) -> Vec4 {
    let b = Vec4::cmple(edge, x);
    Vec4::select(b, Vec4::ONE, Vec4::ZERO)
}

#[inline]
fn step_3(edge: Vec3, x: Vec3) -> Vec3 {
    let b = bvec3(edge.x < x.x, edge.y <= x.y, edge.z <= x.z);
    Vec3::select(b, Vec3::ONE, Vec3::ZERO)
}

// MIT License. © Ian McEwan, Stefan Gustavson, Munrocket, Johan Helsing
/// Simplex noise in three dimensions
pub fn simplex_noise_3d(v: Vec3) -> f32 {
    const C: Vec2 = vec2(1. / 6., 1. / 3.);
    const D: Vec4 = vec4(0., 0.5, 1., 2.);

    // first corner
    let mut i = (v + Vec3::dot(v, C.yyy())).floor();
    let x0 = v - i + Vec3::dot(i, C.xxx());

    // other corners
    let g = step_3(x0.yzx(), x0.xyz());
    let l = 1. - g;
    let i1 = Vec3::min(g.xyz(), l.zxy());
    let i2 = Vec3::max(g.xyz(), l.zxy());

    // x0 = x0 - 0. + 0. * C
    let x1 = x0 - i1 + 1. * C.xxx();
    let x2 = x0 - i2 + 2. * C.xxx();
    let x3 = x0 - 1. + 3. * C.xxx();

    // permutations
    i %= Vec3::splat(289.);
    let p = permute_4(
        permute_4(permute_4(i.z + vec4(0., i1.z, i2.z, 1.)) + i.y + vec4(0., i1.y, i2.y, 1.))
            + i.x
            + vec4(0., i1.x, i2.x, 1.),
    );

    // gradients (NxN points uniformly over a square, mapped onto an octahedron)
    let n_ = 1. / 7.; // N=7
    let ns = n_ * D.wyz() - D.xzx();

    let j = p - 49. * (p * ns.z * ns.z).floor(); // mod(p, N*N)

    let x_ = (j * ns.z).floor();
    let y_ = (j - 7. * x_).floor(); // mod(j, N)

    let x = x_ * ns.x + ns.yyyy();
    let y = y_ * ns.x + ns.yyyy();
    let h = 1. - x.abs() - y.abs();

    let b0 = vec4(x.x, x.y, y.x, y.y);
    let b1 = vec4(x.z, x.w, y.z, y.w);

    let s0 = b0.floor() * 2. + 1.;
    let s1 = b1.floor() * 2. + 1.;
    let sh = -step_4(h, Vec4::splat(0.));

    let a0 = b0.xzyw() + s0.xzyw() * sh.xxyy();
    let a1 = b1.xzyw() + s1.xzyw() * sh.zzww();

    let mut p0 = a0.xy().extend(h.x);
    let mut p1 = a0.zw().extend(h.y);
    let mut p2 = a1.xy().extend(h.z);
    let mut p3 = a1.zw().extend(h.w);

    // normalize gradients
    let norm = taylor_inv_sqrt_4(vec4(
        Vec3::dot(p0, p0),
        Vec3::dot(p1, p1),
        Vec3::dot(p2, p2),
        Vec3::dot(p3, p3),
    ));
    p0 *= norm.x;
    p1 *= norm.y;
    p2 *= norm.z;
    p3 *= norm.w;

    // mix final noise value
    let mut m = 0.5
        - vec4(
            Vec3::dot(x0, x0),
            Vec3::dot(x1, x1),
            Vec3::dot(x2, x2),
            Vec3::dot(x3, x3),
        );
    m = Vec4::max(m, Vec4::ZERO);
    m *= m;
    105. * Vec4::dot(
        m * m,
        vec4(
            Vec3::dot(p0, x0),
            Vec3::dot(p1, x1),
            Vec3::dot(p2, x2),
            Vec3::dot(p3, x3),
        ),
    )
}

// MIT License. © Ian McEwan, Stefan Gustavson, Munrocket, Johan Helsing
/// Simplex noise in three dimensions
pub fn simplex_noise_3d_seeded(v: Vec3, seed: Vec3) -> f32 {
    const C: Vec2 = vec2(1. / 6., 1. / 3.);
    const D: Vec4 = vec4(0., 0.5, 1., 2.);

    // first corner
    let mut i = (v + Vec3::dot(v, C.yyy())).floor();
    let x0 = v - i + Vec3::dot(i, C.xxx());

    // other corners
    let g = step_3(x0.yzx(), x0.xyz());
    let l = 1. - g;
    let i1 = Vec3::min(g.xyz(), l.zxy());
    let i2 = Vec3::max(g.xyz(), l.zxy());

    // x0 = x0 - 0. + 0. * C
    let x1 = x0 - i1 + 1. * C.xxx();
    let x2 = x0 - i2 + 2. * C.xxx();
    let x3 = x0 - 1. + 3. * C.xxx();

    // permutations
    i %= Vec3::splat(289.);
    let seed = (seed + 0.5).floor();
    let p = permute_4(
        permute_4(
            permute_4(i.z + vec4(0., i1.z, i2.z, 1.) + seed.z)
                + i.y
                + vec4(0., i1.y, i2.y, 1.)
                + seed.y,
        ) + i.x
            + vec4(0., i1.x, i2.x, 1.)
            + seed.x,
    );

    // gradients (NxN points uniformly over a square, mapped onto an octahedron)
    let n_ = 1. / 7.; // N=7
    let ns = n_ * D.wyz() - D.xzx();

    let j = p - 49. * (p * ns.z * ns.z).floor(); // mod(p, N*N)

    let x_ = (j * ns.z).floor();
    let y_ = (j - 7. * x_).floor(); // mod(j, N)

    let x = x_ * ns.x + ns.yyyy();
    let y = y_ * ns.x + ns.yyyy();
    let h = 1. - x.abs() - y.abs();

    let b0 = vec4(x.x, x.y, y.x, y.y);
    let b1 = vec4(x.z, x.w, y.z, y.w);

    let s0 = b0.floor() * 2. + 1.;
    let s1 = b1.floor() * 2. + 1.;
    let sh = -step_4(h, Vec4::splat(0.));

    let a0 = b0.xzyw() + s0.xzyw() * sh.xxyy();
    let a1 = b1.xzyw() + s1.xzyw() * sh.zzww();

    let mut p0 = a0.xy().extend(h.x);
    let mut p1 = a0.zw().extend(h.y);
    let mut p2 = a1.xy().extend(h.z);
    let mut p3 = a1.zw().extend(h.w);

    // normalize gradients
    let norm = taylor_inv_sqrt_4(vec4(
        Vec3::dot(p0, p0),
        Vec3::dot(p1, p1),
        Vec3::dot(p2, p2),
        Vec3::dot(p3, p3),
    ));
    p0 *= norm.x;
    p1 *= norm.y;
    p2 *= norm.z;
    p3 *= norm.w;

    // mix final noise value
    let mut m = 0.5
        - vec4(
            Vec3::dot(x0, x0),
            Vec3::dot(x1, x1),
            Vec3::dot(x2, x2),
            Vec3::dot(x3, x3),
        );
    m = Vec4::max(m, Vec4::ZERO);
    m *= m;
    105. * Vec4::dot(
        m * m,
        vec4(
            Vec3::dot(p0, x0),
            Vec3::dot(p1, x1),
            Vec3::dot(p2, x2),
            Vec3::dot(p3, x3),
        ),
    )
}

/// Fractional brownian motion (fbm) based on 2d simplex noise
pub fn fbm_simplex_2d(pos: Vec2, octaves: usize, lacunarity: f32, gain: f32) -> f32 {
    let mut sum = 0.;
    let mut amplitude = 1.;
    let mut frequency = 1.;

    for _ in 0..octaves {
        sum += simplex_noise_2d(pos * frequency) * amplitude;
        amplitude *= gain;
        frequency *= lacunarity;
    }

    sum
}

/// Fractional brownian motion (fbm) based on seeded 2d simplex noise
pub fn fbm_simplex_2d_seeded(
    pos: Vec2,
    octaves: usize,
    lacunarity: f32,
    gain: f32,
    seed: f32,
) -> f32 {
    let mut sum = 0.;
    let mut amplitude = 1.;
    let mut frequency = 1.;

    for _ in 0..octaves {
        sum += simplex_noise_2d_seeded(pos * frequency, seed) * amplitude;
        amplitude *= gain;
        frequency *= lacunarity;
    }

    sum
}

const MAX_WARP_ITERATIONS: usize = 4;

/// The return value of the domain warping function.
#[derive(Copy, Clone)]
pub struct WarpResult {
    /// The final noise value
    pub noise_value: f32,
    /// The history of warped coordinates, where positions[0] is the last iteration, positions[1] is second to last, etc.
    /// Can be useful for mixing colors.
    pub positions: [Vec2; MAX_WARP_ITERATIONS],
}

/// A technique that distorts the position before feeding it to the noise
/// inspired by https://iquilezles.org/articles/warp/
#[allow(clippy::too_many_arguments)]
pub fn fbm_simplex_2d_warp_seeded(
    pos_initial: Vec2,
    octaves: usize,
    lacunarity: f32,
    gain: f32,
    seed: f32,
    warp_iterations: usize,
    warp_scale: Vec2,
    falloff: f32,
) -> WarpResult {
    let mut pos = pos_initial;
    let mut scale = 1.0;
    let mut positions = [Vec2::ZERO; MAX_WARP_ITERATIONS];

    for i in 0..warp_iterations {
        pos.x += scale * warp_scale.x * fbm_simplex_2d_seeded(pos, octaves, lacunarity, gain, seed);
        pos.y += scale * warp_scale.y * fbm_simplex_2d_seeded(pos, octaves, lacunarity, gain, seed);

        // Store positions in reverse order (last iteration at index 0)
        let index = MAX_WARP_ITERATIONS - 1 - i;
        if index < MAX_WARP_ITERATIONS {
            positions[index] = pos;
        }

        scale *= falloff;
    }

    let noise_value = fbm_simplex_2d_seeded(positions[3], octaves, lacunarity, gain, seed);

    WarpResult {
        noise_value,
        positions,
    }
}

/// Fractional brownian motion (fbm) based on 3d simplex noise
pub fn fbm_simplex_3d(pos: Vec3, octaves: usize, lacunarity: f32, gain: f32) -> f32 {
    let mut sum = 0.;
    let mut amplitude = 1.;
    let mut frequency = 1.;

    for _ in 0..octaves {
        sum += simplex_noise_3d(pos * frequency) * amplitude;
        amplitude *= gain;
        frequency *= lacunarity;
    }

    sum
}

/// Fractional brownian motion (fbm) based on seeded 3d simplex noise
pub fn fbm_simplex_3d_seeded(
    pos: Vec3,
    octaves: usize,
    lacunarity: f32,
    gain: f32,
    seed: Vec3,
) -> f32 {
    let mut sum = 0.;
    let mut amplitude = 1.;
    let mut frequency = 1.;

    for _ in 0..octaves {
        sum += simplex_noise_3d_seeded(pos * frequency, seed) * amplitude;
        amplitude *= gain;
        frequency *= lacunarity;
    }

    sum
}

/// Cellular noise
pub fn worley_2d(pos: Vec2, jitter: f32) -> Vec2 {
    const K: f32 = 1.0 / 7.0;
    const KO: f32 = 3.0 / 7.0;

    // Determine the grid cell and fractional position
    let pi = pos.floor();
    let pf = pos.fract_gl();

    // Define offset indices for neighboring grid cells
    let oi = vec3(-1.0, 0.0, 1.0);
    let of_ = vec3(-0.5, 0.5, 1.5);

    // Permute the grid cell indices to get unique values for each cell
    let px = permute_3(pi.x + oi);
    let mut p = permute_3(px.x + pi.y + oi); // p11, p12, p13

    let mut ox = (p * K).fract_gl() - KO;
    let mut oy = (p * K).floor() % 7.0 * K - KO;
    let mut dx = pf.x + 0.5 + jitter * ox;
    let mut dy = pf.y - of_ + jitter * oy;
    let mut d1 = dx * dx + dy * dy;

    p = permute_3(px.y + pi.y + oi); // p21, p22, p23
    ox = (p * K).fract_gl() - KO;
    oy = ((p * K).floor() % 7.0) * K - KO;
    dx = pf.x - 0.5 + jitter * ox;
    dy = pf.y - of_ + jitter * oy;
    let mut d2 = dx * dx + dy * dy; // d21, d22, d23, squared

    p = permute_3(px.z + pi.y + oi); // p31, p32, p33
    ox = (p * K).fract_gl() - KO;
    oy = ((p * K).floor() % 7.0) * K - KO;
    dx = pf.x - 1.5 + jitter * ox;
    dy = pf.y - of_ + jitter * oy;
    let d3 = dx * dx + dy * dy; // d31, d32, d33, squared

    // Find the two smallest distances (F1 and F2)
    let d1a = d1.min(d2);
    d2 = d1.max(d2);
    d2 = d2.min(d3);
    d1 = d1a.min(d2);
    d2 = d1a.max(d2);

    if d1.x > d1.y {
        core::mem::swap(&mut d1.x, &mut d1.y);
    }

    if d1.x > d1.z {
        core::mem::swap(&mut d1.x, &mut d1.z);
    }

    d1.y = d1.y.min(d2.y);
    d1.z = d1.z.min(d2.z);
    d1.y = d1.y.min(d1.z);
    d1.y = d1.y.min(d2.x);

    vec2(d1.x.sqrt(), d1.y.sqrt())
}

#[cfg(test)]
mod test {
    use super::*;
    use insta::assert_debug_snapshot;

    fn sample_2d_fn(f: fn(Vec2) -> f32) -> Vec<f32> {
        let mut values = Vec::new();
        for x in -20..20 {
            let x = x as f32 / 10.;
            for y in -20..20 {
                let y = y as f32 / 10.;
                let v = f(vec2(x, y));
                values.push(v);
            }
        }
        values
    }

    fn sample_3d_fn(f: fn(Vec3) -> f32) -> Vec<f32> {
        let mut values = Vec::new();
        for x in -5..5 {
            let x = x as f32 / 10.;
            for y in -5..5 {
                let y = y as f32 / 10.;
                for z in -5..5 {
                    let z = z as f32 / 10.;
                    let v = f(vec3(x, y, z));
                    values.push(v);
                }
            }
        }
        values
    }

    fn sample_3d_seeded_fn(f: fn(Vec3, Vec3) -> f32) -> Vec<f32> {
        let mut values = Vec::new();
        for seed in [Vec3::X, Vec3::Y, Vec3::Z] {
            for x in -5..5 {
                let x = x as f32 / 10.;
                for y in -5..5 {
                    let y = y as f32 / 10.;
                    for z in -5..5 {
                        let z = z as f32 / 10.;
                        let v = f(vec3(x, y, z), seed);
                        values.push(v);
                    }
                }
            }
        }
        values
    }

    #[test]
    fn simplex_2d_values_unchanged() {
        assert_debug_snapshot!(sample_2d_fn(simplex_noise_2d));
    }

    #[test]
    fn simplex_2d_seeded_values_unchanged() {
        assert_debug_snapshot!(sample_2d_fn(|p| simplex_noise_2d_seeded(p, 0.0)));
        assert_debug_snapshot!(sample_2d_fn(|p| simplex_noise_2d_seeded(p, 123.0)));
    }

    #[test]
    fn fbm_2d_warp_seeded_values_unchanged() {
        assert_debug_snapshot!(sample_2d_fn(|p| {
            fbm_simplex_2d_warp_seeded(p, 10, 2.9, 0.4, 324.0, 4, vec2(0.4, 0.4), 0.1).noise_value
        }));
    }

    #[test]
    fn simplex_3d_values_unchanged() {
        assert_debug_snapshot!(sample_3d_fn(simplex_noise_3d));
    }

    #[test]
    fn simplex_3d_seeded_values_unchanged() {
        assert_debug_snapshot!(sample_3d_seeded_fn(simplex_noise_3d_seeded));
    }

    #[test]
    fn fbm_2d_values_unchanged() {
        assert_debug_snapshot!(sample_2d_fn(|p| { fbm_simplex_2d(p, 5, 2.0, 0.5) }));
    }

    #[test]
    fn fbm_2d_seeded_values_unchanged() {
        assert_debug_snapshot!(sample_2d_fn(|p| {
            fbm_simplex_2d_seeded(p, 5, 2.0, 0.5, 0.0)
        }));
        assert_debug_snapshot!(sample_2d_fn(|p| {
            fbm_simplex_2d_seeded(p, 5, 2.0, 0.5, 123.0)
        }));
    }

    #[test]
    fn fbm_3d_values_unchanged() {
        assert_debug_snapshot!(sample_3d_fn(|p| { fbm_simplex_3d(p, 5, 2.0, 0.5) }));
    }

    #[test]
    fn fbm_3d_seeded_values_unchanged() {
        assert_debug_snapshot!(sample_3d_seeded_fn(|p, s| {
            fbm_simplex_3d_seeded(p, 5, 2.0, 0.5, s)
        }));
    }

    #[test]
    fn worley_2d_values_unchanged() {
        assert_debug_snapshot!({
            let mut values = Vec::new();
            for x in -20..20 {
                let x = x as f32 / 10.;
                for y in -20..20 {
                    let y = y as f32 / 10.;
                    let v = worley_2d(vec2(x, y), 1.0);
                    values.push(v);
                }
            }
            values
        });
    }
}