To optimize my “cascade shadow mapping” technique I am thinking of having the three depth textures that I use ( one per cascade ), in a single texture array, avoiding switching between textures when I am calculating the shadow.
So it is possible to have a FrameBuffer with a texture array as depth texture?
If so, how can I select the desired texture array layer when I am rendering the depth information of each cascade?
Thanks in advance.
You can attach one layer of a 3D texture or texture array, one face of a cube map, or one layer-face of a cube map array to a framebuffer using
Also: you can use any of those types as a layered framebuffer attachment using
glFramebufferTexture. In that case, you need to set
gl_Layer in a geometry shader to select the layer which is rendered to.
Due to the performance cost of geometry shaders, layered framebuffers should be avoided if you can reasonably render each layer in a separate pass.
Alternatively, if you have access to ARB_shader_viewport_layer_array
gl_Layer may additionally be assigned in the vertex or tessellation stages. I assume that would get rid of the performance concern since the geometry stage is no longer needed.
Thanks to your explanation I have understood, I have created 3 framebuffers ( one per cascade ) and these ones share the same texture array.
Now it works fine.
I don’t know if I agree with that. While GS’s are definitely slow, so is changing FBO state or binding new FBOs to render with. And if you’re using instanced GS’s, you can mitigate the need to re-render geometry to different layers. It’s something I’d want to profile to make sure.
Also, GL_ARB_shader_viewport_layer_array is fairly widely available these days, so you can set them from the VS.