// Applied only to the map surface: blips retain their original colours.
texture mapTexture;
float2 mapSize = float2(350, 210);
sampler MapSampler = sampler_state
{
    Texture = <mapTexture>;
    MinFilter = Linear;
    MagFilter = Linear;
    AddressU = Clamp;
    AddressV = Clamp;
};

float4 drawMap(float2 uv : TEXCOORD0, float4 diffuse : COLOR0) : COLOR0
{
    float4 source = tex2D(MapSampler, uv);
    float luminance = dot(source.rgb, float3(0.299, 0.587, 0.114));
    float roads = smoothstep(0.08, 0.72, luminance);
    float3 colour = lerp(float3(0.055, 0.078, 0.086), float3(0.48, 0.57, 0.55), roads);

    // Pixel-sized corners and a restrained inset edge; no white mask fringe.
    float radius = 7.0;
    float2 q = abs((uv - 0.5) * mapSize) - (mapSize * 0.5 - radius);
    float distance = length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - radius;
    float coverage = 1.0 - smoothstep(-0.8, 0.0, distance);
    float edge = 1.0 - smoothstep(1.0, 14.0, -distance);
    colour *= 1.0 - edge * 0.22;
    float rim = (1.0 - smoothstep(0.7, 1.7, -distance)) * 0.22;
    colour = lerp(colour, float3(0.25, 0.44, 0.40), rim);
    return float4(colour, source.a * coverage) * diffuse;
}

technique NeucMap
{
    pass P0
    {
        PixelShader = compile ps_2_0 drawMap();
    }
}
