Skip to content

Commit

Permalink
PolarLights and Octopus: deterministic + SuperSync control
Browse files Browse the repository at this point in the history
FX.cpp
- SuperSync control on Polar lights and Octopus:  only calculate pixels for the first panel
  • Loading branch information
ewowi committed Oct 8, 2023
1 parent 4b12f05 commit 71abd11
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
60 changes: 45 additions & 15 deletions wled00/FX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5481,7 +5481,6 @@ uint16_t mode_2DPolarLights(void) { // By: Kostyantyn Matviyevskyy https
if (SEGENV.call == 0) {
SEGMENT.setUpLeds();
SEGMENT.fill(BLACK);
SEGENV.step = 0;
}

float adjustHeight = (float)map(rows, 8, 32, 28, 12); // maybe use mapf() ???
Expand All @@ -5504,19 +5503,35 @@ uint16_t mode_2DPolarLights(void) { // By: Kostyantyn Matviyevskyy https
uint16_t _scale = map(SEGMENT.intensity, 0, 255, 30, adjScale);
byte _speed = map(SEGMENT.speed, 0, 255, 128, 16);

for (int x = 0; x < cols; x++) {
for (int y = 0; y < rows; y++) {
SEGENV.step++;
SEGMENT.setPixelColorXY(x, y, ColorFromPalette(auroraPalette,
qsub8(
inoise8((SEGENV.step%2) + x * _scale, y * 16 + SEGENV.step % 16, SEGENV.step / _speed),
fabsf((float)rows / 2.0f - (float)y) * adjustHeight)));
//WLEDMM add SuperSync control
uint16_t xStart, xEnd, yStart, yEnd;
if (SEGMENT.check1) { //Master (sync on needs to show the whole effect, children only their first panel)
xStart = strip.panel[0].xOffset;
xEnd = strip.panel[0].xOffset + strip.panel[0].width;
yStart = strip.panel[0].yOffset;
yEnd = strip.panel[0].yOffset + strip.panel[0].height;
}
else {
xStart = 0;
xEnd = cols;
yStart = 0;
yEnd = rows;
}

SEGENV.step = strip.now / 25 * (cols * rows); //40fps

This comment has been minimized.

Copy link
@softhack007

softhack007 Oct 8, 2023

Collaborator

@ewowi now / 25 basically creates fixed time-steps each 25ms, with nothing in between. Not sure you want that here.

if you want higher accuracy, change the line to SEGENV.step = (strip.now * cols * rows) / 25 ; //baseline 40fps
reason is integer arithmetic. (uint / 25) * a * b losses precision at the division, while doing the division as last operation preserves higher accuracy.

This comment has been minimized.

Copy link
@ewowi

ewowi Oct 8, 2023

Author

Yeah you are right, thx! I will adjust it

for (int x = xStart; x < xEnd; x++) {
for (int y = yStart; y < yEnd; y++) {
SEGENV.step++;
SEGMENT.setPixelColorXY(x, y, ColorFromPalette(auroraPalette,
qsub8(
inoise8((SEGENV.step%2) + x * _scale, y * 16 + SEGENV.step % 16, SEGENV.step / _speed),
fabsf((float)rows / 2.0f - (float)y) * adjustHeight)));
}
}

return FRAMETIME;
} // mode_2DPolarLights()
static const char _data_FX_MODE_2DPOLARLIGHTS[] PROGMEM = "Polar Lights@!,Scale;;;2";
static const char _data_FX_MODE_2DPOLARLIGHTS[] PROGMEM = "Polar Lights@!,Scale,,,,SuperSync;;;2";


/////////////////////////
Expand Down Expand Up @@ -7982,6 +7997,21 @@ uint16_t mode_2Doctopus() {
uint8_t *offsX = reinterpret_cast<uint8_t*>(SEGENV.data + dataSize);
uint8_t *offsY = reinterpret_cast<uint8_t*>(SEGENV.data + dataSize + 1);

//WLEDMM add SuperSync control
uint16_t xStart, xEnd, yStart, yEnd;
if (SEGMENT.check1) { //Master (sync on needs to show the whole effect, children only their first panel)
xStart = strip.panel[0].xOffset;
xEnd = strip.panel[0].xOffset + strip.panel[0].width;
yStart = strip.panel[0].yOffset;
yEnd = strip.panel[0].yOffset + strip.panel[0].height;
}
else {
xStart = 0;
xEnd = cols;
yStart = 0;
yEnd = rows;
}

// re-init if SEGMENT dimensions or offset changed
if (SEGENV.call == 0 || SEGENV.aux0 != cols || SEGENV.aux1 != rows || SEGMENT.custom1 != *offsX || SEGMENT.custom2 != *offsY) {
if (!true) //WLEDMM SuperSync
Expand All @@ -7992,21 +8022,21 @@ uint16_t mode_2Doctopus() {
*offsY = SEGMENT.custom2;
const uint8_t C_X = cols / 2 + (SEGMENT.custom1 - 128)*cols/255;
const uint8_t C_Y = rows / 2 + (SEGMENT.custom2 - 128)*rows/255;
for (int x = 0; x < cols; x++) {
for (int y = 0; y < rows; y++) {
for (int x = xStart; x < xEnd; x++) {
for (int y = yStart; y < yEnd; y++) {
rMap[XY(x, y)].angle = 40.7436f * atan2f(y - C_Y, x - C_X); // avoid 128*atan2()/PI
rMap[XY(x, y)].radius = hypotf(x - C_X, y - C_Y) * mapp; //thanks Sutaburosu
}
}
}

if (true) // WLEDMM SuperSync
SEGENV.step = (strip.now / 40) * (SEGMENT.speed / 32 + 1); // WLEDMM 40fps
SEGENV.step = (strip.now / 25) * (SEGMENT.speed / 32 + 1); // WLEDMM 40fps
else
SEGENV.step += SEGMENT.speed / 32 + 1; // 1-4 range

for (int x = 0; x < cols; x++) {
for (int y = 0; y < rows; y++) {
for (int x = xStart; x < xEnd; x++) {
for (int y = yStart; y < yEnd; y++) {
byte angle = rMap[XY(x,y)].angle;
byte radius = rMap[XY(x,y)].radius;
//CRGB c = CHSV(SEGENV.step / 2 - radius, 255, sin8(sin8((angle * 4 - radius) / 4 + SEGENV.step) + radius - SEGENV.step * 2 + angle * (SEGMENT.custom3/3+1)));
Expand All @@ -8018,7 +8048,7 @@ uint16_t mode_2Doctopus() {
}
return FRAMETIME;
}
static const char _data_FX_MODE_2DOCTOPUS[] PROGMEM = "Octopus@!,,Offset X,Offset Y,Legs;;!;2;";
static const char _data_FX_MODE_2DOCTOPUS[] PROGMEM = "Octopus@!,,Offset X,Offset Y,Legs, SuperSync;;!;2;";


//Waving Cell
Expand Down
2 changes: 1 addition & 1 deletion wled00/wled.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

// version code in format yymmddb (b = daily build)
#define VERSION 2310080
#define VERSION 2310081

//uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG
Expand Down

0 comments on commit 71abd11

Please sign in to comment.