I'm creating a lightning geometry shader using hlsl that creates an array of points based on an arbitrary number of generations. The gist of what I want to accomplish is here: http://drilian.com/2009/02/25/lightning-bolts/
The problem is the fact that the pseudo-code uses a dynamic array which deletes the current generations line segment and then resizes to add new line segments. I can only use fixed sized arrays in hlsl.
My current code is as stands:
int generations = 4;
int pointsarraysize = pow(2, generations) + 1;
float3 points[pointsarraysize];
points[0] = startpoint;
points[pointsarraysize - 1] = endpoint;
for(int currentgeneration = 0; currentgeneration < genetations; ++currentgeneration)
{
for(int i = 0; i < pointsarraysize; ++i)
{
if (i == pow(2, currentgeneration))
{
}
}
}
So what i've got creates an array of the size of points I want to end up with and sets the start point and end point.
How do I fill the array so that each iteration over the array creates the points in the right place in the array? I can't simply iterate linearly and calculate points depending on the index position because calculating, for example, the first point in an array with 4 generations requires the start point point[0] and a generation 3 point, point[2].
Is this even the best way to fill the array or am I missing something that could simplify the problem? I want to be able to change the number of generations rather than hard coding a certain amount.