#version 330 core

in vec3 vNormal;
in vec3 vWorldPos;
out vec4 FragColor;

uniform vec3 uCameraPos;
uniform vec3 uLightDir;
uniform vec3 uColor;

float saturate(float x) { return clamp(x, 0.0, 1.0); }

void main() {
    vec3 N = normalize(vNormal);
    vec3 L = normalize(uLightDir);
    vec3 V = normalize(uCameraPos - vWorldPos);
    vec3 H = normalize(L + V);

    float diff = saturate(dot(N, L));
    float spec = pow(saturate(dot(N, H)), 24.0);

    vec3 col = uColor * (0.35 + 0.65 * diff);
    col += vec3(1.0) * spec * 0.08;
    FragColor = vec4(clamp(col, 0.0, 1.0), 1.0);
}
