Skip to content

Commit

Permalink
Fix rendering of pinwheel with >8 arms
Browse files Browse the repository at this point in the history
  • Loading branch information
dkulp committed Jan 25, 2025
1 parent da8a56a commit 41d9eb4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
7 changes: 4 additions & 3 deletions xLights/effects/PinwheelEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,15 @@ void PinwheelEffect::RenderNewArms(RenderBuffer& buffer, PinwheelData &data) {
rdata.numColors = data.colorsAsColor.size();
rdata.colorarray = &data.colorarray[0];

std::vector<ispc::float3> colorsAsHSV;
colorsAsHSV.resize(rdata.numColors);
std::vector<ispc::float3> colorsAsHSV(rdata.numColors);
std::vector<uint8_t> colorIsSpacial(rdata.numColors);
for (int x = 0; x < rdata.numColors; x++) {
colorsAsHSV[x] = {(float)data.colorsAsHSV[x].hue, (float)data.colorsAsHSV[x].saturation, (float)data.colorsAsHSV[x].value};
rdata.colorIsSpacial[x] = data.colorIsSpacial[x];
colorIsSpacial[x] = data.colorIsSpacial[x] ? 1 : 0;
}
rdata.colorsAsColor = (ispc::uint8_t4*)&data.colorsAsColor[0];
rdata.colorsAsHSV = &colorsAsHSV[0];
rdata.colorIsSpacial = &colorIsSpacial[0];
rdata.bufferData = (void*)&buffer;

int max = buffer.BufferHt * buffer.BufferWi;
Expand Down
3 changes: 2 additions & 1 deletion xLights/effects/ispc/ISPCComputeUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ __ISPC_ALIGNED_STRUCT__(64) v16_varying_SpacialData {
};
#endif
extern "C" {
void getSpacialColorForGang(void *buffer, float xcenter, float ycenter, float maxradius, int active, int pc, void *d) {
uint32_t getSpacialColorForGang(void *buffer, float xcenter, float ycenter, float maxradius, int active, int pc, void *d) {
RenderBuffer *b = (RenderBuffer*)buffer;
if (pc == 8) {
v8_varying_SpacialData *data = (v8_varying_SpacialData*)d;
Expand All @@ -79,6 +79,7 @@ extern "C" {
}
}
}
return 0;
}
}

Expand Down
6 changes: 3 additions & 3 deletions xLights/effects/ispc/PinwheelFunctions.ispc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct PinwheelData {
uint32 numColors;
uint8<4> *colorsAsColor;
float<3> *colorsAsHSV;
bool colorIsSpacial[8];
uint8 *colorIsSpacial;
uint32 *colorarray;

void* bufferData;
Expand Down Expand Up @@ -120,11 +120,11 @@ export void PinwheelEffectStyle0(const uniform PinwheelData &data,
t2 = abs(t2 - (data.tmax / 2)) * 2;
int ColorIdx2 = ((int)((theta / data.degrees_per_arm))) % data.pinwheel_arms;
uint8<4> color = data.colorsAsColor[ColorIdx2];
if (data.colorIsSpacial[ColorIdx2]) {
if (data.colorIsSpacial[ColorIdx2] > 0) {
color = getSpacialColor(data.bufferData, data.colorarray[ColorIdx2],
data.xc_adj + data.width / 2,
data.yc_adj + data.height / 2,
x, y, round, data.max_radius);
x, y, round, data.max_radius);
if (!data.allowAlpha) {
hsv = data.colorsAsHSV[ColorIdx2];
}
Expand Down
2 changes: 1 addition & 1 deletion xLights/effects/ispc/PinwheelFunctions.ispc.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct PinwheelData {
uint32_t numColors;
uint8_t4 * colorsAsColor;
float3 * colorsAsHSV;
bool colorIsSpacial[8];
uint8_t * colorIsSpacial;
uint32_t * colorarray;
void * bufferData;
};
Expand Down
9 changes: 7 additions & 2 deletions xLights/effects/ispc/SpacialColors.ispc.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ struct SpacialData {
};


extern "C" uniform uint32 getSpacialColorForGang(void * uniform buffer, uniform float xcenter, uniform float ycenter, uniform float maxradius, uniform int activeLanes, uniform int programCount, SpacialData d[]);
extern "C" uniform int32 getSpacialColorForGang(void * uniform buffer, uniform float xcenter, uniform float ycenter, uniform float maxradius, uniform int activeLanes, uniform int programCount, SpacialData d[]);


inline uint8<4> getSpacialColor(void * uniform buffer, uint32 colorIdx, uniform float xcenter, uniform float ycenter, float x, float y, float r, uniform float maxradius) {
SpacialData d = { colorIdx, x, y, r, 0};
getSpacialColorForGang(buffer, xcenter, ycenter, maxradius, lanemask(), programCount, &d);
return d.result;
uint8<4> result;
result.r = (d.result & 0xFF);
result.g = ((d.result >> 8) & 0xFF);
result.b = ((d.result >> 16) & 0xFF);
result.a = ((d.result >> 24) & 0xFF);
return result;
}

0 comments on commit 41d9eb4

Please sign in to comment.