uniform vec3 Right, Up;
varying vec2 TexCoord;
varying vec4 Clr;

void main()
{
	vec4 vert = gl_Vertex;

	// life > 0
	if (vert.w > 0.0)
	{
		// color lerp
		Clr = vec4(1.0);//gl_MultiTexCoord1 + (gl_Color - gl_MultiTexCoord1) * vert.w;

		// Start and Stop size
        vec2 sz = abs(gl_MultiTexCoord0.xy);
		// size lerp
		float size = sz.y + (sz.x - sz.y) * vert.w;

		// TexCoord -1..1
		TexCoord.x = sign(gl_MultiTexCoord0.x);
		TexCoord.y = sign(gl_MultiTexCoord0.y);

		// screen aligned quad vertex using "TexCoord" (-1..1) and camera screen vectors
		vert.xyz += size * TexCoord.x * Right + size * Up * TexCoord.y;

		// rotation lerp
		float rot = gl_MultiTexCoord0.z + (gl_MultiTexCoord0.w - gl_MultiTexCoord0.z) * vert.w;

		// rotation matrix
		mat2 rotmat;
		rotmat[0][0] = rotmat[1][1] = cos(rot);
		rotmat[0][1] = sin(rot);
		rotmat[1][0] = -rotmat[0][1];

		//rotate TexCoord and transform them to range 0..1
		TexCoord = ((rotmat * TexCoord) + 1.0) * 0.5;

		// transfomation
		vert.w = 1.0;
		gl_Position = gl_ModelViewProjectionMatrix * vert;
	}
	else
	{
  		// z wokna ven!
		gl_Position = vec4(-2.0);
	}
}
