/*
   Author: Themaister
   License: Public domain
*/

// Border shader. 1x input scale, 300x280 border.

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

const float box_scale = 1.0; // 1x scale.
const float2 out_res = float2(300.0, 280.0); // Output target size.

void main_vertex
(
   float4 position : POSITION,
   out float4 oPosition : POSITION,
   uniform float4x4 modelViewProj,

   float2 tex : TEXCOORD,
   out float2 oTex : TEXCOORD,

   float2 tex_border : TEXCOORD1,
   out float2 otex_border : TEXCOORD1,

   uniform input IN
)
{
   oPosition = mul(modelViewProj, position);
   
   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;

   middle = float2(0.5, 0.5);
   float2 dist = tex_border - middle;
   otex_border = middle + dist * IN.output_size / out_res;
}

float4 main_fragment (
   float2 tex : TEXCOORD0, float2 tex_border : TEXCOORD1,
   uniform sampler2D s0 : TEXUNIT0,
   uniform sampler2D bg,
   uniform input IN) : COLOR
{
   float4 frame = tex2D(s0, tex);
   float4 background = tex2D(bg, tex_border);
   return lerp(frame, background, background.a);
}


