Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Stack for nodes that need to be processed
- // Start with root at first node
- int stack[32];
- stack[0] = 0;
- int stackptr = 0;
- int node = 0;
- do
- {
- // Fetch children and check overlap of both
- ivec2 children = ivec2 (texelFetch (Light_BVHChildrenNodes, node).rg);
- bvec2 overlap = bvec2 (IsOverlapping (children.x, depths, tilerect), IsOverlapping (children.y, depths, tilerect));
- // Increment light count for this cluster if node is a leaf
- if (overlap.x && children.x > LightCount) ++count;
- if (overlap.y && children.y > LightCount) ++count;
- // Tree needs to be traversed if the child is not a leaf and overlapping eith the cluster
- bvec2 traverse = bvec2 (overlap.x && children.x < LightCount, overlap.y && children.y < LightCount);
- if (any (traverse))
- {
- // Go on to the next child, if both childs need traversal save the other one on the stack
- node = (traverse.x) ? children.x : children.y;
- if (traverse.x && traverse.y)
- stack[++stackptr] = children.y;
- }
- else
- {
- // Children need no traversal, pop the next node from the stack
- node = stack[stackptr--];
- }
- } while (node != 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement