#pragma parameter percent "Flicker Bright %" 0.0 0.0 1.0 0.05

#ifdef PARAMETER_UNIFORM
uniform float percent;
#else
#define percent 0.0
#endif

/* COMPATIBILITY 
   - HLSL compilers
   - Cg   compilers
*/

/*
   Flicker shader based on interlacing.cg
   Author: hunterk
   License: Public domain
   
   Note: This shader is for testing video synchronization with a 30Hz flicker applied to the image.
*/

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

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

   float4 color : COLOR,
   out float4 oColor : COLOR,

   float2 texCoord : TEXCOORD,
   out float2 oTexCoord : TEXCOORD,

   uniform input IN
)
{
   oPosition = mul(modelViewProj, position);
   oColor = color;
   oTexCoord = texCoord;
}

float4 main_fragment (in float2 texCoord : TEXCOORD, in sampler2D s0 : TEXUNIT0, uniform input IN) : COLOR
{
   float4 res = tex2D(s0, texCoord);
   float y = 0.0;

   // flicker every other frame
   y = texCoord.y + IN.frame_count;

   if (fmod(y, 2.0) > 0.99999) return res;
   else
      return float4(percent) * res;
}