Blur effect - why two passes?
Hi,
I have implemented a simple blur effect, as found in effects like bloom.
I am a little confused why articles talk about two passes being processed, vertical and horizontal. In my code I seem to be sampling all around the target pixel, using a gaussian distribution of weighting to creating the effect. I sample 13 times like this:
T = target pixel
X = Sampled pixel
O = not sampled pixel
OOXOO
OXXXO
XXTXX
OXXXO
OOXOO
Is this not a single pass approach?
Thanks for your advice.
Because a single pass is much slower. If you're using a separable filter kernel, 2 passes will only take O(2n) time to complete, whereas a single pass will take O(n^2).
In your case, you're sampling 13 times, all around the pixel. Instead, you could blur it once on the X axis: (5 samples per pixel)
Then blur that once more on the Y axis: (another 5 samples per pixel)
Which, for a guassian blur, will produce the exact same result.
In your case, you're sampling 13 times, all around the pixel. Instead, you could blur it once on the X axis: (5 samples per pixel)
OOOOOOOOOOXXTXXOOOOOOOOOO
Then blur that once more on the Y axis: (another 5 samples per pixel)
OOXOOOXXXOXXTXXOXXXOOOXOO
Which, for a guassian blur, will produce the exact same result.
NextWar: The Quest for Earth available now for Windows Phone 7.
While you can do a blur effect in a single pass this generally requires you to sample a lot more pixels. The articles you are refering to use a two pass approach most likely with a separable gausian blur; first only blurring in one direction and then blurring the blurred image in the other direction. For an 8x8 filter this would require 8 samples in x and 8 in y totaling in 16 samples whereas the single pass approach would need to sample 8x8 = 64 samples. So the two pass approach is generally faster.
Thank you both, this clarified things for me and now it glows nicely!
My next question: For what purpose is the downsampling commonly found in the bloom effect. The DX9 sample uses a factor of 8, but I find my bloom looks better the closer to full res the down-sampled texture is.
My next question: For what purpose is the downsampling commonly found in the bloom effect. The DX9 sample uses a factor of 8, but I find my bloom looks better the closer to full res the down-sampled texture is.
Downsampling is generally just for performance optimizations. Fewer samples means faster, no? In a dynamic situation one doesn't usually notice the lack of resolution in the blur effect, so visually it doesn't impact too much. In some cases I find it can even look a bit better.
Yep. Blurring is an expensive operation, and downsampling means that you don't have to do the operation on as many pixels. Downsampling by 8x on each side means you're dealing with 64x less pixels, which means your shader will be 64x faster. In most cases, the downsample is an acceptable tradeoff between looks and performance.
NextWar: The Quest for Earth available now for Windows Phone 7.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement