2017-08-19 22:19:58 +00:00
|
|
|
// OBS Default
|
2017-07-03 05:20:15 +00:00
|
|
|
uniform float4x4 ViewProj;
|
2017-08-19 22:19:58 +00:00
|
|
|
|
|
|
|
// Settings (Shared)
|
|
|
|
uniform texture2d u_image;
|
|
|
|
uniform float2 u_imageSize;
|
|
|
|
uniform float2 u_imageTexelDelta;
|
|
|
|
uniform int u_radius;
|
|
|
|
uniform int u_diameter;
|
|
|
|
uniform float2 u_texelDelta;
|
|
|
|
|
|
|
|
// Settings (Private)
|
2017-07-03 05:20:15 +00:00
|
|
|
uniform float bilateralSmoothing;
|
|
|
|
uniform float bilateralSharpness;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bilateral Blur
|
|
|
|
float Bilateral(float x, float sigma)
|
|
|
|
{
|
|
|
|
return 0.39894 * exp(-0.5 * (x*x) / (sigma*sigma)) / sigma;
|
|
|
|
}
|
|
|
|
|
|
|
|
float Bilateral3(float3 v, float sigma)
|
|
|
|
{
|
|
|
|
return 0.39894 * exp(-0.5 * dot(v,v) / (sigma*sigma)) / sigma;
|
|
|
|
}
|
|
|
|
|
|
|
|
float4 PSBilateral(VertDataOut v_in) : TARGET
|
|
|
|
{
|
2017-08-19 22:19:58 +00:00
|
|
|
float4 source = image.Sample(textureSampler, v_in.uv);
|
|
|
|
|
2017-07-03 05:20:15 +00:00
|
|
|
float3 color = float3(0, 0, 0);
|
|
|
|
float2 rootuv = v_in.uv - (texel * widthHalf);
|
|
|
|
float Z = 0.0;
|
|
|
|
float bZ = 1.0 / Bilateral(0.0, bilateralSharpness);
|
|
|
|
for (int k = -widthHalf; k <= widthHalf; k++) {
|
|
|
|
// Sample Color
|
|
|
|
float3 sample = image.Sample(textureSampler, rootuv);
|
2017-08-19 22:19:58 +00:00
|
|
|
|
2017-07-03 05:20:15 +00:00
|
|
|
// Bilateral Stuff
|
|
|
|
float bKernel = Bilateral(abs(k), bilateralSmoothing);
|
2017-08-19 22:19:58 +00:00
|
|
|
bKernel *= bKernel;
|
2017-07-03 05:20:15 +00:00
|
|
|
float factor = Bilateral3(sample - source.rgb, bilateralSharpness) * bZ * bKernel;
|
|
|
|
Z += factor;
|
2017-08-19 22:19:58 +00:00
|
|
|
|
2017-07-03 05:20:15 +00:00
|
|
|
// Store Color
|
|
|
|
color += factor * sample;
|
2017-08-19 22:19:58 +00:00
|
|
|
|
2017-07-03 05:20:15 +00:00
|
|
|
// Advance UV
|
|
|
|
rootuv += texel;
|
|
|
|
}
|
2017-08-19 22:19:58 +00:00
|
|
|
|
2017-07-03 05:20:15 +00:00
|
|
|
return float4(color.rgb / Z, source.a);
|
|
|
|
}
|
|
|
|
|
|
|
|
technique Draw
|
|
|
|
{
|
|
|
|
pass
|
|
|
|
{
|
|
|
|
vertex_shader = VSDefault(v_in);
|
|
|
|
pixel_shader = PSBilateral(v_in);
|
|
|
|
}
|
|
|
|
}
|