It seems hard to find information on how to access depth buffers and stencils in the shaders of successive rendering passes.
In the first rendering pass, I not only display color and depth information, but also use stencil operations to count objects. I use a multi-page target FBO for this, with color buffers and a combined depth stencil buffer. All of them are presented in the form of textures (objects of the visualization buffer are not involved).
In the second rendering session (when rendering to the screen), I want to access the previously computed stencil index per pixel (but not necessarily the same pixel that I draw), it looks like you would like to access the previously displayed color a buffer for applying some post-processing effect.
But I was not able to bind the texture of the depth of the stencil in the second pass to my shader program as a uniform. At least only black values are read from it, so I assume that it is not connected correctly.
Is it possible to link the texture of a deep stencil with a texture block for use in a shader program? Is it not possible to access the depth and texture of the stencil using "normal" samplers? Is this possible with some kind of “special” sampler? Does it depend on the interpolation mode set on the texture or similar setting?
If not, what is the best (fastest) way to copy the stencil information into a separate color texture between these two rendering passes? Maybe the third rendering step is involved, which paints one color using the stencil test (I only need the binary version of the stencil buffer in the final rendering, more precisely, I need to check if the value is equal).
The texture setting used by the intermediate FBO is as follows:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, w, h, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 0);
"" . :
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, <texture>);
glUniform1i(texLocation, 0);
:
uniform sampler2D tex;
in vec2 texCoord;
out vec4 fragColor;
void main() {
fragColor = texture2D(tex, texCoord);
}
:
<texture> , , , .
<texture> , ( , ).
24 + 8 , .