Skip to content

Commit

Permalink
Fix some divide by 0 issues in Plasma Effect with single line buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
dkulp committed Dec 17, 2024
1 parent 0b35e7b commit 4f703f4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions xLights/effects/PlasmaEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void PlasmaEffect::Render(Effect *effect, const SettingsMap &SettingsMap, Render

int block = buffer.BufferHt * buffer.BufferWi > 100 ? 1 : -1;
parallel_for(0, buffer.BufferWi, [&] (int x) {
double rx = ((float)x / (buffer.BufferWi - 1)); // rx is now in the range 0.0 to 1.0
double rx = buffer.BufferWi <= 0 ? 0.0f : ((float)x / (buffer.BufferWi - 1)); // rx is now in the range 0.0 to 1.0
double rx2 = rx * rx;
double cx = rx + .5*sin_time_5;
double cx2 = cx*cx;
Expand All @@ -113,7 +113,7 @@ void PlasmaEffect::Render(Effect *effect, const SettingsMap &SettingsMap, Render
{
// reference: http://www.bidouille.org/prog/plasma

double ry = ((float)y/(buffer.BufferHt-1)) ;
double ry = buffer.BufferHt <= 1 ? 0.0f : ((float)y/(buffer.BufferHt-1)) ;
double v = v1;

// second equation
Expand Down
4 changes: 2 additions & 2 deletions xLights/effects/metal/PlasmaFunctions.metal
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ uchar4 plasma_getMultiColorBlend(constant PlasmaData &data, half n, bool circula
float plasmaCalc_vldpi(constant PlasmaData &data, uint32_t x, uint32_t y) {
float time = data.time;

float rx = data.width > 0 ? ((float)x / (float)(data.width - 1)) : 0.0; // rx is now in the range 0.0 to 1.0
float rx = data.width > 1 ? ((float)x / (float)(data.width - 1)) : 0.0; // rx is now in the range 0.0 to 1.0
float rx2 = rx * rx;
float cx = rx + 0.5f * data.sin_time_5;
float cx2 = cx*cx;
float sin_rx_time = sin(rx + time);

// 1st equation
float v = sin(rx * 10.0f + time);
float ry = data.height > 0 ? ((float)y/(float)(data.height - 1)) : 0;
float ry = data.height > 1 ? ((float)y/(float)(data.height - 1)) : 0;

// second equation
v += sin(10.0f*(rx*data.sin_time_2+ry*data.cos_time_3)+time);
Expand Down

0 comments on commit 4f703f4

Please sign in to comment.