#include "mta-helper.fx"
float sRain = 0;
float3 sFogColor = float3(0.44,0.49,0.54);
struct V { float3 p : POSITION0; };
struct P { float4 p : POSITION0; float fog : TEXCOORD0; };
P VS(V v) {
    P o; o.p = mul(float4(v.p,1),gWorldViewProjection);
    float3 world = MTACalcWorldPosition(v.p);
    float d = max(0,distance(gCameraPosition,world) - 28);
    float layer = 0.83 + 0.17 * sin(world.z * 0.035 + gTime * 0.035);
    // Smooth aerial perspective is evaluated per vertex instead of every pixel.
    o.fog = (1 - exp(-d * d * 0.000014 * layer)) * sRain * 0.78;
    return o;
}
float4 PS(P i) : COLOR0 {
    return float4(sFogColor,i.fog);
}
technique aerialFog { pass P0 {
    AlphaBlendEnable = true; SrcBlend = SRCALPHA; DestBlend = INVSRCALPHA;
    ZWriteEnable = false; DepthBias = -0.00005;
    VertexShader = compile vs_3_0 VS(); PixelShader = compile ps_3_0 PS();
} }
technique fallback { pass P0 {} }
