Jump to content
  • Advertisement
Sign in to follow this  
NiGoea

Bilateral Filtering

This topic is 3204 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

For those of you who've implemented bilateral filtering (in my case for SSAO), I would like to ask about the implementation. Particularly, what weight function do you use to sum values ? Do you use a linear or kind of a 'step' function ? When used for SSAO, do you think it worth using it ? I've tried some implementations, but it's hard to find a good one. It is not a problem of speed, but a problem of final result. THANKS

Share this post


Link to post
Share on other sites
Advertisement
In my case i use a simple box filter, sum the values together then divide by the number of samples.

I think it is more important how you distribute you samples in SSAO that the filtering you apply afterwards. There is a thing called "importance sampling" that might be well suited for this.
Anyway, i spent ages creating several random-sampling textures and using several methods for the SSAO sampling until i got it right (at least for my taste). It´s just a matter of tinkering around.

Share this post


Link to post
Share on other sites
Ok, but with a "box-filter" like your, also the edges that have only a side shadowed (so that the edge should be shadowed in part), will end up totally darker.
Bilinear filter preserves that.
Anyway, in most of the cases the effect of a non-bilinear filter is negligible, expecially if you use a big SSAO buffer (this is not my case, because I use a 4 down sized buffer).

Anyway, mr. ArKano22, I would like to ask you about the frame drop of your SSAO.
Right now I'm using well distributed 8 samples per pixel, exploiting the normal buffer. When I turn of the SSAO, I go from 100+ fps to 60.
What is you case?

thanks !!

Share this post


Link to post
Share on other sites
To do a proper bilateral filter, you need two weight function: one relative to pixel distance, e.g a gaussian, and one relative to z difference to preserve edge. You can also use a weight function related to normals similartiy but usually z difference is sufficient to preserve edge properly.

Here is the glsl code I used for my bilateral filter:

vec4 bilateralFilter() {
vec4 color = vec4(0.0);
vec2 center = gl_TexCoord[0].xy;
vec2 sample;
float sum = 0.0;
float coefG,coefZ,finalCoef;
float Zp = getDepth(center);

const float epsilon = 0.01;

for(int i = -(kernelSize-1)/2; i <= (kernelSize-1)/2; i++) {
for(int j = -(kernelSize-1)/2; j <= (kernelSize-1)/2; j++) {
sample = center + vec2(i,j) / texSize;
coefG = gaussianCoef(i,j);
float zTmp = getDepth(sample);
coefZ = 1.0 / (epsilon + abs(Zp - zTmp));
finalCoef = coefG * coefZ;
sum += finalCoef;
color += finalCoef * texture2D(AOTex,sample);
}
}

return color / sum;
}

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!