Search code examples
androidopengl-esarmdepth-buffer

OpenGL: Fetch depth on Tiled GPU with color-only fetch extension


I want to fetch depth from tile local memory with OpenGL ES.

That is needed to make soft particles effect and color-only deferred decals in a videogame. ARM_shader_framebuffer_fetch_depth_stencil extension works great and gives direct access to depth value.

Now I want to achieve same result with ARM_shader_framebuffer_fetch and EXT_shader_framebuffer_fetch. In GDC talk Bringing Fortnite to Mobile with Vulkan and OpenGL ES I see that one possible solution is writing depth value to alpha.

This approach doesn't work for me because of major precision loss, my alpha is 8 bits only. I consider adding second attachment with enough precision and writing to it with MRT.

The question is: is MRT a way to go, or I miss some important trick?


Solution

  • Implementations that support ARM_shader_framebuffer_fetch do not guarantee to support MRT at all. If they do support it, then only the color of attachment zero can be retrieved. There are also some restrictions around color format; e.g. it only supports unorm color formats, so likely cannot have enough precision for depth even if you put the depth info in attachment zero.

    Using EXT_shader_framebuffer_fetch is more generic and adds full MRT support, but not all tile-based GPUs support it.