I understand that in OpenGL early depth test can be performed in the rasterizer (before running the fragment shader), but is it the same case for WebGL? If so, how is early depth test enabled in WebGL?
In my answer I relate to WebGL 2 / Opengl ES 3.0.
As far as I know
ARB_shader_image_load_store is not supported. But there is
discard available for fragment shaders in WebGL 2! So what you can do is to
- make a depth pass with a straight-forward fragment shader and
- then in a second pass test
gl_FragCoord.zagainst the value of the depth texture.
It's up to you, if it's worth the additional texture lookup and rendering the scene twice.