texture vd_srctexture;
float4 vd_texsize;

sampler src = sampler_state {
	Texture = <vd_srctexture>;
	AddressU = clamp;
	AddressV = clamp;
	MinFilter = Linear;
	MagFilter = Linear;
	MipFilter = None;
};

float2 taps[24]={
	{ -2, -2 },
	{ -1, -2 },
	{  0, -2 },
	{  1, -2 },
	{  2, -2 },
	{ -2, -1 },
	{ -1, -1 },
	{  0, -1 },
	{  1, -1 },
	{  2, -1 },
	{ -2,  0 },
	{ -1,  0 },
	{  1,  0 },
	{  2,  0 },
	{ -2,  1 },
	{ -1,  1 },
	{  0,  1 },
	{  1,  1 },
	{  2,  1 },
	{ -2,  2 },
	{ -1,  2 },
	{  0,  2 },
	{  1,  2 },
	{  2,  2 },
};

void VS(
	float4 pos : POSITION,
	float2 t0 : TEXCOORD0,
	out float4 oPos : POSITION,
	out float2 oT0 : TEXCOORD0
)
{
	oPos = pos;
	oT0 = t0;
}
 
float getweight(float3 diff) {
//	return saturate(1.0 - 200.0*dot(diff, diff));
//	return saturate(1.0 - 50.0*dot(diff, diff));
	return saturate(1.0 - 5.0*length(diff));
}

float4 PS(
	float2 t0 : TEXCOORD0,
	float2 t1 : TEXCOORD1,
	float2 t2 : TEXCOORD2,
	float2 t3 : TEXCOORD3,
	float2 t4 : TEXCOORD4
) : COLOR0
{
	float4 p0 = float4(tex2D(src, t0).xyz, 1);
	float w = 1;//getweight(0);
	float4 sum = p0*w;

	for(int i=0; i<24; ++i) {
		float4 p = float4(tex2D(src, t0 + taps[i]*vd_texsize.wz).xyz, 1);
		float4 d = getweight((p - p0).xyz);

		sum += p*d;
	}

	return sum / sum.a;
}

technique {
	pass {
		VertexShader = compile vs_2_0 VS();
		PixelShader = compile ps_2_a PS();
	}
}
