sampler texture0 : register(s0);

float4x4 ViewTransform;
float4x4 ProjectionTransform;
float4x4 WorldTransform;

float fRelativePosition;
float2 fTextureSize;

float fShadowSize;
float2 fMaxPictureTextureSize;
float2 fStartOffset;

float4 vKenBurnsStart;
float4 vKenBurnsEnd;

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

struct PS_OUTPUT
{
    float4 RGBColor : COLOR0;
};

VS_OUTPUT vertexMain(
				float4 vPosition : POSITION,
				float2 texCoord : TEXCOORD0)
{
	VS_OUTPUT Output; 
	Output.TexCoord  = texCoord;
	
 
	float fTimeFactor1 = 10.f;
	float fTimeFactor2 = 1.f;

	float4 delta1 = vKenBurnsEnd - vKenBurnsStart;

	float t2 = saturate(saturate(fRelativePosition) * fTimeFactor2);
	float f2 = sign(t2);

	float4 delta = f2 * delta1 * t2;

		//Output.Position = Output.Position + vKenBurnsStart + delta;
		//Output.Position = Output.Position + vKenBurnsStart;
	Output.Position = vPosition + vKenBurnsStart + delta;
	Output.Position = mul(Output.Position, ViewTransform);
	Output.Position = mul(Output.Position, WorldTransform);
	Output.Position = mul(Output.Position, ProjectionTransform);

	return( Output );
}

PS_OUTPUT pixelMain(VS_OUTPUT In)
{
	PS_OUTPUT Output; 
	float2 coord = In.TexCoord + 1.f / fTextureSize / 2.f;
	Output.RGBColor  = tex2D(texture0, coord);
	return Output; 
}

PS_OUTPUT shadowMain(VS_OUTPUT In)
{
	PS_OUTPUT Output;
	float fMaxAlpha = 0.3f;

	float fFactor = 1.f;
	if (In.TexCoord.x < fStartOffset.x + fShadowSize)
		fFactor = min(fFactor, 1.f - (fStartOffset.x + fShadowSize - In.TexCoord.x + 0.01f) / fShadowSize);
	if (In.TexCoord.x > (fMaxPictureTextureSize.x - fShadowSize))
		fFactor = min(fFactor, 1.f - (In.TexCoord.x + 0.01f - (fMaxPictureTextureSize.x - fShadowSize)) / fShadowSize);
	
	if (In.TexCoord.y <  fStartOffset.y + fShadowSize)
		fFactor = min(fFactor, 1.f - (fStartOffset.y + fShadowSize - In.TexCoord.y) / fShadowSize);
	if (In.TexCoord.y > (fMaxPictureTextureSize.y - fShadowSize))
		fFactor = min(fFactor, 1.f - (In.TexCoord.y - (fMaxPictureTextureSize.y - fShadowSize)) / fShadowSize);

	Output.RGBColor.r = 0.f;
	Output.RGBColor.g = 0.f;
	Output.RGBColor.b = 0.f;
	Output.RGBColor.a = fMaxAlpha * saturate(fFactor);
	return Output; 
}