#version 330 core
// fragment shader for [billboarded] small torch

in vec4 aPos; //actual vertex pos

out vec4 color;

uniform sampler2D myTextureSampler; //new 8am

uniform vec3 wPos;  // current centroid
uniform float wRad; // current radius

void main(){

	vec3 origin = vec3( wPos.x, wPos.y-wRad, wPos.z );
	//2x1 ellipse:
	vec3 diff=vec3(aPos.x-origin.x, 0.5*(aPos.y-origin.y), aPos.z-origin.z);
	//vec3 diff=vec3(aPos.x-origin.x, (aPos.y-origin.y), aPos.z-origin.z);
	float cool = length( diff );

	float cool01;
	//cool01 = clamp( cool01, 0.0, 1.0 );
	cool01 = clamp( cool*10.0, 0.0, 1.0 );

	vec2 tPos = vec2(0, 1.0-cool01);

	color = texture( myTextureSampler, tPos).rgba;

	float dist = length( vec3(aPos.xyz-wPos) );
	dist /= wRad;
	dist = clamp( dist, 0.0, 1.0 );

	float opacity = (1.0-cool01); //too wide; must clip

	// ? should we clip the pts below center ?
	if( aPos.y < wPos.y )
		opacity *= (1.0-dist);

	opacity = clamp( opacity, 0.0, 1.0 );
	opacity = sqrt(opacity);

	color.a = opacity;

	if(color.a < 0.05) discard;

}

