#version 410 core
in vec3 FragPos;
in vec3 Normal;
in vec3 Color;

out vec4 FragColor;

uniform vec3 uSunDir;
uniform vec3 uSunColor;
uniform vec3 uSkyColor;
uniform vec3 uGroundColor;
uniform vec3 uViewPos;
uniform float uSpecularStrength;
uniform float uShininess;

void main() {
    vec3 N = normalize(Normal);
    float up = 0.5 + 0.5 * N.y;
    vec3 ambient = mix(uGroundColor, uSkyColor, up);
    float NdotL = max(dot(N, uSunDir), 0.0);
    vec3 diffuse = NdotL * uSunColor;
    vec3 V = normalize(uViewPos - FragPos);
    vec3 H = normalize(uSunDir + V);
    float spec = pow(max(dot(N, H), 0.0), uShininess) * (NdotL > 0.0 ? 1.0 : 0.0);
    vec3 specular = uSpecularStrength * spec * uSunColor;
    vec3 result = (ambient + diffuse) * Color + specular;
    FragColor = vec4(result, 1.0);
}
