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?

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.