texture vd_srctexture;
float4 vd_texsize;

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

void VS(
	float4 pos : POSITION,
	float2 t0 : TEXCOORD0,
	out float4 oPos : POSITION,
	out float2 oT0 : TEXCOORD0,
	out float2 oT1 : TEXCOORD1,
	out float2 oT2 : TEXCOORD2,
	out float2 oT3 : TEXCOORD3
)
{
	oPos = pos;
		
	oT0 = t0 + vd_texsize.wz * float2(-0.5, -0.5);
	oT1 = t0 + vd_texsize.wz * float2(+0.5, -0.5);
	oT2 = t0 + vd_texsize.wz * float2(-0.5, +0.5);
	oT3 = t0 + vd_texsize.wz * float2(+0.5, +0.5);
}

float4 PS(
	float2 t0 : TEXCOORD0,
	float2 t1 : TEXCOORD1,
	float2 t2 : TEXCOORD2,
	float2 t3 : TEXCOORD3
) : COLOR0
{
	float4 p0 = tex2D(src, t0);
	float4 p1 = tex2D(src, t1);
	float4 p2 = tex2D(src, t2);
	float4 p3 = tex2D(src, t3);

	const float3 luma = {0.30, 0.59, 0.11};
	float x0 = dot((p0-p3).xyz, luma);
	float x1 = dot((p1-p2).xyz, luma);

	return length(float2(x0+x1, x0-x1));
}

technique {
	pass {
		VertexShader = compile vs_1_1 VS();
		PixelShader = compile ps_2_0 PS();
	}
}
