GL_EXT_multisampled_render_to_texture with depth attachment

Hello,



Is it possible to mutlisample FBO with only a depth attacment. I am trying to use mutlisample FBO for shadow maps, the extension



https://www.khronos.org/registry/gles/extensions/EXT/EXT_multisampled_render_to_texture.txt



says the attachment restriction is only GL_COLOR_ATTACMENT_0



Regards,

Ganesh

The extension is written against the GLES2 spec, and according the the “framebuffer completeness” rules in the GLES2 spec, it sounds like as long as you have at least one “image” attached to the FBO (e.g. to the depth attachment), it can be complete.



GL is much the same here, requiring at least one image/attachment (though there’s an extension, ARB_framebuffer_no_attachments, that allows you to render to an FBO with “no” images/attachments).

Hello Ganesh,



In the GLES2 extension only the multi-sampled colour buffer can be resolved. The attached multi-sample depth and stencil buffers are only visible to the hardware - they will not be accessible subsequently.



This can be worked around by writing the depth values into the colour buffer. Please note that you would then need to pack the 32-bit depth value into RGBA so that interpolation works correctly when resolving to texture. I believe there would be potential precision issues with this. If you would still like to try this method, please let me know and I will explain how to pack 32-bit depth into RGBA so it can be resolved correctly.



In GLES3 the multi-sampled depth buffer can be written out but it will not be resolved. Instead it will be stored at the size of the multi-sample buffer.



Thanks,

Paul

In the GLES2 extension only the multi-sampled colour buffer can be resolved. The attached multi-sample depth and stencil buffers are only visible to the hardware - they will not be accessible subsequently.


texelFetch() in GLSL should let you access the multisample depth buffer/texture. Just bind it to a sampler2DMS and read away.
In GLES3 the multi-sampled depth buffer can be written out but it will not be resolved.


Looking through the GLES3.1 spec, it appears that it behaves like GL in that glBlitFramebuffer can downsample multisample depth texture/renderbuffers. However, "If the source formats are depth values, sample values are resolved in an implementation-dependent manner where the result will be between the minimum and maximum depth values in the pixel.

Though even then, resolving depth is of questionable utility, particularly when you don't know any more than this about how it operates.

Hello Ganesh,



Could you please confirm if you are targeting OpenGL ES 2.0?



Dark_Photon, looking at the 3.1 spec you are correct about glBlitFrameBuffer. In this case I assume Ganesh is not using 3.1 as he is using an OpenGL ES 2.0 extension - texelFetch() and glBlitFrameBuffer are not available in OpenGL ES 2.0.



Thanks,

Paul

Hello,

Sorry for the delay in replying was out of station.



I am targeting Opengl ES 2.0/3.0,



For ES 3.0+ i blit the framebuffer,

https://www.khronos.org/opengles/sdk/docs/man3/html/glBlitFramebuffer.xhtml

Looking carefully through it, i think it is not useful , since it takes GL_NEAREST,

So i will not get any Antialiasing benefits?.



Coming to texelFetch(), you mean i can bind the render buffer to a texture slot and read as normal texture, what are the performance implications of this?.More information on this could be helpful.





Packing depth into RGBA is not optimal i think mainly because.

1>RGBA samples are individually multisampled right and this may end up in wrong depth information.

2>Lose the benefit of color free rendering, thus needing to allocate extra color and enable color writes.



What i am trying to do is render to lower resolution shadow map with msaa,instead of higher resolution shadowmap, since msaa is so fast on power vr and sampling lower resolution texture is better for texture cache.





Regards,

Ganesh

Coming to texelFetch(), you mean i can bind the render buffer to a texture slot and read as normal texture, what are the performance implications of this?.More information on this could be helpful.

Close. You can't bind renderbuffers to samplers. You can bind textures. So you'd create a multisample depth texture (or depth+stencil texture), bind it to a sampler, and then you could access the individual samples of that multisample depth texture in the shader with texelFetch().

(Caveat: I haven't done this in GL-ES, but have done it in GL.)