sampler texture0 : register(s0);
sampler texture1 : register(s1);

float4x4 WorldViewProjectionTransform  : WORLDVIEWPROJ;
float2 fTextureSize;
float fRelativePosition;

struct VS_OUTPUT 
{
   float4 Position  : POSITION;
   float2 TexCoord  : TEXCOORD0;
};

struct PS_OUTPUT
{
    float4 RGBColor : COLOR0;  // Pixel color    
};

VS_OUTPUT vertexMain(
				float4 vPosition : POSITION,
				float2 texCoord : TEXCOORD0)
{
	VS_OUTPUT Output; 

	Output.Position = mul(vPosition, WorldViewProjectionTransform);
	Output.TexCoord = texCoord;
	return Output;
}

PS_OUTPUT pixelMain(VS_OUTPUT In)
{
	float2 coord = In.TexCoord + 1.f / fTextureSize / 2.f;

	float4 fFadeToColor;
	fFadeToColor.a = 1.f;
	fFadeToColor.r = 1.f;
	fFadeToColor.g = 1.f;
	fFadeToColor.b = 1.f;

	float fInFactor = 1.f - saturate(fRelativePosition / 0.5f);
	float fOutFactor = saturate((fRelativePosition - 0.5f) / 0.5f);

	float4 px0 = tex2D(texture0, coord);
	float4 px1 = tex2D(texture1, coord);
	
	float fFirstPixel = step(fRelativePosition, 0.5f);
	float fFirstPixelInv = 1.f - fFirstPixel;
	float4 result = lerp(fFadeToColor, px0, fInFactor) * fFirstPixel + lerp(fFadeToColor, px1, fOutFactor) * fFirstPixelInv;

	PS_OUTPUT output;
	output.RGBColor = result;
	output.RGBColor.a = 1.f;

	return output;
}