FastLED 3.9.15
Loading...
Searching...
No Matches
perlin_s8x8.h
Go to the documentation of this file.
1#pragma once
2
3// 2D Perlin noise s8x8 implementation
4// Extracted from animartrix_detail.hpp
5//
6// s8x8 Perlin: Ultra-fast 8-bit variant for maximum speed with reduced precision
7// Uses 8 fractional bits throughout. Trades accuracy for speed (4x faster multiplies vs i32).
8
11
12namespace fl {
13
15 static constexpr int HP_BITS = 8; // Q8 precision!
16 static constexpr fl::i32 HP_ONE = 1 << HP_BITS; // 256 = 1.0
17
18 // Build 257-entry Perlin fade LUT in Q8 format (8 fractional bits).
19 static void init_fade_lut(fl::i32 *table);
20
21 // 2D Perlin noise. Input s16x16, output s16x16 approx [-1, 1].
23 const fl::i32 *fade_lut,
24 const fl::u8 *perm);
25
26 // Raw i32 version using Q8 internal precision.
27 // Fast path: all arithmetic uses i16 operations (except final shift).
28 static fl::i32 pnoise2d_raw(fl::i32 fx_raw, fl::i32 fy_raw,
29 const fl::i32 *fade_lut,
30 const fl::u8 *perm);
31
32 private:
33 static constexpr int FP_BITS = fl::s16x16::FRAC_BITS;
34 static constexpr fl::i32 FP_ONE = static_cast<fl::i32>(1) << FP_BITS;
35
36 // Decompose s16x16 raw value into integer floor and Q8 fractional part.
37 static FASTLED_FORCE_INLINE void floor_frac(fl::i32 fp16, int &ifloor,
38 fl::i16 &frac8);
39
40 // LUT fade: Direct table lookup (t is already 8-bit index)
41 static FASTLED_FORCE_INLINE fl::i16 fade(fl::i16 t, const fl::i32 *table);
42
43 static FASTLED_FORCE_INLINE fl::i16 lerp(fl::i16 t, fl::i16 a, fl::i16 b);
44
45 // z=0 gradient via branchless coefficient LUT (Q8 format).
46 static FASTLED_FORCE_INLINE fl::i16 grad(int hash, fl::i16 x, fl::i16 y);
47};
48
49} // namespace fl
static constexpr int FRAC_BITS
Definition s16x16.h:22
unsigned char u8
Definition s16x16x4.h:132
Base definition for an LED controller.
Definition crgb.hpp:179
#define FASTLED_FORCE_INLINE
static constexpr fl::i32 HP_ONE
Definition perlin_s8x8.h:16
static FASTLED_FORCE_INLINE fl::i16 grad(int hash, fl::i16 x, fl::i16 y)
static constexpr fl::i32 FP_ONE
Definition perlin_s8x8.h:34
static FASTLED_FORCE_INLINE void floor_frac(fl::i32 fp16, int &ifloor, fl::i16 &frac8)
static fl::i32 pnoise2d_raw(fl::i32 fx_raw, fl::i32 fy_raw, const fl::i32 *fade_lut, const fl::u8 *perm)
static FASTLED_FORCE_INLINE fl::i16 fade(fl::i16 t, const fl::i32 *table)
static constexpr int HP_BITS
Definition perlin_s8x8.h:15
static void init_fade_lut(fl::i32 *table)
static fl::s16x16 pnoise2d(fl::s16x16 fx, fl::s16x16 fy, const fl::i32 *fade_lut, const fl::u8 *perm)
static FASTLED_FORCE_INLINE fl::i16 lerp(fl::i16 t, fl::i16 a, fl::i16 b)
static constexpr int FP_BITS
Definition perlin_s8x8.h:33