#version 330

in vec2 fragTexCoord;
in vec3 fragNormal;
in vec3 fragFragPos;
in vec4 fragColor;

out vec4 finalColor;

uniform sampler2D texture0;
uniform vec4 colDiffuse;

// Custom Uniforms for PS2-era arcade look
uniform vec3 lightDir;      // Direction light comes from (e.g. overhead sun)
uniform vec3 lightColor;    // Color of sun/streetlights (e.g. warm white/yellow)
uniform vec3 ambientColor;  // Shadow tint (e.g. dark blue/purple night sky)
uniform vec3 viewPos;       // Camera position for specular shine

void main() {
    // 1. Sample base texture and material tint
    vec4 texColor = texture(texture0, fragTexCoord) * colDiffuse * fragColor;
    
    vec3 N = normalize(fragNormal);
    vec3 L = normalize(-lightDir);
    vec3 V = normalize(viewPos - fragFragPos);

    // 2. Directional Diffuse (Lambert)
    float diff = max(dot(N, L), 0.0);
    vec3 diffuse = diff * lightColor;

    // 3. Early-2000s Specular Highlight (Blinn-Phong)
    vec3 H = normalize(L + V);
    float spec = pow(max(dot(N, H), 0.0), 32.0); // 32.0 = medium glossiness
    vec3 specular = lightColor * spec * 0.6;      // 0.6 = gloss strength

    // 4. Combine Ambient + Diffuse + Specular
    vec3 lighting = ambientColor + diffuse + specular;
    
    finalColor = vec4(texColor.rgb * lighting, texColor.a);
}
