#version 330 core

in vec3 normalVec;
in vec2 texCoord;
in vec4 worldPos;

out vec4 FragColor;

uniform vec3 lightPos;
uniform vec3 eyePos;
uniform vec3 lightCol;

uniform sampler2D albedoMap;
uniform vec3 specular;
uniform float shininess;

void main()
{
    vec3 Kd = texture(albedoMap, texCoord).rgb;

    vec3 N = normalize(normalVec);
    vec3 L = normalize(lightPos - worldPos.xyz);
    vec3 V = normalize(eyePos   - worldPos.xyz);
    vec3 H = normalize(L + V);

    float NL = max(dot(N, L), 0.0);
    float HN = max(dot(H, N), 0.0);

    vec3 Ia = 0.1 * lightCol;
    vec3 Id = lightCol * Kd * NL;
    vec3 Is = lightCol * specular * pow(HN, shininess);

    vec3 color = Ia * Kd + Id + Is;

    FragColor = vec4(color, 1.0);
}
