#version 330

in vec3 vWorldPos;
in vec2 vTexCoord;

uniform sampler2D texture0;
uniform vec3  u_playerPos;     // player world pos
uniform float u_inner;         // start of vignette (m)
uniform float u_outer;         // end of vignette (m)  u_outer > u_inner
uniform float u_minShadow;     // baseline darkness at center [0..1], e.g. 0.15
uniform vec4  u_fogColor;      // usually vec4(0,0,0,1)
uniform float u_alphaCutoff;   // for trees/billboards too

out vec4 finalColor;

void main()
{
    vec4 texel = texture(texture0, vTexCoord);
    if (texel.a < u_alphaCutoff) discard;

    // distance on the ground plane
    float distXZ = length(vWorldPos.xz - u_playerPos.xz);

    // 0 at u_inner, 1 at u_outer
    float t = smoothstep(u_inner, u_outer, distXZ);

    // add baseline shadow so center is not fully bright
    t = u_minShadow + (1.0 - u_minShadow) * t;

    vec3 rgb = mix(texel.rgb, u_fogColor.rgb, t);
    finalColor = vec4(rgb, texel.a);
}
