#version 140

varying vec4 fColor;
varying vec3 fNormal;
varying vec2 fUV;
varying float fLightingFactor;
varying float fTextureFactor;

uniform vec3 uLightDir;
uniform vec3 uLightColor;
uniform vec3 uAmbientLightColor;

uniform sampler2D uTexture;

void main() {
    vec3 normal = normalize(fNormal);

    vec4 texColor = mix(vec4(1), texture2D(uTexture, fUV), fTextureFactor);
    vec3 albedo = texColor.rgb * fColor.rgb;
    float alpha = texColor.a * fColor.a;

    vec3 light = uAmbientLightColor;
    light += clamp(dot(uLightDir, normal), 0.0, 1.0) * uLightColor;
    light = mix(vec3(1), light, fLightingFactor);

    vec3 color = light * albedo;
    gl_FragColor = vec4(color * alpha, alpha);
}
