/* COMPATIBILITY 
   - HLSL compilers
   - Cg   compilers
*/

const float box_scale = 1.0; // 1x scale.

struct input
{
   float2 video_size;
   float2 texture_size;
   float2 output_size;
   float  frame_count;
   float  frame_direction;
   float frame_rotation;
};


/* Default Vertex shader */
void main_vertex
(
   float4 position : POSITION,
   out float4 oPosition : POSITION,
   uniform float4x4 modelViewProj,

   float4 color : COLOR,
   out float4 oColor : COLOR,

   float2 tex : TEXCOORD,
   out float2 oTex : TEXCOORD,

   uniform input IN
)
{
   oPosition = mul(modelViewProj, position);
   oColor = color;
   
   float2 scale = (IN.output_size / IN.video_size) / box_scale;
   float2 middle = 0.5 * IN.video_size / IN.texture_size;
   float2 diff = tex.xy - middle;
   oTex = middle + diff * scale;
}

struct output 
{
  float4 color    : COLOR;
};

output main_fragment( in float2 Tex : TEXCOORD0, uniform sampler2D s0 : TEXUNIT0 )
{
   float4 Color = tex2D( s0, Tex.xy );
   float Sharpenfactor = 5; //Make this between 10 and 50;

   Color -= tex2D( s0, Tex.xy+0.0001)*Sharpenfactor;
   Color += tex2D( s0, Tex.xy-0.0001)*Sharpenfactor;

   Color.a = 1.0;
   output OUT;
   OUT.color = Color;
   return OUT;
}
