#version 330

uniform mat4 perspective_matrix;
uniform mat4 modelview_matrix;

uniform sampler2D readTexture;

in vec2 vertex;

out vec4 particle_eye;
out float point_size;


void main(void)
{
	vec4 particle = vec4(texture(readTexture, vertex).xyz, 1.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 = 24;

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

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

	gl_Position = perspective_matrix*particle_eye;
	//particle_eye = gl_Position;
	point_size = gl_PointSize;
	//particle_eye = perspective_matrix*particle_eye;
}
