Can I build a bounding volume hierarchy efficiently with WebGL 2 shaders?
Is it possible to adapt the approach in this article from CUDA to WebGL 2 shaders and still be efficient?
- (1) Assign a Morton code to each primitive according to its centroid.
- Should be easy since bitwise operations (AND, OR, etc.) are available in WebGL 2 shaders.
- (2) Sort Morton codes.
- Do you think the Histopyramids based bucket / radix sort will do the trick, the most important bit in the first place? This will replace parallel radix sort on paper. Are there any other applicable sorting methods for WebGL 2? Bitonic merge (seems harder to implement)?
- (3) Construct a binary radix tree.
- Will the Histopyramid bucket / radius sort in stage 2 also be able to implicitly build the tree? Or does it take another step? For example. for pass pointers (parent and child pointers?).
- (4) Assign a bounding box to each inner node.
- Haven't thought too much about it yet. I hope that doing this from the bottom up with one shader call per level is fast enough.
Has this been done before? I couldn't find it. Any relevant links are appreciated. The closest I've found is Space Sharing - Kd-tree - Using WebGL . It creates a tree in JavaScript, but it shows you how to do stacked tree traversal in a WebGL shader. If it turns out that it is too difficult to build a BVH using shaders, I might be fine with building it in JavaScript, since the KD tree demo only uses "2ms" on 4096 elements on my machine. It would be great to zoom in though.
My goal is to do GPU collision detection for RTS play by scaling as many units and projectiles as possible. All elements are considered spherical. The BVH will be reconstructed in real time on every frame (which leaves 16ms at 60FPS, not considering other tasks). Currently I can think of three tasks:
- Element overlap dispersion.
- Target selection (closest neighbor, as units with long attack range may have too many matches).
- The use of shells for shells.
There are perhaps smarter tricks or simplifications than using BVH. Suggestions are welcome.
source to share
No one has answered this question yet
Check out similar questions: