#version 330 core

in vec3 normal;
in vec3 fragmentPosition;


uniform vec4 ambientColor;
uniform vec4 diffusionColor;
uniform vec4 specularColor;

uniform float shininess;

uniform vec4 ambientLight;
uniform vec3 lightPosition;
uniform vec4 lightColor;


float emissionStrength = 0.0;


void main() {
	vec3 norm = normalize(normal);
	vec3 lightDir = normalize(lightPosition - fragmentPosition);
	vec3 eyeDir = -normalize(fragmentPosition);

	float diff = max(dot(norm, lightDir), 0.0);

	vec3 halfway = (lightDir + eyeDir) / length(lightDir + eyeDir);
	float specular = pow(max(dot(halfway, norm), 0.0), shininess);

	gl_FragColor =
		// EMISSION
		diffusionColor * emissionStrength +

		// // AMBIENT
		ambientLight * ambientColor +

		// DIFFUSION
		diff * lightColor * diffusionColor +

		// SPECULAR
		specular * lightColor * specularColor;
}