Thursday, April 11, 2013

2 Pass Gaussian Blur

2 Pass Gaussian Blur

In computer graphics you sometimes need to blur the image. Many Shader algorithms require a blur for example Bloom, SSAO, Motion Blur, Depth of Field, etc. 2 pass Gaussian blur is a simple way to blur an image. This method is better than 2D Gaussian blur and box blur as it has less texture reads and doesn't have the aliasing that box blur does. Although it does requires another FBO and FBO texture.

The algorithm is just as simple as the 2D Gaussian blur but this is only done in one dimension in stead of two. Which is why it requires two passes, one pass for vertical blur and one for horizontal blur. For the horizontal you sample the pixel colour at the fragment multiply that by a weighting. Then sample pixel to the left of that multiply that colour by a weighting and add it to the sum. Finally sample the color from the pixel to the right and multiply that by a weighting and add that to the sum. The sum is now your outColour. Take that resulting FBO texture and apply the vertical pass. For the vertical pass do the same but in a vertical fashion sampling above and below the current fragment.

Here are some sample of a 2 pass Gaussian Blur which look identical to the 2D Gaussian blur

http://vimeo.com/20226360
http://www.jhlabs.com/ip/blurring.html


No comments:

Post a Comment