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

◆ draw()

void fl::Chasing_Spirals_Q31_SIMD::draw ( Context & ctx)
overridevirtual

Implements fl::IAnimartrix2Viz.

Definition at line 416 of file chasing_spirals.cpp.hpp.

416 {
418 const int total_pixels = setup.total_pixels;
419 const i32 *base_angle = setup.base_angle;
420 const i32 *dist_scaled = setup.dist_scaled;
421 const i32 *rf3_arr = setup.rf3;
422 const i32 *rf_half_arr = setup.rf_half;
423 const i32 *rf_qtr_arr = setup.rf_quarter;
424 const u16 *pixel_idx = setup.pixel_idx;
425 const i32 *fade_lut = setup.fade_lut;
426 const u8 *perm = setup.perm;
427 const i32 cx_raw = setup.cx_raw;
428 const i32 cy_raw = setup.cy_raw;
429 const i32 lin0_raw = setup.lin0_raw;
430 const i32 lin1_raw = setup.lin1_raw;
431 const i32 lin2_raw = setup.lin2_raw;
432 const i32 rad0_raw = setup.rad0_raw;
433 const i32 rad1_raw = setup.rad1_raw;
434 const i32 rad2_raw = setup.rad2_raw;
435 fl::span<CRGB> leds = setup.leds;
436
437 // SIMD pixel pipeline: process 4 pixels per iteration
438 int i = 0;
439 for (; i + 3 < total_pixels; i += 4) {
440 // Aligned SoA loads (arrays are FL_ALIGNAS(16), stride is 4)
441 auto base_vec = loadAligned(base_angle, i);
442 auto dist_vec = loadAligned(dist_scaled, i);
443 auto rf3_vec = loadAligned(rf3_arr, i);
444 auto rf_half_vec = loadAligned(rf_half_arr, i);
445 auto rf_qtr_vec = loadAligned(rf_qtr_arr, i);
446
447 auto r_vec = simd4_processChannel(
448 base_vec, dist_vec, rad0_raw, lin0_raw, fade_lut, perm, cx_raw, cy_raw, rf3_vec);
449 auto g_vec = simd4_processChannel(
450 base_vec, dist_vec, rad1_raw, lin1_raw, fade_lut, perm, cx_raw, cy_raw, rf_half_vec);
451 auto b_vec = simd4_processChannel(
452 base_vec, dist_vec, rad2_raw, lin2_raw, fade_lut, perm, cx_raw, cy_raw, rf_qtr_vec);
453
454 // Scatter to LED array (pixel_idx holds arbitrary xyMap-remapped indices)
455 scatterPixel(leds, pixel_idx[i+0], r_vec, g_vec, b_vec, 0);
456 scatterPixel(leds, pixel_idx[i+1], r_vec, g_vec, b_vec, 1);
457 scatterPixel(leds, pixel_idx[i+2], r_vec, g_vec, b_vec, 2);
458 scatterPixel(leds, pixel_idx[i+3], r_vec, g_vec, b_vec, 3);
459 }
460
461 // Scalar fallback for remaining pixels (when total_pixels % 4 != 0)
462 for (; i < total_pixels; i++) {
463 const i32 base_raw = base_angle[i];
464 const i32 dist_raw = dist_scaled[i];
465
466 auto noise_ch = [&](i32 rad_raw, i32 lin_raw) -> i32 {
467 u32 a24 = radiansToA24(base_raw, rad_raw);
468 SinCos32 sc = sincos32(a24);
469 i32 nx = perlinCoord(sc.cos_val, dist_raw, lin_raw + cx_raw);
470 i32 ny = perlinCoord(sc.sin_val, dist_raw, cy_raw);
471 i32 raw = Perlin::pnoise2d_raw(nx, ny, fade_lut, perm);
472 return clampAndScale255(raw);
473 };
474
475 i32 s0 = noise_ch(rad0_raw, lin0_raw);
476 i32 s1 = noise_ch(rad1_raw, lin1_raw);
477 i32 s2 = noise_ch(rad2_raw, lin2_raw);
478
479 i32 r = applyRadialFilter(s0, rf3_arr[i]);
480 i32 g = applyRadialFilter(s1, rf_half_arr[i]);
481 i32 b = applyRadialFilter(s2, rf_qtr_arr[i]);
482
483 leds[pixel_idx[i]] = CRGB(static_cast<u8>(r), static_cast<u8>(g), static_cast<u8>(b));
484 }
485}
void setup()
fl::CRGB leds[NUM_LEDS]
FASTLED_FORCE_INLINE u32 radiansToA24(i32 base_s16x16, i32 offset_s16x16)
FASTLED_FORCE_INLINE void scatterPixel(fl::span< CRGB > leds, u16 idx, simd::simd_u32x4 r, simd::simd_u32x4 g, simd::simd_u32x4 b, int lane)
FASTLED_FORCE_INLINE i32 applyRadialFilter(i32 noise_255, i32 rf_raw)
simd::simd_u32x4 simd4_processChannel(simd::simd_u32x4 base_vec, simd::simd_u32x4 dist_vec, i32 radial_offset, i32 linear_offset, const i32 *fade_lut, const u8 *perm, i32 cx_raw, i32 cy_raw, simd::simd_u32x4 rf_vec)
FASTLED_FORCE_INLINE i32 perlinCoord(i32 sc_val, i32 dist_raw, i32 offset)
FrameSetup setupChasingSpiralFrame(Context &ctx, ChasingSpiralState &state)
FASTLED_FORCE_INLINE i32 clampAndScale255(i32 raw_s16x16)
FASTLED_FORCE_INLINE simd::simd_u32x4 loadAligned(const i32 *arr, int i)
unsigned char u8
Definition stdint.h:131
fl::CRGB CRGB
Definition video.h:15
FASTLED_FORCE_INLINE SinCos32 sincos32(u32 angle) FL_NOEXCEPT
Definition sin32.h:88

References fl::SinCos32::cos_val, leds, mState, setup(), fl::SinCos32::sin_val, and fl::sincos32().

+ Here is the call graph for this function: