// transformations
float4x4 View : register(c4);
float4x4 Proj : register(c8);

float3 CamPos;

float Timer;

struct VS_OUTPUT{
    float4 Pos				: POSITION;
	float Tex               : TEXCOORD0;
	float Alpha				: TEXCOORD1;
};

struct VS_INPUT{
    float3 Pos              : POSITION;
    float3 Normal			: NORMAL;
    float3 Direction		: NORMAL1;
    float StartTime			: TEXCOORD0;
    float Size				: TEXCOORD1;
    float Alpha				: TEXCOORD2;
};

VS_OUTPUT main(const VS_INPUT Input){
	float LocalTimer = Timer - Input.StartTime;
	
	float Size;
	if (LocalTimer < 1.0f){
		Size = LocalTimer * Input.Size;
	}
	else if (LocalTimer < 3){
		Size = sqrt(1.0f - ((LocalTimer - 1) / 2)) * Input.Size;
	}
	else Size = 0;

	//Size += Size * sin(LocalTimer) * 0.01f;
		
	float3 Pos = Input.Pos + Input.Normal * Size;
	
	// Compute intensity
    float3 Dir = Pos - CamPos;
    float T = dot(Dir, Input.Direction);
   
    Dir -= T * Input.Direction;
    Dir = normalize(Dir);
    
    float Color = dot(Dir, -Input.Normal);
	Color = clamp(Color, 0, 1);
	Color = pow(Color, 10);

	// Continue
	Pos = mul(float4(Pos, 1), (float4x3)View);

	VS_OUTPUT Out;
    Out.Pos = mul(float4(Pos, 1), Proj);
	Out.Tex = Color;
	Out.Alpha = Input.Alpha;
    return Out;
}