Jump to content
  • Advertisement
Sign in to follow this  
ramirofages

gaussian blur and linear sampling clarification

This topic is 509 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was reading several articles regarding the use of linear filter when sampling textures to optimize a gaussian blur kernel effectiveness.

Here:

https://software.intel.com/en-us/blogs/2014/07/15/an-investigation-of-fast-real-time-gpu-based-image-blur-algorithms
http://rastergrid.com/blog/2010/09/efficient-gaussian-blur-with-linear-sampling/
http://prideout.net/archive/bloom/#Sneaky

And the first thing I don't understand is the fact that they are talking as if the linear filter were taking only 2 samples when ( if I understood correctly) it should takes 4 samples, doesn't that affect the result in any way? (when performing two pass blur, first horizontally and then vertically).

[attachment=34952:three2.png]

(taken from the third link)

The other thing may be due to my lack of proper understanding of how linear filtering works, but from what I could find, linear filtering is performed first by rounding the uv position to the nearest texel, taking a sample there and then taking a sample from the right, right-bottom, and bottom texels ( the four nearest texels), as shown below.

[attachment=34951:Screenshot_4.png]

(awesomely drawn grid of texels)

So if we are sampling at the center of the grid (blue point), the returned value will be the interpolated value between all of those green rectangles (plus the filled one).

If that is correct then I don't understand the way they are calculating the offsets to sample with the kernel. I mean, why there?

[attachment=34953:three3.png]

Instead of here

[attachment=34954:three4.png]

 

I hope my explanation/questions are clear, if not please say so and I will try to draw it better :P

 

 

Share this post


Link to post
Share on other sites
Advertisement

"That means if we don’t fetch at texel center positions our texture then we can get information about multiple pixels."

Never thought of this. What happens is that if you fetch any texel with nearest filtering, you will get either the 6 pixel or the 5 pixel in your case.  If you sample 5.5, the texture filtering processors (a piece of hardware outside of your current shader), is going to take care of giving you the average between the 6 and 5 pixel. So anytime you call a texture fetch, it will be able to average 2 pixels. Which bi-linear averaging is probably free at this point because it probably comes back to the shader at the same time as point filtering.  So let it average pixels for you, and then you average together those results.

Share this post


Link to post
Share on other sites

So anytime you call a texture fetch, it will be able to average 2 pixels.

Better than that, you can do any kind of lerp / weighted average by choosing the texture coordinate carefully. 

And the first thing I don't understand is the fact that they are talking as if the linear filter were taking only 2 samples when ( if I understood correctly) it should takes 4 samples, doesn't that affect the result in any way? (when performing two pass blur, first horizontally and then vertically).

If your coordinates are perfectly in line with one row of pixels, then that row will have a weight of 1.0 and the row above/below will have a weight of 0.0. So, yes, technically you're blending 4 texels, but 2 of them are multiplied by zero, so it's as if you're only blending two pixels.

The other thing may be due to my lack of proper understanding of how linear filtering works, but from what I could find, linear filtering is performed first by rounding the uv position to the nearest texel, taking a sample there and then taking a sample from the right, right-bottom, and bottom texels ( the four nearest texels), as shown below.

That's not quite right. You blend the nearest 4 texels to the sample location.

In your diagram, the blue sample location is above the center of the center texel, so the nearest four texels, relative to your filled-green texel are right and up (not right and down).

Share this post


Link to post
Share on other sites

 

 What happens is that if you fetch any texel with nearest filtering, you will get either the 6 pixel or the 5 pixel in your case.
If you sample 5.5, the texture filtering processors are going to take care of giving you the average between the 6 and 5 pixel. So anytime you call a texture fetch, it will be able to average 2 pixels.

So wait, this is ground breaking to me. You're telling me that nearest filtering is actually able of sampling and averaging 2 pixels instead of one? What happens if you sample a point at exactly between 4 centers? Or were you talking already about linear instead of point filtering.

 

And the first thing I don't understand is the fact that they are talking as if the linear filter were taking only 2 samples when ( if I understood correctly) it should takes 4 samples, doesn't that affect the result in any way? (when performing two pass blur, first horizontally and then vertically).

If your coordinates are perfectly in line with one row of pixels, then that row will have a weight of 1.0 and the row above/below will have a weight of 0.0. So, yes, technically you're blending 4 texels, but 2 of them are multiplied by zero, so it's as if you're only blending two pixels

 

Oh, I didn't know that linear filtering was taking samples and multiplying them by a certain weight. Everything I've read always said that it took 4 samples and computed an average. So I always thought it was something like (t1+t2+t3+t4)/4.

I guess it goes along these lines then:

http://supercomputingblog.com/graphics/coding-bilinear-interpolation/
 

Thank you for your time!

Share this post


Link to post
Share on other sites

Nearest just gives you the exact texel color that is closest to your uv location. Linear will blend 4 as said, but its weighting everything by how close the sample is to any given sample. So as suggested, if vertically its dead center on a row, then the 2 pixel in that row are weighted.

Further more..... there is tri-linear filtering, which does all of this linear stuff on 2 mip maps, and then takes those 2 outputs from the linear weighting, and weights them as well.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!