Original Post
I'm trying to make a gaussian blur with a variable depth. Forgive the simple question, I searched for some time and couldn't answer... Here's my HLSL code: The problem is I would like to increase the depth without increasing the number of samples taken. I thought if I simply multiplied the pixel kernel by an amount, for example 2, it would then sample pixels 2, 4, 6, 8 etc. and give a deeper blur (eg. samp.x = Tex.x + PixelKernel * pixelWidth * 2). Instead it gives an ugly ghosting effect. How do I keep the gaussian blur nice and "soft" over a large area? Also is 13 samples a sensible amount? How would the quality of a deeper 5 sample gaussian compare? What's an easy way to determine the blur weights?
// Foreground texture
texture ForegroundTexture;
// Foreground sampler
sampler2D foreground = sampler_state {
Texture = (ForegroundTexture);
MinFilter = Point;
MagFilter = Point;
MipFilter = Point;
};
// Pixel width in texels
float pixelWidth;
float PixelKernel[13] =
{
-6,
-5,
-4,
-3,
-2,
-1,
0,
1,
2,
3,
4,
5,
6,
};
static 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,
};
// Effect function
float4 EffectProcess( float2 Tex : TEXCOORD0 ) : COLOR0
{
// Apply surrounding pixels
float4 color = 0;
float2 samp = Tex;
samp.y = Tex.y;
for (int i = 0; i < 13; i++) {
samp.x = Tex.x + PixelKernel * pixelWidth;
color += tex2D(foreground, samp.xy) * BlurWeights;
}
return color;
}
technique MyTechnique
{
pass p0
{
VertexShader = null;
PixelShader = compile ps_2_0 EffectProcess();
}
}
