/* COMPATIBILITY 
   - HLSL compilers
   - Cg   compilers
*/

void main_vertex
(
	float4 position	: POSITION,
	float4 color	: COLOR,
	float2 texCoord : TEXCOORD0,

    uniform float4x4 modelViewProj,

	out float4 oPosition : POSITION,
	out float4 oColor    : COLOR,
	out float2 otexCoord : TEXCOORD
)
{
	oPosition = mul(modelViewProj, position);
	oColor = color;
	otexCoord = texCoord;
}

struct output 
{
  float4 color    : COLOR;
};

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


// "LeiFX" shader - Gamma process
// 
// 	Copyright (C) 2013-2014 leilei
// 
// 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.


float mod2(float x, float y)
{
	return x - y * floor (x/y);
}

output main_fragment(float2 texCoord : TEXCOORD0, uniform sampler2D decal : TEXUNIT0, uniform input IN) 
{
   output OUT;
   OUT.color = tex2D(decal, texCoord);

	float2 res;
	res.x = IN.texture_size.x;
	res.y = IN.texture_size.y;

	// Gamma scanlines
	// the Voodoo drivers usually supply a 1.3 gamma setting whether people liked it or not
	// but it was enough to brainwash the competition for looking 'too dark'

	float gammaed = 0.15;

	float leifx_linegamma = gammaed;
	float2 dithet = texCoord.xy * res.xy;
	dithet.y = texCoord.y * res.y;
	float horzline1 = 	(mod2(dithet.y, 	2.0));
	if (horzline1 < 1)	leifx_linegamma = 0;
	float leifx_gamma = 1.3 - gammaed + leifx_linegamma;


	OUT.color.r = pow(OUT.color.r, 1.0 / leifx_gamma);
	OUT.color.g = pow(OUT.color.g, 1.0 / leifx_gamma);
	OUT.color.b = pow(OUT.color.b, 1.0 / leifx_gamma);

   return OUT;
}
