2017-07-03 00:46:33 +00:00
|
|
|
uniform float4x4 ViewProj;
|
|
|
|
uniform texture2d image;
|
|
|
|
uniform float2 texel;
|
2017-07-03 05:01:23 +00:00
|
|
|
uniform int widthHalf;
|
|
|
|
uniform int width;
|
2017-07-03 00:46:33 +00:00
|
|
|
|
|
|
|
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
|
2017-07-18 14:47:04 +00:00
|
|
|
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)));
|
2017-07-03 00:46:33 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 14:47:04 +00:00
|
|
|
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;
|
2017-07-03 00:46:33 +00:00
|
|
|
}
|
|
|
|
return rgba;
|
|
|
|
}
|
|
|
|
|
2017-07-03 05:01:23 +00:00
|
|
|
technique Draw
|
2017-07-03 00:46:33 +00:00
|
|
|
{
|
2017-07-03 05:01:23 +00:00
|
|
|
pass
|
2017-07-03 00:46:33 +00:00
|
|
|
{
|
|
|
|
vertex_shader = VSDefault(v_in);
|
|
|
|
pixel_shader = PSGaussian(v_in);
|
|
|
|
}
|
|
|
|
}
|