/*
    Motion Blur
    Authors: hunterk, cgwg
 
    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the Free
    Software Foundation; either version 2 of the License, or (at your option)
    any later version.
*/

struct previous
{
   uniform sampler2D texture;
   float2 tex_coord;
};

struct input
{
    float2 video_size;
    float2 texture_size;
    float2 output_size;
    float frame_count;
    float frame_direction;
    float frame_rotation;
    sampler2D texture : TEXUNIT0;
};

struct tex_coords
{
   float2 tex;
   float2 prev;
   float2 prev1;
   float2 prev2;
   float2 prev3;
   float2 prev4;
   float2 prev5;
   float2 prev6;
};

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

   previous PREV,
   previous PREV1,
   previous PREV2,
   previous PREV3,
   previous PREV4,
   previous PREV5,
   previous PREV6,
   out tex_coords coords
)
{
   oPosition = mul(modelViewProj, position);
   coords = tex_coords(tex, PREV.tex_coord,
      PREV1.tex_coord,
      PREV2.tex_coord,
      PREV3.tex_coord,
      PREV4.tex_coord,
      PREV5.tex_coord,
      PREV6.tex_coord);
}

struct output 
{
  float4 col    : COLOR;
};

output main_fragment(tex_coords coords,
uniform input IN,
      previous PREV,
      previous PREV1,
      previous PREV2,
      previous PREV3,
      previous PREV4,
      previous PREV5,
      previous PREV6
)
{
   float4 color = tex2D(PREV6.texture, coords.prev6);
   color = (color + tex2D(PREV5.texture, coords.prev5)) / 2.0;
   color = (color + tex2D(PREV4.texture, coords.prev4)) / 2.0;
   color = (color + tex2D(PREV3.texture, coords.prev3)) / 2.0;
   color = (color + tex2D(PREV2.texture, coords.prev2)) / 2.0;
   color = (color + tex2D(PREV1.texture, coords.prev1)) / 2.0;
   color = (color + tex2D(PREV.texture, coords.prev)) / 2.0;
   color = (color + tex2D(IN.texture, coords.tex)) / 2.0;


   output OUT;
   OUT.col = color;
   return OUT;
}
