I'm trying to implement a gaussian blur on a Texture2D and have had trouble trying to find any good tutorials etc.
I've finally managed to find a nice piece of one-pass sample code and it visibly does blur the image a tiny bit but I want to be able to make it more blurrier and less blurrier over time and I don't know enough about how Gaussian blurring works to realise this.
I guess it must be something to do with the PixelKernel and BlurWeights but I don't really know what these values are for/what changing them does.
So my question is basically:
Is this a good way of doing Gaussian blur in HLSL/XNA? If so, how do I make the scene blurrier? As an added bonus, can you point me to a nice explanation of how Gaussian Blur works in the context of a shader?
Thanks for your time,
TS
P.S.
Just Realised I should include the code:
sampler2D Tex0;
float TintColour;
int TexHeight = 640;
int TexWidth = 480;
const int KernelSize = 7;
float2 PixelKernel[7] =
{
{-3, 0},
{-2, 0},
{-1, 0},
{0, 0},
{1, 0},
{2, 0},
{3, 0},
};
const float BlurWeights[7] =
{
0.064759,
0.120985,
0.176033,
0.199471,
0.176033,
0.120985,
0.064759,
};
struct VertexShaderOutput
{
float2 TexCoord0 : TEXCOORD0;
};
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
float4 colour = 0;
float2 TexSize = float2(1.0/TexHeight, 1.0/TexWidth);
for(int p = 0; p < 7; p++)
{
colour += tex2D(Tex0, input.TexCoord0 + (PixelKernel[p] * TexSize)) * BlurWeights[p];
}
colour.a = 1.0f;
return colour;
}
technique Technique1
{
pass Pass1
{
// TODO: set renderstates here.
PixelShader = compile ps_2_0 PixelShaderFunction();
}
}