Jump to content
  • Advertisement
Sign in to follow this  
BattleMetalChris

Dark-pass gaussian blur

This topic is 2589 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'm trying to make a shader that will apply a gaussian blur of a strength proportional to a pixel's intensity - a 'dark pass' blur.

At the moment, I'm applying a blur with a kernel size of 9 x 9, and adjusting the sigma value between 0 and a maximum value depending on the original intensity of the centre pixel. I'm having trouble with the special case where the intensity is very low or zero, which is giving me either a stupidly high value for the gaussian function or even NaN, due to the divide by zero when sigma is zero.

Is there anything else I can do other than clamp sigma to some minimum value, which seems messy and means I'm still applying *some* blur, even at tiny intensities?

Share this post


Link to post
Share on other sites
Advertisement
So you're looking for a family of 9x9 kernels with different "widths," parameterized by a single number (let's call it p, and say it ranges from 0 to 1), such that, when p=0, it's the Kronecker (not Dirac!) delta function (i.e., equals 1 at the origin and zero at all 80 other pixels in the kernel), and when p=1 it's roughly the same number at all of them. And you want something cheap to compute.

Ok...

How about we use something with finite support then -- say the "poly6 kernel" (see page 10 of this otherwise-unrelated PDF, and look for W[sub]poly6[/sub]). There, 'h' is the radius of the kernel. So how about you just use h=0.5 when p=0 (I'm assuming pixels are 1 unit apart), and h=some_constant (try 4?) when p=1. That's achieved by,

h = (1 - p)*0.5 + p*some_constant_maybe_4 .

Yes, this does involve a branch, because the poly6 kernel returns zero when r>h, but on the plus side, it otherwise only takes a few adds and muls, which I assume is cheaper than exponentials.

[EDIT: You're also going to need to modify the scaling factor in front of the poly6. The factor used in the PDF I linked to makes its integral equal to one, but that doesn't matter; we want its SAMPLES to SUM to one. So you can just drop the scaling coefficient that's in front, but then add up the coefficients you do get, and divide by their sum.]

Share this post


Link to post
Share on other sites

Is there anything else I can do other than clamp sigma to some minimum value, which seems messy and means I'm still applying *some* blur, even at tiny intensities?


You mean like this:

float sigma = ComputeSigma(color);
if(sigma >= MinSigma)
color = Blur(sigma);

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!