#version 400 core
#define M_PI 3.1415926535897932384626433832795
in vec2 vTexCoord;
out vec4 vOutputColour;

uniform sampler2D sampler0;
uniform vec4 vColour;
uniform int quality;
uniform float outlineWidth;
uniform vec4 outlineColor;

void main()
{
	vec4 vTexColour = texture(sampler0, vTexCoord);
	if(vTexColour.r > 0.5){
		vOutputColour = vec4(vTexColour.r) * vColour;
	}
	else{
		vOutputColour = vec4(vTexColour.r) * vColour;
		float t = outlineWidth;
		for(int i = 0; i < quality; i++)
		{
			float angle = (2 * i * M_PI)/quality;
			vec4 vTex = texture(sampler0, vTexCoord + (t * vec2(cos(angle), sin(angle))));
			
			if(vTex.r > 0.5){
				vOutputColour = outlineColor;
				break;
			}
		
		}
	}
}