uniform float4x4 ViewProj; uniform texture2d image; uniform float2 texel; uniform int widthHalf; uniform int width; sampler_state textureSampler { Filter = Point; AddressU = Clamp; AddressV = Clamp; }; struct VertDataIn { float4 pos : POSITION; float2 uv : TEXCOORD0; }; struct VertDataOut { float4 pos : POSITION; float2 uv : TEXCOORD0; }; VertDataOut VSDefault(VertDataIn v_in) { VertDataOut vert_out; vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj); vert_out.uv = v_in.uv; return vert_out; } // Gaussian Blur float Gaussian(float x, float o) { const float pivalue = 3.1415926535897932384626433832795; return (1.0 / (o * sqrt(2.0 * pivalue))) * exp((-(x * x)) / (2 * (o * o))); } float4 PSGaussian(VertDataOut v_in) : TARGET { const float pivalue = 3.1415926535897932384626433832795; float4 rgba = image.Sample(textureSampler, v_in.uv) * Gaussian(0, width / pivalue); float2 uvoffset = texel; for (int k = 1; k <= widthHalf; k++) { float g = Gaussian(k, width / pivalue); float4 spos = image.Sample(textureSampler, v_in.uv + uvoffset) * g; float4 sneg = image.Sample(textureSampler, v_in.uv - uvoffset) * g; rgba += spos + sneg; uvoffset += texel; } return rgba; } technique Draw { pass { vertex_shader = VSDefault(v_in); pixel_shader = PSGaussian(v_in); } }