2017-08-19 22:19:58 +00:00
|
|
|
// OBS Default
|
2017-07-03 00:46:33 +00:00
|
|
|
uniform float4x4 ViewProj;
|
|
|
|
|
2017-08-19 22:19:58 +00:00
|
|
|
// Settings (Shared)
|
|
|
|
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;
|
|
|
|
|
|
|
|
// Settings (Private)
|
|
|
|
//uniform float registerkernel[25];
|
|
|
|
uniform texture2d kernel;
|
|
|
|
uniform float2 kernelTexel;
|
|
|
|
|
|
|
|
sampler_state pointClampSampler {
|
2017-07-03 00:46:33 +00:00
|
|
|
Filter = Point;
|
|
|
|
AddressU = Clamp;
|
|
|
|
AddressV = Clamp;
|
2017-08-19 22:19:58 +00:00
|
|
|
MinLOD = 0;
|
|
|
|
MaxLOD = 0;
|
|
|
|
};
|
|
|
|
sampler_state bilinearClampSampler {
|
|
|
|
Filter = Bilinear;
|
|
|
|
AddressU = Clamp;
|
|
|
|
AddressV = Clamp;
|
|
|
|
MinLOD = 0;
|
|
|
|
MaxLOD = 0;
|
2017-07-03 00:46:33 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-10-22 17:05:29 +00:00
|
|
|
float4 InternalGaussian(float2 p_uv, float2 p_uvStep, int p_radius,
|
|
|
|
texture2d p_image, float2 p_imageTexel) {
|
2017-08-19 22:19:58 +00:00
|
|
|
float l_gauss = Gaussian(0, p_size);
|
2017-10-22 17:05:29 +00:00
|
|
|
float4 l_value = p_image.Sample(pointClampSampler, p_uv) * gauss;
|
|
|
|
float2 l_uvoffset = float2(0, 0);
|
2017-08-19 22:19:58 +00:00
|
|
|
for (int k = 1; k <= p_size; k++) {
|
2017-10-22 17:05:29 +00:00
|
|
|
l_uvoffset += p_uvStep;
|
2017-08-19 22:19:58 +00:00
|
|
|
float l_g = Gaussian(k, p_size);
|
2017-10-22 17:05:29 +00:00
|
|
|
float4 l_p = p_image.Sample(pointClampSampler, p_uv + l_uvoffset) * l_g;
|
|
|
|
float4 l_n = p_image.Sample(pointClampSampler, p_uv - l_uvoffset) * l_g;
|
2017-08-19 22:19:58 +00:00
|
|
|
l_value += l_p + l_n;
|
|
|
|
l_gauss += l_g;
|
|
|
|
}
|
|
|
|
l_value = l_value * (1.0 / l_gauss);
|
|
|
|
return l_value;
|
|
|
|
}
|
|
|
|
|
2017-10-22 17:05:29 +00:00
|
|
|
float4 InternalGaussianPrecalculated(float2 p_uv, float2 p_uvStep, int p_radius,
|
|
|
|
texture2d p_image, float2 p_imageTexel,
|
|
|
|
texture2d p_kernel, float2 p_kernelTexel) {
|
|
|
|
float4 l_value = p_image.Sample(pointClampSampler, p_uv)
|
2017-08-19 22:19:58 +00:00
|
|
|
* kernel.Sample(pointClampSampler, float2(0, 0)).r;
|
2017-10-22 17:05:29 +00:00
|
|
|
float2 l_uvoffset = float2(0, 0);
|
|
|
|
for (int k = 1; k <= p_radius; k++) {
|
2017-08-19 22:19:58 +00:00
|
|
|
l_uvoffset += p_uvStep;
|
2017-10-22 17:05:29 +00:00
|
|
|
float l_g = p_kernel.Sample(pointClampSampler, p_kernelTexel * k).r;
|
|
|
|
float4 l_p = p_image.Sample(pointClampSampler, p_uv + l_uvoffset) * l_g;
|
|
|
|
float4 l_n = p_image.Sample(pointClampSampler, p_uv - l_uvoffset) * l_g;
|
|
|
|
l_value += l_p + l_n;
|
2017-08-19 22:19:58 +00:00
|
|
|
}
|
|
|
|
return l_value;
|
|
|
|
}
|
|
|
|
|
2017-10-22 17:05:29 +00:00
|
|
|
/*float4 InternalGaussianPrecalculatedNVOptimized(float2 p_uv, int p_size,
|
|
|
|
texture2d p_image, float2 p_imageTexel,
|
|
|
|
texture2d p_kernel, float2 p_kernelTexel) {
|
2017-08-19 22:19:58 +00:00
|
|
|
if (p_size % 2 == 0) {
|
2017-10-22 17:05:29 +00:00
|
|
|
float4 l_value = p_image.Sample(pointClampSampler, p_uv)
|
2017-08-19 22:19:58 +00:00
|
|
|
* kernel.Sample(pointClampSampler, float2(0, 0)).r;
|
|
|
|
float2 l_uvoffset = p_texel;
|
2017-10-22 17:05:29 +00:00
|
|
|
float2 l_koffset = p_kernelTexel;
|
2017-08-19 22:19:58 +00:00
|
|
|
for (int k = 1; k <= p_size; k++) {
|
|
|
|
float l_g = p_kernel.Sample(pointClampSampler, l_koffset).r;
|
2017-10-22 17:05:29 +00:00
|
|
|
float4 l_p = p_image.Sample(pointClampSampler, p_uv + l_uvoffset) * l_g;
|
|
|
|
float4 l_n = p_image.Sample(pointClampSampler, p_uv - l_uvoffset) * l_g;
|
2017-08-19 22:19:58 +00:00
|
|
|
l_value += l_p + l_n;
|
|
|
|
l_uvoffset += p_texel;
|
2017-10-22 17:05:29 +00:00
|
|
|
l_koffset += p_kernelTexel;
|
2017-08-19 22:19:58 +00:00
|
|
|
}
|
|
|
|
return l_value;
|
|
|
|
} else {
|
2017-10-22 17:05:29 +00:00
|
|
|
return InternalGaussianPrecalculated(p_uv, p_image, p_texel, p_size, p_kernel, p_kerneltexel);)
|
2017-07-03 00:46:33 +00:00
|
|
|
}
|
2017-10-22 17:05:29 +00:00
|
|
|
}*/
|
2017-08-19 22:19:58 +00:00
|
|
|
|
|
|
|
float4 PSGaussian(VertDataOut v_in) : TARGET {
|
2017-10-22 17:05:29 +00:00
|
|
|
//return InternalGaussian(v_in.uv, u_texelDelta, u_image, u_imageTexel, u_radius);
|
|
|
|
|
|
|
|
///*
|
|
|
|
return InternalGaussianPrecalculated(
|
|
|
|
v_in.uv, u_texelDelta, u_radius,
|
|
|
|
u_image, u_imageTexel,
|
|
|
|
kernel, kernelTexel);//*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
return InternalGaussianPrecalculatedNVOptimize(
|
|
|
|
v_in.uv, u_texelDelta, u_radius,
|
|
|
|
u_image, u_imageTexel,
|
|
|
|
kernel, kernelTexel);//*/
|
2017-07-03 00:46:33 +00:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|