Stencil buffer from transparent texture for occlusion query

78 views Asked by At

I am trying to implement something like https://shawnhargreaves.com/blog/pixel-perfect-collision-detection-using-gpu-occlusion-queries.html on webgl

The issue I'm running into appears to be that I cannot create a stencil from just the non-transparent pixels. I've tried various approaches - stencilOp comparison operators, discard, and so on.

Is this simply impossible to do on WebGL, because it would require ALPHA_TEST, and discard is too late? Or is there some way to get stencil buffer data from non-transparent pixels and then use only that for occlusion queries?

I know we're supposed to be focused on just very specific questions here - but if there's a way of doing pixel-perfect 2d collisions in webgl based on just the texture data, not creating hulls or hitboxes or other geometry-based tests, I'm open to ideas! :)

Related: https://stackoverflow.com/a/51226566/784519

0

There are 0 answers