#version 330

uniform mat4 perspective_matrix;
uniform mat4 modelview_matrix;

uniform sampler2D readTexture;

in vec2 vertex;

out float alpha;
flat out int tex_num; //determine which texture to use for this particle

void main(void)
{
	vec4 particle = vec4(texture(readTexture, vertex).xyz, 1.0);

	alpha = pow(clamp(1.0 - texture(readTexture, vertex).w, 0.0, 1.0), 3);

	if (vertex.x > vertex.y)
	{
		tex_num = 1;
	}
	else
	{
		tex_num = 0;
	}

	vec4 particle_eye = modelview_matrix*particle;


	//experimental hardcoded far-plane value for proper size of snow particles
	float far_plane = 60.0;
	float max_size = 32;

	gl_PointSize =  clamp(max_size * (1 - (-particle_eye.z / far_plane)), 3.0, max_size);

	//old version
	//gl_PointSize =  clamp (32 * (1.0 - texture(readTexture, vertex).w), 5, 64);

	gl_Position = perspective_matrix*particle_eye;
}
