Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Blur the depth buffer

  1. #1
    Junior Member Regular Contributor Kopelrativ's Avatar
    Join Date
    Apr 2011
    Posts
    214

    Blur the depth buffer

    I have a shader that does a two pass Gaussian blur on a GL_RED texture. Now I want to blur a depth buffer. Is it possible to use a FBO with the output to a depth texture in GL_COLOR_ATTACHMENT0? It didn't work when I tried.

    If this is not possible, do I have to make another blur filter, that blurs the depth instead of the pixel color?

    The purpose is to implement Exponential Shadow Maps (ESM).

    A follow-up question: I need to allocate two depth buffers, to have the blurring shader alternating outputs to use. This is a little costly, but I don't see any way around this?

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,098
    To your first question - create a texture buffer and attach it as depth buffer
    Code :
    glGenTextures(1, &c_RenderDepthTexture);
    glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, c_RenderDepthTexture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, c_Samples, GL_DEPTH24_STENCIL8, c_Width, c_Height, GL_FALSE);                
    glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D_MULTISAMPLE, c_RenderDepthTexture, 0);

    Now you have a texture to use later

    To your second question - no but you can detach one and attach another

  3. #3
    Junior Member Regular Contributor Kopelrativ's Avatar
    Join Date
    Apr 2011
    Posts
    214
    Quote Originally Posted by tonyo_au View Post
    To your first question - create a texture buffer and attach it as depth buffer
    I don't understand. If I attach it as a depth buffer, I can't use the current blur filter that blurs a color buffer, can I?

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,098
    You can't use it in the pass that you write to it - it is not a read/write buffer. You do a depth render pass then attach it as an extra texture for a colour pass.

  5. #5
    Junior Member Regular Contributor Kopelrativ's Avatar
    Join Date
    Apr 2011
    Posts
    214
    I found a solution to this. The objective was to use the same blurring shader for color textures and depth buffers. To extend the shader to also allow blurring of depth buffers, I simply added the following line in the end:
    Code :
    gl_FragDepth = fragColor.r;
    The shader still uses one input texture, which can be either a color bitmap or a depth texture. The FBO output has to be configured so as to either write to a GL_COLOR_ATTACHMENT, or write to the depth map. The extra line doesn't seem to add any performance penalty.

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,098
    Sorry I misunderstood. I thought you wanted to read an arbituary part of the depth buffer in the shader.

    either write to a GL_COLOR_ATTACHMENT, or write to the depth map

    You must write something all all attachments that exist in a fragment shader or you will get unpredictable results.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •