2020-01-02 02:41:43 +00:00
|
|
|
//
|
|
|
|
// File: foldhaus_default_nodes.h
|
|
|
|
// Author: Peter Slattery
|
|
|
|
// Creation Date: 2020-01-01
|
|
|
|
//
|
|
|
|
#ifndef FOLDHAUS_DEFAULT_NODES_H
|
|
|
|
|
2019-08-18 12:56:18 +00:00
|
|
|
//////////////////////////////////
|
|
|
|
//
|
|
|
|
// Values
|
|
|
|
//
|
|
|
|
/////////////////////////////////
|
|
|
|
|
|
|
|
NODE_STRUCT(float_value_data)
|
|
|
|
{
|
|
|
|
NODE_IN(r32, Value);
|
|
|
|
NODE_OUT(r32, Result);
|
|
|
|
};
|
|
|
|
|
|
|
|
NODE_PROC(FloatValue, float_value_data)
|
|
|
|
{
|
|
|
|
Data->Result = Data->Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
NODE_STRUCT(vector_data)
|
|
|
|
{
|
|
|
|
NODE_IN(r32, X);
|
|
|
|
NODE_IN(r32, Y);
|
|
|
|
NODE_IN(r32, Z);
|
|
|
|
NODE_IN(r32, W);
|
|
|
|
NODE_OUT(v4, Result);
|
|
|
|
};
|
|
|
|
|
|
|
|
NODE_PROC(VectorValue, vector_data)
|
|
|
|
{
|
|
|
|
Data->Result = v4{Data->X, Data->Y, Data->Z, Data->W};
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////
|
|
|
|
//
|
|
|
|
// Arithmetic
|
|
|
|
//
|
|
|
|
/////////////////////////////////
|
|
|
|
|
|
|
|
NODE_STRUCT(multiply_data)
|
|
|
|
{
|
|
|
|
NODE_IN(r32, A);
|
|
|
|
NODE_IN(r32, B);
|
|
|
|
NODE_OUT(r32, Result);
|
|
|
|
};
|
|
|
|
|
|
|
|
NODE_PROC(MultiplyNodeProc, multiply_data)
|
|
|
|
{
|
|
|
|
Data->Result = Data->A * Data->B;
|
|
|
|
}
|
|
|
|
|
|
|
|
NODE_STRUCT(add_data)
|
|
|
|
{
|
|
|
|
NODE_IN(v4, A);
|
|
|
|
NODE_IN(v4, B);
|
|
|
|
NODE_OUT(v4, Result);
|
|
|
|
};
|
|
|
|
|
|
|
|
NODE_PROC(AddNodeProc, add_data)
|
|
|
|
{
|
|
|
|
Data->Result = Data->A + Data->B;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////
|
|
|
|
//
|
|
|
|
// Animators
|
|
|
|
//
|
|
|
|
/////////////////////////////////
|
|
|
|
|
2020-01-19 12:03:07 +00:00
|
|
|
GSMetaTag(node_struct);
|
|
|
|
struct sin_wave_data
|
2019-08-18 12:56:18 +00:00
|
|
|
{
|
2020-01-19 12:03:07 +00:00
|
|
|
GSMetaTag(node_input);
|
|
|
|
r32 Period;
|
|
|
|
|
|
|
|
GSMetaTag(node_input);
|
|
|
|
r32 Min;
|
|
|
|
|
|
|
|
GSMetaTag(node_input);
|
|
|
|
r32 Max;
|
|
|
|
|
|
|
|
GSMetaTag(node_input);
|
|
|
|
r32 Result;
|
2019-08-18 12:56:18 +00:00
|
|
|
|
|
|
|
r32 Accumulator;
|
|
|
|
};
|
|
|
|
|
|
|
|
NODE_PROC(SinWave, sin_wave_data)
|
|
|
|
{
|
|
|
|
Data->Accumulator += DeltaTime;
|
|
|
|
if (Data->Period > 0)
|
|
|
|
{
|
|
|
|
while (Data->Accumulator > Data->Period)
|
|
|
|
{
|
|
|
|
Data->Accumulator -= Data->Period;
|
|
|
|
}
|
|
|
|
|
|
|
|
r32 ActualMin = GSMin(Data->Min, Data->Max);
|
|
|
|
r32 ActualMax = GSMax(Data->Min, Data->Max);
|
|
|
|
r32 SinResult = GSSin((Data->Accumulator / Data->Period) * PI * 2);
|
|
|
|
Data->Result = GSRemap(SinResult, -1.f, 1.f, ActualMin, ActualMax);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Data->Result = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////
|
|
|
|
//
|
|
|
|
// Pattern Mixing
|
|
|
|
//
|
|
|
|
/////////////////////////////////
|
|
|
|
|
2020-01-19 12:03:07 +00:00
|
|
|
GSMetaTag(node_struct);
|
|
|
|
struct multiply_patterns_data
|
2019-08-18 12:56:18 +00:00
|
|
|
{
|
2020-01-19 12:03:07 +00:00
|
|
|
GSMetaTag(node_input);
|
|
|
|
color_buffer A;
|
|
|
|
|
|
|
|
GSMetaTag(node_input);
|
|
|
|
color_buffer B;
|
|
|
|
|
|
|
|
GSMetaTag(node_output);
|
|
|
|
color_buffer Result;
|
2019-08-18 12:56:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
NODE_PROC(MultiplyPatterns, multiply_patterns_data)
|
|
|
|
{
|
2020-01-19 12:03:07 +00:00
|
|
|
led* LED = Data->Result.LEDs;
|
|
|
|
for (s32 l = 0; l < Data->Result.LEDCount; l++)
|
2019-08-18 12:56:18 +00:00
|
|
|
{
|
2020-01-19 12:03:07 +00:00
|
|
|
Assert(LED->Index >= 0 && LED->Index < Data->Result.LEDCount);
|
2019-08-18 12:56:18 +00:00
|
|
|
|
2020-01-19 12:03:07 +00:00
|
|
|
s32 AR = Data->A.Colors[LED->Index].R;
|
|
|
|
s32 AG = Data->A.Colors[LED->Index].G;
|
|
|
|
s32 AB = Data->A.Colors[LED->Index].B;
|
2019-08-18 12:56:18 +00:00
|
|
|
|
2020-01-19 12:03:07 +00:00
|
|
|
s32 BR = Data->B.Colors[LED->Index].R;
|
|
|
|
s32 BG = Data->B.Colors[LED->Index].G;
|
|
|
|
s32 BB = Data->B.Colors[LED->Index].B;
|
2019-08-18 12:56:18 +00:00
|
|
|
|
|
|
|
s32 RCombined = (AR * BR) / 255;
|
|
|
|
s32 GCombined = (AG * BG) / 255;
|
|
|
|
s32 BCombined = (AB * BB) / 255;
|
|
|
|
|
2020-01-19 12:03:07 +00:00
|
|
|
Data->Result.Colors[LED->Index].R = (u8)RCombined;
|
|
|
|
Data->Result.Colors[LED->Index].G = (u8)GCombined;
|
|
|
|
Data->Result.Colors[LED->Index].B = (u8)BCombined;
|
2019-08-18 12:56:18 +00:00
|
|
|
|
|
|
|
LED++;
|
|
|
|
}
|
|
|
|
}
|
2020-01-02 02:41:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define FOLDHAUS_DEFAULT_NODES_H
|
|
|
|
#endif // FOLDHAUS_DEFAULT_NODES_H
|