2018-09-30 20:48:47 +00:00
|
|
|
// Parameters
|
|
|
|
/// OBS
|
2017-07-03 05:01:23 +00:00
|
|
|
uniform float4x4 ViewProj;
|
2018-09-30 20:48:47 +00:00
|
|
|
/// Blur
|
2017-08-19 22:19:58 +00:00
|
|
|
uniform texture2d u_image;
|
|
|
|
uniform float2 u_imageSize;
|
2017-10-22 17:05:29 +00:00
|
|
|
uniform float2 u_imageTexel;
|
2017-08-19 22:19:58 +00:00
|
|
|
uniform int u_radius;
|
|
|
|
uniform int u_diameter;
|
|
|
|
uniform float2 u_texelDelta;
|
2017-07-03 05:01:23 +00:00
|
|
|
|
2018-04-28 22:14:29 +00:00
|
|
|
// Data
|
2018-09-30 20:48:47 +00:00
|
|
|
sampler_state pointSampler {
|
2017-07-03 05:01:23 +00:00
|
|
|
Filter = Point;
|
|
|
|
AddressU = Clamp;
|
|
|
|
AddressV = Clamp;
|
2018-04-28 22:14:29 +00:00
|
|
|
MinLOD = 0;
|
|
|
|
MaxLOD = 0;
|
2017-07-03 05:01:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Box Blur
|
2018-04-28 22:14:29 +00:00
|
|
|
float4 BlurFunc(float2 uv, float4 rgba) {
|
|
|
|
float4 final = rgba;
|
2017-08-19 22:19:58 +00:00
|
|
|
for (int k = 1; k <= u_radius; k++) {
|
2018-09-30 20:48:47 +00:00
|
|
|
final += u_image.SampleLevel(pointSampler, uv + (u_texelDelta * k), 0);
|
|
|
|
final += u_image.SampleLevel(pointSampler, uv - (u_texelDelta * k), 0);
|
2018-04-28 22:14:29 +00:00
|
|
|
}
|
|
|
|
return final / u_diameter;
|
|
|
|
}
|
|
|
|
|
|
|
|
float4 PSBox(VertDataOut v_in) : TARGET {
|
2018-09-30 20:48:47 +00:00
|
|
|
float4 rgba = u_image.SampleLevel(pointSampler, v_in.uv, 0);
|
2018-04-28 22:14:29 +00:00
|
|
|
return BlurFunc(v_in.uv, rgba);
|
|
|
|
}
|
|
|
|
|
2017-07-03 05:01:23 +00:00
|
|
|
technique Draw
|
|
|
|
{
|
|
|
|
pass
|
|
|
|
{
|
|
|
|
vertex_shader = VSDefault(v_in);
|
|
|
|
pixel_shader = PSBox(v_in);
|
|
|
|
}
|
|
|
|
}
|