
float4x4 gWorldViewPorj: WORLDVIEWPROJECTION;

float4 gColourFactor: COLOR;

float gNumSquares;

 
struct PixelIn
{	
	float4 pos : POSITION;
	float2 texco    : TEXCOORD0;
};
 

//convert to gray scale
float4 grayScalePs(PixelIn input,
				   uniform sampler2D image ): COLOR
{
	float4 color = tex2D(image, input.texco);
	float grayValue = color.r * 0.3 + color.g * 0.59 + color.b * 0.11;
	color.rgb = grayValue;
	return color;
}

//invert color
float4 invertColorPs(PixelIn input,
				   uniform sampler2D image ): COLOR
{				
	float4 color = tex2D(image, input.texco);
	color.rgb = 1 - color.rgb;
	return color;
}

//GBSwap color, shader version can not be 1 (?)
float4 greenBlueSwapPs(PixelIn input,
				   uniform sampler2D image ): COLOR
{				
	float4 color = tex2D(image, input.texco);
	color.gb = color.bg;
	return color;
}

//square mode
float4 squareModePs(PixelIn input,
				   	    uniform sampler2D image): COLOR
{	

	float setpSize = 1/gNumSquares;   //stepSize = 1/n,  square as 0.02 * 0.02 in tex coord
	float2 fragment = float2( setpSize * floor(input.texco.x * gNumSquares), setpSize * floor(input.texco.y * gNumSquares) ); //achived by scale to n*n first, in order to use floor to round
	return tex2D(image, fragment);
}

//color factor
float4 colorFactorPs(PixelIn input,
				   	    uniform sampler2D image ): COLOR
{
	return tex2D(image, input.texco) * gColourFactor;
}



float4 mrt2Cycle(PixelIn input,
			  uniform float gTime,
			  uniform float gCycleFactor,
			  uniform sampler2D tex0,
			  uniform sampler2D tex1) : COLOR0
{
	float factor = cos(gTime * gCycleFactor)* 0.5 + 0.5;
	
	return lerp(tex2D(tex1, input.texco), tex2D(tex0, input.texco), factor );
}
 


float4 glassPS(float2 iTexCoord : TEXCOORD0,
			  uniform sampler2D RT,
			  uniform sampler2D NormalMap) : COLOR
{
	float4 normal = 2 * (tex2D(NormalMap, iTexCoord * 2.5) - 0.5);

	return tex2D(RT, iTexCoord + normal.xy * 0.05);
}