mirror of
https://github.com/wled/WLED.git
synced 2025-07-24 11:16:37 +00:00
Soap gap bugfix & aditional size tuning
This commit is contained in:
parent
8e7d6d5dad
commit
2473065b98
@ -7469,40 +7469,54 @@ static const char _data_FX_MODE_2DDISTORTIONWAVES[] PROGMEM = "Distortion Waves@
|
|||||||
//@Stepko
|
//@Stepko
|
||||||
//Idea from https://www.youtube.com/watch?v=DiHBgITrZck&ab_channel=StefanPetrick
|
//Idea from https://www.youtube.com/watch?v=DiHBgITrZck&ab_channel=StefanPetrick
|
||||||
// adapted for WLED by @blazoncek, optimization by @dedehai
|
// adapted for WLED by @blazoncek, optimization by @dedehai
|
||||||
void soapProcessPixels(bool isRow, uint8_t* noise3d) {
|
static void soapPixels(bool isRow, uint8_t *noise3d, CRGB *pixels) {
|
||||||
const int cols = SEG_W;
|
const int cols = SEG_W;
|
||||||
const int rows = SEG_H;
|
const int rows = SEG_H;
|
||||||
const auto XY = [&](int x, int y) { return (x%cols) + (y%rows) * cols; };
|
const auto XY = [&](int x, int y) { return x + y * cols; };
|
||||||
CRGB ledsbuff[MAX(cols,rows)];
|
const auto abs = [](int x) { return x<0 ? -x : x; };
|
||||||
const int rowcol = isRow ? rows : cols;
|
const int tRC = isRow ? rows : cols; // transpose if isRow
|
||||||
const int colrow = isRow ? cols : rows;
|
const int tCR = isRow ? cols : rows; // transpose if isRow
|
||||||
int amplitude = isRow ? (cols-8) >> 3 : (rows-8) >> 3;
|
const int amplitude = 2 * ((tCR >= 16) ? (tCR-8) : 8) / (1 + ((255 - SEGMENT.custom1) >> 5));
|
||||||
amplitude = 2 * max(1, amplitude * (1 + SEGMENT.custom1) >> 6);
|
const int shift = 0; //(128 - SEGMENT.custom2)*2;
|
||||||
|
|
||||||
for (int i = 0; i < rowcol; i++) {
|
CRGB ledsbuff[tCR];
|
||||||
int amount = ((int)noise3d[isRow ? i * cols : i] - 128) * amplitude;
|
|
||||||
int delta = abs(amount) >> 8;
|
for (int i = 0; i < tRC; i++) {
|
||||||
|
int amount = ((int)noise3d[isRow ? i*cols : i] - 128) * amplitude + shift; // use first row/column: XY(0,i)/XY(i,0)
|
||||||
|
int delta = abs(amount) >> 8;
|
||||||
int fraction = abs(amount) & 255;
|
int fraction = abs(amount) & 255;
|
||||||
for (int j = 0; j < colrow; j++) {
|
for (int j = 0; j < tCR; j++) {
|
||||||
int zD, zF;
|
int zD, zF;
|
||||||
if (amount < 0) {
|
if (amount < 0) {
|
||||||
zD = j - delta;
|
zD = j - delta;
|
||||||
zF = zD - 1;
|
zF = zD - 1;
|
||||||
} else {
|
} else {
|
||||||
zD = j + delta;
|
zD = j + delta;
|
||||||
zF = zD + 1;
|
zF = zD + 1;
|
||||||
}
|
}
|
||||||
CRGB PixelA = CRGB::Black;
|
int yA = abs(zD);
|
||||||
if ((zD >= 0) && (zD < colrow)) PixelA = isRow ? SEGMENT.getPixelColorXY(zD, i) : SEGMENT.getPixelColorXY(i, zD);
|
int yB = abs(zF);
|
||||||
else PixelA = ColorFromPalette(SEGPALETTE, ~noise3d[isRow ? XY(abs(zD), i) : XY(i, abs(zD))] * 3);
|
int xA = i;
|
||||||
CRGB PixelB = CRGB::Black;
|
int xB = i;
|
||||||
if ((zF >= 0) && (zF < colrow)) PixelB = isRow ? SEGMENT.getPixelColorXY(zF, i) : SEGMENT.getPixelColorXY(i, zF);
|
if (isRow) {
|
||||||
else PixelB = ColorFromPalette(SEGPALETTE, ~noise3d[isRow ? XY(abs(zF), i) : XY(i, abs(zF))] * 3);
|
std::swap(xA,yA);
|
||||||
|
std::swap(xB,yB);
|
||||||
|
}
|
||||||
|
const int indxA = XY(xA,yA);
|
||||||
|
const int indxB = XY(xB,yB);
|
||||||
|
CRGB PixelA;
|
||||||
|
CRGB PixelB;
|
||||||
|
if ((zD >= 0) && (zD < tCR)) PixelA = pixels[indxA];
|
||||||
|
else PixelA = ColorFromPalette(SEGPALETTE, ~noise3d[indxA]*3);
|
||||||
|
if ((zF >= 0) && (zF < tCR)) PixelB = pixels[indxB];
|
||||||
|
else PixelB = ColorFromPalette(SEGPALETTE, ~noise3d[indxB]*3);
|
||||||
ledsbuff[j] = (PixelA.nscale8(ease8InOutApprox(255 - fraction))) + (PixelB.nscale8(ease8InOutApprox(fraction)));
|
ledsbuff[j] = (PixelA.nscale8(ease8InOutApprox(255 - fraction))) + (PixelB.nscale8(ease8InOutApprox(fraction)));
|
||||||
}
|
}
|
||||||
for (int j = 0; j < colrow; j++) {
|
for (int j = 0; j < tCR; j++) {
|
||||||
if (isRow) SEGMENT.setPixelColorXY(j, i, ledsbuff[j]);
|
CRGB c = ledsbuff[j];
|
||||||
else SEGMENT.setPixelColorXY(i, j, ledsbuff[j]);
|
if (isRow) std::swap(j,i);
|
||||||
|
SEGMENT.setPixelColorXY(i, j, pixels[XY(i,j)] = c);
|
||||||
|
if (isRow) std::swap(j,i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -7512,24 +7526,22 @@ uint16_t mode_2Dsoap() {
|
|||||||
|
|
||||||
const int cols = SEG_W;
|
const int cols = SEG_W;
|
||||||
const int rows = SEG_H;
|
const int rows = SEG_H;
|
||||||
const auto XY = [&](int x, int y) { return (x%cols) + (y%rows) * cols; };
|
const auto XY = [&](int x, int y) { return x + y * cols; };
|
||||||
|
|
||||||
const size_t dataSize = SEGMENT.width() * SEGMENT.height() * sizeof(uint8_t); // prevent reallocation if mirrored or grouped
|
const size_t segSize = SEGMENT.width() * SEGMENT.height(); // prevent reallocation if mirrored or grouped
|
||||||
|
const size_t dataSize = segSize * (sizeof(uint8_t) + sizeof(CRGB)); // pixels and noise
|
||||||
if (!SEGENV.allocateData(dataSize + sizeof(uint32_t)*3)) return mode_static(); //allocation failed
|
if (!SEGENV.allocateData(dataSize + sizeof(uint32_t)*3)) return mode_static(); //allocation failed
|
||||||
|
|
||||||
uint8_t *noise3d = reinterpret_cast<uint8_t*>(SEGENV.data);
|
uint8_t *noise3d = reinterpret_cast<uint8_t*>(SEGENV.data);
|
||||||
|
CRGB *pixels = reinterpret_cast<CRGB*>(SEGENV.data + segSize * sizeof(uint8_t));
|
||||||
uint32_t *noisecoord = reinterpret_cast<uint32_t*>(SEGENV.data + dataSize); // x, y, z coordinates
|
uint32_t *noisecoord = reinterpret_cast<uint32_t*>(SEGENV.data + dataSize); // x, y, z coordinates
|
||||||
const uint32_t scale32_x = 160000U/cols;
|
const uint32_t scale32_x = 160000U/cols;
|
||||||
const uint32_t scale32_y = 160000U/rows;
|
const uint32_t scale32_y = 160000U/rows;
|
||||||
const uint32_t mov = MIN(cols,rows)*(SEGMENT.speed+2)/2;
|
const uint32_t mov = MIN(cols,rows)*(SEGMENT.speed+2)/2;
|
||||||
const uint8_t smoothness = MIN(250,SEGMENT.intensity); // limit as >250 produces very little changes
|
const uint8_t smoothness = MIN(250,SEGMENT.intensity); // limit as >250 produces very little changes
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
if (SEGENV.call == 0) for (int i = 0; i < 3; i++) noisecoord[i] = hw_random(); // init
|
||||||
if (SEGENV.call == 0)
|
else for (int i = 0; i < 3; i++) noisecoord[i] += mov;
|
||||||
noisecoord[i] = hw_random(); // init
|
|
||||||
else
|
|
||||||
noisecoord[i] += mov;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < cols; i++) {
|
for (int i = 0; i < cols; i++) {
|
||||||
int32_t ioffset = scale32_x * (i - cols / 2);
|
int32_t ioffset = scale32_x * (i - cols / 2);
|
||||||
@ -7550,12 +7562,12 @@ uint16_t mode_2Dsoap() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
soapProcessPixels(true, noise3d); // rows
|
soapPixels(true, noise3d, pixels); // rows
|
||||||
soapProcessPixels(false, noise3d); // cols
|
soapPixels(false, noise3d, pixels); // cols
|
||||||
|
|
||||||
return FRAMETIME;
|
return FRAMETIME;
|
||||||
}
|
}
|
||||||
static const char _data_FX_MODE_2DSOAP[] PROGMEM = "Soap@!,Smoothness,Density;;!;2;pal=11";
|
static const char _data_FX_MODE_2DSOAP[] PROGMEM = "Soap@!,Smoothness,Density;;!;2;pal=11,c1=0";
|
||||||
|
|
||||||
|
|
||||||
//Idea from https://www.youtube.com/watch?v=HsA-6KIbgto&ab_channel=GreatScott%21
|
//Idea from https://www.youtube.com/watch?v=HsA-6KIbgto&ab_channel=GreatScott%21
|
||||||
|
Loading…
x
Reference in New Issue
Block a user