FastLED 3.9.15
Loading...
Searching...
No Matches

◆ inoise16_raw() [4/4]

int16_t inoise16_raw ( uint32_t x,
uint32_t y,
uint32_t z,
uint32_t w )
extern

Definition at line 387 of file noise.cpp.

387 {
388 // 1. Extract the integer (grid) parts.
389 uint8_t X = (x >> 16) & 0xFF;
390 uint8_t Y = (y >> 16) & 0xFF;
391 uint8_t Z = (z >> 16) & 0xFF;
392 uint8_t T = (t >> 16) & 0xFF;
393
394 // 2. Extract the fractional parts.
395 uint16_t u = x & 0xFFFF;
396 uint16_t v = y & 0xFFFF;
397 uint16_t w = z & 0xFFFF;
398 uint16_t s = t & 0xFFFF;
399
400 // 3. Easing of the fractional parts.
401 u = EASE16(u);
402 v = EASE16(v);
403 w = EASE16(w);
404 s = EASE16(s);
405
406 uint16_t N = 0x8000L; // fixed-point half-scale
407
408 // 4. Precompute fixed-point versions for the gradient evaluations.
409 int16_t xx = (u >> 1) & 0x7FFF;
410 int16_t yy = (v >> 1) & 0x7FFF;
411 int16_t zz = (w >> 1) & 0x7FFF;
412
413 // 5. Hash the 3D cube corners (the “base” for both t slices).
414 uint8_t A = P(X) + Y;
415 uint8_t AA = P(A) + Z;
416 uint8_t AB = P(A + 1) + Z;
417 uint8_t B = P(X + 1) + Y;
418 uint8_t BA = P(B) + Z;
419 uint8_t BB = P(B + 1) + Z;
420
421 // 6. --- Lower t Slice (using T) ---
422 uint8_t AAA = P(AA) + T;
423 uint8_t AAB = P(AA + 1) + T;
424 uint8_t ABA = P(AB) + T;
425 uint8_t ABB = P(AB + 1) + T;
426 uint8_t BAA = P(BA) + T;
427 uint8_t BAB = P(BA + 1) + T;
428 uint8_t BBA = P(BB) + T;
429 uint8_t BBB = P(BB + 1) + T;
430
431 int16_t L1 = LERP(grad16(AAA, xx, yy, zz), grad16(BAA, xx - N, yy, zz), u);
432 int16_t L2 = LERP(grad16(ABA, xx, yy - N, zz), grad16(BBA, xx - N, yy - N, zz), u);
433 int16_t L3 = LERP(grad16(AAB, xx, yy, zz - N), grad16(BAB, xx - N, yy, zz - N), u);
434 int16_t L4 = LERP(grad16(ABB, xx, yy - N, zz - N), grad16(BBB, xx - N, yy - N, zz - N), u);
435
436 int16_t Y1 = LERP(L1, L2, v);
437 int16_t Y2 = LERP(L3, L4, v);
438 int16_t noise_lower = LERP(Y1, Y2, w);
439
440 // 7. --- Upper t Slice (using T+1) ---
441 uint8_t Tupper = T + 1;
442 uint8_t AAA_u = P(AA) + Tupper;
443 uint8_t AAB_u = P(AA + 1) + Tupper;
444 uint8_t ABA_u = P(AB) + Tupper;
445 uint8_t ABB_u = P(AB + 1) + Tupper;
446 uint8_t BAA_u = P(BA) + Tupper;
447 uint8_t BAB_u = P(BA + 1) + Tupper;
448 uint8_t BBA_u = P(BB) + Tupper;
449 uint8_t BBB_u = P(BB + 1) + Tupper;
450
451 int16_t U1 = LERP(grad16(AAA_u, xx, yy, zz), grad16(BAA_u, xx - N, yy, zz), u);
452 int16_t U2 = LERP(grad16(ABA_u, xx, yy - N, zz), grad16(BBA_u, xx - N, yy - N, zz), u);
453 int16_t U3 = LERP(grad16(AAB_u, xx, yy, zz - N), grad16(BAB_u, xx - N, yy, zz - N), u);
454 int16_t U4 = LERP(grad16(ABB_u, xx, yy - N, zz - N), grad16(BBB_u, xx - N, yy - N, zz - N), u);
455
456 int16_t V1 = LERP(U1, U2, v);
457 int16_t V2 = LERP(U3, U4, v);
458 int16_t noise_upper = LERP(V1, V2, w);
459
460 // 8. Final interpolation in the t dimension.
461 int16_t noise4d = LERP(noise_lower, noise_upper, s);
462
463 return noise4d;
464}
uint32_t z[NUM_LAYERS]
Definition Fire2023.ino:82
uint32_t x[NUM_LAYERS]
Definition Fire2023.ino:80
uint32_t y[NUM_LAYERS]
Definition Fire2023.ino:81
#define P(x)
Reads a single byte from the p array.
Definition noise.cpp:51
static int16_t grad16(uint8_t hash, int16_t x, int16_t y, int16_t z)
Definition noise.cpp:133

References grad16(), P, x, y, and z.

+ Here is the call graph for this function: