1. I implemented Gaussian Blur and trying to turn the entire scene blurry gradually (not all of sudden)
Now I'm getting weird edges:
[attachment=30128:blur_effect.png]
Here is what I'm doing in Pixel Shader:
// Pixel Shader
const float Pixels[13] =
{
-6,
-5,
-4,
-3,
-2,
-1,
0,
1,
2,
3,
4,
5,
6
};
const float BlurWeights[13] =
{
0.002216,
0.008764,
0.026995,
0.064759,
0.120985,
0.176033,
0.199471,
0.176033,
0.120985,
0.064759,
0.026995,
0.008764,
0.002216,
};
float blur = 20.0f; // The higher the more blurry
float4 color = float4(0.0f, 0.0f, 0.0f, 1.0f);
// Horizontal
float pixelWidth = (1.0f / screenWidth) * blur;
for (int i = 0; i < 13; i++)
{
color += Tex.Sample(SampleType, IN.UV + float2(Pixels[i] * pixelWidth, 0.0f)) * BlurWeights[i];
}
// Vertical
float pixelHeight = (1.0f / screenHeight) * blur;
for (int i = 0; i < 13; i++)
{
color += Tex.Sample(SampleType, IN.UV + float2(0.0f, Pixels[i] * pixelWidth)) * BlurWeights[i];
}
return color / 2;
2. Should I do the blur effect in two different shader passes (one for Horizontal and one for Vertical) or both in one single function call like the above code?
What if I'm doing Horizontal and vertical calculation in the same Pixel Shader function, is that a good way?
3. In the above example I'm not doing any down sample, If I do down sample and the blur is not too high, I see undesired jagged edges, which make things look unrealistic when I do gradual blur.
4. In the above example the kernel size is 13, when should I increase or decrease that number?