#ifdef GL_ES
precision mediump float;
#endif

uniform sampler2D u_texture;

varying vec2 v_eyePosition;
varying vec2 v_vertexPosition;
varying vec2 v_rotation;
varying float v_halfFov;
varying float v_radius;
varying vec4 v_color;

const float PI = 3.141592653589793238462643383;

void main() {
	float angle = atan(v_vertexPosition.y, v_vertexPosition.x);
	float globalRotation = -atan(v_rotation.y, v_rotation.x);
	angle = globalRotation + angle - PI / 2.0;

	if (angle > PI) {
		angle -= 2.0 * PI;
	} else if (angle < -PI) {
		angle += 2.0 * PI;
	}

	if (angle < -v_halfFov || angle > v_halfFov) {
		discard;
	}

	float l = length(v_vertexPosition);
	if (l > v_radius) {
		discard;
	}

	float factor = 0.005 + (0.40 * ((v_radius - l) / v_radius));
	gl_FragColor = vec4(v_color.r, v_color.g, v_color.b, factor);
}

