#version 460 core

in vec2 TexCoord0;
flat in float TTL0;
uniform vec3 color;
out vec4 FragColor;

vec3 pow3(vec3 v, float p) { return pow(abs(v), vec3(p)); }

vec3 glowSphere(vec3 color, vec2 p, float radius, float glow) {
	float term = 1./length(p)/5.;
	return pow3(color * term * 0.5, glow) * radius;
}

void main() {
	vec3 baseColor = color * clamp(TTL0, 0.0, 1.0);
	vec3 color = glowSphere(baseColor, TexCoord0 * 2 - 1, 5, 3.25);
	float lum = dot(color, vec3(0.299, 0.587, 0.114));

	FragColor = vec4(color, lum);
}