layout (points) in;
layout (triangle_strip, max_vertices = 4) out;

in vec3 geoUvec[];
in float geoRadius[];
in vec4 geoColor[];
in float geoArrayIndex[];

out float fragRadius;
out vec4 fragPosition;
out vec4 fragTexCoord;
out vec4 fragColor;

layout (std140) uniform matrixData {
	mat4 modelViewMatrix;
	mat4 projMatrix;
};

void main(void)
{
	vec3 forward_vec = vec3(0.0, 0.0, 1.0);
	vec3 up_vec = normalize(geoUvec[0]);
	vec3 right_vec = cross(forward_vec, up_vec);
	vec4 pos = vec4(0.0, 0.0, 0.0, 0.0);
	right_vec = normalize(right_vec);
	pos = (gl_in[0].gl_Position - vec4(geoRadius[0] * up_vec, 0.0) - vec4(geoRadius[0] * right_vec, 0.0));
	gl_Position = projMatrix * pos;
	fragPosition = pos;
	fragTexCoord = vec4(0.0, 0.0, geoArrayIndex[0], 0.0);
	fragRadius = geoRadius[0];
	fragColor = geoColor[0];
	EmitVertex();

	pos = (gl_in[0].gl_Position - vec4(geoRadius[0] * up_vec, 0.0) + vec4(geoRadius[0] * right_vec, 0.0));
	gl_Position = projMatrix * pos;
	fragPosition = pos;
	fragTexCoord = vec4(0.0, 1.0, geoArrayIndex[0], 0.0);
	fragRadius = geoRadius[0];
	fragColor = geoColor[0];
	EmitVertex();

	pos = (gl_in[0].gl_Position + vec4(geoRadius[0] * up_vec, 0.0) - vec4(geoRadius[0] * right_vec, 0.0));
	gl_Position = projMatrix * pos;
	fragPosition = pos;
	fragTexCoord = vec4(1.0, 0.0, geoArrayIndex[0], 0.0);
	fragRadius = geoRadius[0];
	fragColor = geoColor[0];
	EmitVertex();

	pos = (gl_in[0].gl_Position + vec4(geoRadius[0] * up_vec, 0.0) + vec4(geoRadius[0] * right_vec, 0.0));
	gl_Position = projMatrix * pos;
	fragPosition = pos;
	fragTexCoord = vec4(1.0, 1.0, geoArrayIndex[0], 0.0);
	fragRadius = geoRadius[0];
	fragColor = geoColor[0];
	EmitVertex();
	EndPrimitive();
}
