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

◆ pnoise2d_raw()

fl::i32 fl::perlin_i16_optimized::pnoise2d_raw ( fl::i32 fx_raw,
fl::i32 fy_raw,
const fl::i32 * fade_lut,
const fl::u8 * perm )
static

Definition at line 34 of file perlin_i16_optimized.cpp.hpp.

36 {
37 int X, Y;
38 fl::i16 x16, y16; // i16 fractional parts!
39 floor_frac_i16(fx_raw, X, x16);
40 floor_frac_i16(fy_raw, Y, y16);
41 X &= 255;
42 Y &= 255;
43
44 // Fade values can be up to 65536, need to stay i32
45 // But we can still optimize grad and internal lerp to use i16
46 fl::i32 u = fade(x16, fade_lut);
47 fl::i32 v = fade(y16, fade_lut);
48
49 int A = perm[X & 255] + Y;
50 int AA = perm[A & 255];
51 int AB = perm[(A + 1) & 255];
52 int B = perm[(X + 1) & 255] + Y;
53 int BA = perm[B & 255];
54 int BB = perm[(B + 1) & 255];
55
56 // grad returns i16 (coordinates are i16), lerp takes i32 fade values
57 fl::i32 g00 = grad_i16(perm[AA & 255], x16, y16);
58 fl::i32 g10 = grad_i16(perm[BA & 255], x16 - HP_ONE_I16, y16);
59 fl::i32 g01 = grad_i16(perm[AB & 255], x16, y16 - HP_ONE_I16);
60 fl::i32 g11 = grad_i16(perm[BB & 255], x16 - HP_ONE_I16, y16 - HP_ONE_I16);
61
62 // Lerp with i32 (grad results fit in i16 range but lerp needs i32 for fade values)
63 fl::i32 lerp0 = lerp(u, g00, g10);
64 fl::i32 lerp1 = lerp(u, g01, g11);
65 fl::i32 result = lerp(v, lerp0, lerp1);
66
67 return result;
68}
FL_DISABLE_WARNING_PUSH unsigned char * B
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31
static FASTLED_FORCE_INLINE void floor_frac_i16(fl::i32 fp16, int &ifloor, fl::i16 &frac16)
static constexpr fl::i32 HP_ONE_I16
static FASTLED_FORCE_INLINE fl::i32 grad_i16(int hash, fl::i16 x, fl::i16 y)
static FASTLED_FORCE_INLINE fl::i32 lerp(fl::i32 t, fl::i32 a, fl::i32 b)
static FASTLED_FORCE_INLINE fl::i32 fade(fl::i16 t, const fl::i32 *table)

References fl::B, fade(), floor_frac_i16(), grad_i16(), HP_ONE_I16, and lerp().

Referenced by pnoise2d(), and autoresearch::animartrix_check::runPerlinBenchmark().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: