Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Traverse the tree left node first
- // Bitfield, a bit set at position n means that the traversal at this level has to continue with its sibling node
- uint levelindex = 0;
- // Start with root
- int node = 0;
- bool setlca = true;
- do
- {
- // Process leafnodes
- if (node >= LightCount) ++count;
- //if (texelFetch (Light_BVHNodes, node).r >= LightCount) ++count;
- // Test child nodes
- else
- {
- ivec2 children = ivec2 (texelFetch (Light_BVHChildrenNodes, node).rg);
- bvec2 overlap = bvec2 (IsOverlapping (children.x, depths, tilerect), IsOverlapping (children.y, depths, tilerect));
- if (any (overlap))
- {
- // Shift levelindex because we descended on level in the tree
- levelindex <<= 1;
- // If both children need to be processed set the rightmost bit of levelindex to 1
- if (!all (overlap)) ++levelindex;
- else if (setlca)
- {
- lca = node;
- setlca = false;
- }
- // Continue with the left child if posible
- node = (overlap.x) ? children.x : children.y;
- continue;
- }
- }
- // Find the first ancestor, that has a sibling that needs to be processed
- ++levelindex;
- while ((levelindex & 1) == 0)
- {
- // Continue with the parent
- node = (node >= LightCount) ? int (texelFetch (Light_BVHParentLeafs, node - LightCount).r) : int (texelFetch (Light_BVHParentNodes, node).r);
- levelindex >>= 1;
- }
- // Continue with the sibling of the current node
- if (node != 0)
- {
- node = (node >= LightCount) ? int (texelFetch (Light_BVHParentLeafs, node - LightCount).r) : int (texelFetch (Light_BVHParentNodes, node).r);
- node = int (texelFetch (Light_BVHChildrenNodes, node).g);
- }
- } while (node != 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement