#version 330

in vec2 fragTexCoord;
in vec4 fragColor;

uniform sampler2D texture0;
uniform sampler2D lightMap;
uniform vec3 ambient;

out vec4 finalColor;

void main() {
    vec4 base = texture(texture0, fragTexCoord) * fragColor;
    vec2 lightCoords = vec2(fragTexCoord.x, 1.0 - fragTexCoord.y);
    vec3 light = texture(lightMap, lightCoords).rgb;
    vec3 lighting = clamp(ambient + light, 0.0, 1.0);
    vec3 color = base.rgb * lighting;
    finalColor = vec4(color, base.a);
}
