// Basic HLSL shader
// Author : BlooV
// Date : 15.08.2011
//

float4x4 VPM    : register(c0);

// Vertex shader code
struct appdata {
       float4 Position : POSITION;
       float2 UV       : TEXCOORD0;
       float3 Normal   : NORMAL;
       float3 Tangent  : TANGENT;
       float3 Binormal : BINORMAL;
};

struct vertexOutput {
  float4	Position : POSITION;
  float2	TexCoord : TEXCOORD0;
};

vertexOutput std_VS(appdata Input){
  vertexOutput Output = (vertexOutput)0;
  Output.Position = mul(VPM, Input.Position);
  Output.TexCoord = Input.UV;
  return Output;
}

// Pixel shader code
sampler2D DiffuseMap : register( s0 );
float2    pixelSize  : register( c1 );

float4 std_PS(vertexOutput Input) : COLOR {
	float4 Output = ( 0.0, 0.0, 0.0, 1.0 );
	float2 dist   = distance( Input.TexCoord, float2( 0.5, 0.5 ) ) * pixelSize;
	float2 bcoord = Input.TexCoord;
	float2 rcoord = Input.TexCoord;
	float2 tmp    = bcoord - float2( 0.5, 0.5 );
	
	dist   *= tmp / abs( tmp );
	bcoord += dist;
	rcoord -= dist;

	Output.r = tex2D( DiffuseMap, rcoord ).r;
	Output.g = tex2D( DiffuseMap, Input.TexCoord ).g;
	Output.b = tex2D( DiffuseMap, bcoord ).b;
	
  	return Output;
}

// Compiler directives
technique main
{
  pass Pass0
  {
    VertexShader = compile vs_2_0 std_VS();
    PixelShader = compile ps_2_0 std_PS();
  }
};
