precision lowp float;

uniform sampler2D u_mapbox;

uniform int u_vignettingEnable;
uniform vec3 u_lightColor;
uniform vec3 u_lightPosition;
uniform float u_strength;

varying vec2 v_uv;
varying vec3 v_pos;


void main() {
  vec4 color = texture2D(u_mapbox, v_uv);
  
  if (u_vignettingEnable == 1) {
    vec3 origin = vec3(0.0);
    float side1 = distance(u_lightPosition, origin);
    float side2 = distance(v_pos, origin);
    float side3 = distance(v_pos, u_lightPosition);
    float tanA = side1 / side2;
    float cosA = side1 / side3;
    
    vec4 reflectedLight = vec4(u_lightColor, 1.0) * u_strength * color * cosA;

    gl_FragColor = vec4(reflectedLight.rgb, 1.0);
  } else {
    gl_FragColor = color;
  }
}