I'm moving my sparse voxel octree code over to the GPU and have encountered something I've never had to deal with before. GLSL does not support recursive function calls. I know I can do this with a loop somehow, but my brain is not working very well today. How to structure this code to work without recursion?:
bool SVOTGetNodeColor(in uint index, in uint x, in uint y, in uint z, out vec4 diffuse, out vec3 emission)
{
//If we have hit a terminal node return the color
uint level = svotnodes[index].params[2];
if (level == maxlevels - 1)
{
diffuse = unpackRGBA(svotnodes[index].position[3]);
emission = vec3(0.0f);
return true;
}
//Check children
for (int n = 0; n < 8; ++n)
{
if (SVOTNodeContainsNode(svotnodes[index].child[n], x, y, z))
{
if (SVOTGetNodeColor(index, x, y, z, diffuse, emission)) return true;
}
}
return false;
}