Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2014
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. // Stack for nodes that need to be processed
  2. // Start with root at first node
  3. int stack[32];
  4. stack[0] = 0;
  5.  
  6. int stackptr = 0;
  7. int node = 0;
  8.  
  9. do
  10. {
  11.     // Fetch children and check overlap of both
  12.     ivec2 children = ivec2 (texelFetch (Light_BVHChildrenNodes, node).rg);
  13.     bvec2 overlap = bvec2 (IsOverlapping (children.x, depths, tilerect), IsOverlapping (children.y, depths, tilerect));
  14.  
  15.     // Increment light count for this cluster if node is a leaf
  16.     if (overlap.x && children.x > LightCount) ++count;
  17.     if (overlap.y && children.y > LightCount) ++count;
  18.  
  19.     // Tree needs to be traversed if the child is not a leaf and overlapping eith the cluster
  20.     bvec2 traverse = bvec2 (overlap.x && children.x < LightCount, overlap.y && children.y < LightCount);
  21.     if (any (traverse))
  22.     {
  23.         // Go on to the next child, if both childs need traversal save the other one on the stack
  24.         node = (traverse.x) ? children.x : children.y;
  25.         if (traverse.x && traverse.y)
  26.             stack[++stackptr] = children.y;
  27.     }
  28.     else
  29.     {
  30.         // Children need no traversal, pop the next node from the stack
  31.         node = stack[stackptr--];
  32.     }
  33. } while (node != 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement