Depth buffer blur in OpenGL - how to access mipmap levels in a fragment shader?

I am trying to blur the depth texture by blurring and mixing the mipmap levels in the fragment shader.

I have two framebuffer objects:
1) Color framebuffer with attached depth image.
2) Z paper with depth texture.

As soon as I draw the scene to the color framebuffer object, I then blit to the depth buffer object and can successfully do this (the output is the GL_LUMINANCE depth texture).

I can successfully access any given mipmap level by selecting it before drawing the depth buffer, for example, I can display the mipmap 3 level as follows:

// FBO setup - all buffer objects created successfully and are complete and the color // framebuffer has been rendered to (it has a depth renderbuffer attached), and no // OpenGL errors are issued: glBindFramebuffer(GL_READ_FRAMEBUFFER, _fbo_color); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _fbo_z); glBlitFramebuffer(0,0,_w, _h, 0, 0, _w, _h, GL_DEPTH_BUFFER_BIT, GL_NEAREST); glGenerateMipmap(GL_TEXTURE_2D); glBindFramebuffer(GL_FRAMEBUFFER, 0); // This works: // Select mipmap level 3 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 3); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 3); draw_depth_texture_on_screen_aligned_quad(); // Reset mipmap glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1000); 

Alternatively, I would like to add an offset parameter to the GLSL function texture2D () or use texture2DLod () and work with a single texture sampler, but whenever I select a level above 0, mipmap was not generated:

 // fragment shader (Both texture2DLod and texture2D(sampler, tcoord, bias) // are behaving the same. uniform sampler2D zbuffer; uniform int mipmap_level; void main() { gl_FragColor = texture2DLod(zbuffer, gl_TexCoord[0].st, float(mipmap_level)); } 

I'm not sure how mipmapping works with glBlitFramebuffer (), but my question is how to properly configure the program so that calls made in texture2D / texture2DLod give the expected results?

Thanks Dennis

+3
opengl mipmaps fragment-shader framebuffer
source share
1 answer

Good - I think I did it ... My depth buffer did not have mipmap levels generated. I use a lot of texturing, and during rendering I activate texture 1 for the texture of the color frame and texture block 1 for the texture of the depth buffer. When I activate / link textures, I call glGenerateMipmap (GL_TEXTURE_2D) as follows:

 glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_2D, _color_texture); glGenerateMipmap(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE1_ARB); glBindTexture(GL_TEXTURE_2D, _zbuffer_texture); glGenerateMipmap(GL_TEXTURE_2D); 

When this is done, increasing the offset in texture2D (sampler, coordination, offset) gives fragments from the mipmap level as expected.

+3
source share

All Articles