FastLED 3.10.8
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#include "fl/stl/noexcept.h"
12
13namespace fl {
14
16 static constexpr int HP_BITS = 8; // Q8 precision!
17 static constexpr fl::i32 HP_ONE = 1 << HP_BITS; // 256 = 1.0
18
19 // Build 257-entry Perlin fade LUT in Q8 format (8 fractional bits).
20 static void init_fade_lut(fl::i32 *table) FL_NO_EXCEPT;
21
22 // 2D Perlin noise. Input s16x16, output s16x16 approx [-1, 1].
24 const fl::i32 *fade_lut,
25 const fl::u8 *perm) FL_NO_EXCEPT;
26
27 // Raw i32 version using Q8 internal precision.
28 // Fast path: all arithmetic uses i16 operations (except final shift).
29 static fl::i32 pnoise2d_raw(fl::i32 fx_raw, fl::i32 fy_raw,
30 const fl::i32 *fade_lut,
31 const fl::u8 *perm) FL_NO_EXCEPT;
32
33 private:
34 static constexpr int FP_BITS = fl::s16x16::FRAC_BITS;
35 static constexpr fl::i32 FP_ONE = static_cast<fl::i32>(1) << FP_BITS;
36
37 // Decompose s16x16 raw value into integer floor and Q8 fractional part.
38 static FASTLED_FORCE_INLINE void floor_frac(fl::i32 fp16, int &ifloor,
39 fl::i16 &frac8) FL_NO_EXCEPT;
40
41 // LUT fade: Direct table lookup (t is already 8-bit index)
42 static FASTLED_FORCE_INLINE fl::i16 fade(fl::i16 t, const fl::i32 *table) FL_NO_EXCEPT;
43
44 static FASTLED_FORCE_INLINE fl::i16 lerp(fl::i16 t, fl::i16 a, fl::i16 b) FL_NO_EXCEPT;
45
46 // z=0 gradient via branchless coefficient LUT (Q8 format).
47 static FASTLED_FORCE_INLINE fl::i16 grad(int hash, fl::i16 x, fl::i16 y) FL_NO_EXCEPT;
48};
49
50} // namespace fl
static constexpr int FRAC_BITS
Definition s16x16.h:24
#define FASTLED_FORCE_INLINE
unsigned char u8
Definition stdint.h:131
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
Base definition for an LED controller.
Definition crgb.hpp:179
static fl::i32 pnoise2d_raw(fl::i32 fx_raw, fl::i32 fy_raw, const fl::i32 *fade_lut, const fl::u8 *perm) FL_NO_EXCEPT
static constexpr fl::i32 HP_ONE
Definition perlin_s8x8.h:17
static FASTLED_FORCE_INLINE fl::i16 fade(fl::i16 t, const fl::i32 *table) FL_NO_EXCEPT
static FASTLED_FORCE_INLINE fl::i16 lerp(fl::i16 t, fl::i16 a, fl::i16 b) FL_NO_EXCEPT
static constexpr fl::i32 FP_ONE
Definition perlin_s8x8.h:35
static FASTLED_FORCE_INLINE fl::i16 grad(int hash, fl::i16 x, fl::i16 y) FL_NO_EXCEPT
static FASTLED_FORCE_INLINE void floor_frac(fl::i32 fp16, int &ifloor, fl::i16 &frac8) FL_NO_EXCEPT
static constexpr int HP_BITS
Definition perlin_s8x8.h:16
static fl::s16x16 pnoise2d(fl::s16x16 fx, fl::s16x16 fy, const fl::i32 *fade_lut, const fl::u8 *perm) FL_NO_EXCEPT
static constexpr int FP_BITS
Definition perlin_s8x8.h:34
static void init_fade_lut(fl::i32 *table) FL_NO_EXCEPT