texture texture0;
float factor;

sampler Sampler0 = sampler_state
{
    Texture = (texture0);
    AddressU = Clamp;
    AddressV = Clamp;
};

struct PSInput
{
    float2 TexCoord : TEXCOORD0;
};

float4 PixelShader_Background(PSInput PS) : COLOR0
{
    float4 sum = tex2D(Sampler0, PS.TexCoord);
    float totalWeight = 1.0;

    // Matriz de deslocamentos
    float2 offsets[8] = {
        float2(factor, 0), float2(-factor, 0),
        float2(0, factor), float2(0, -factor),
        float2(factor, factor), float2(-factor, factor),
        float2(factor, -factor), float2(-factor, -factor)
    };

    float weights[8] = { 0.8, 0.8, 0.8, 0.8, 0.5, 0.5, 0.5, 0.5 };

    for (int i = 0; i < 8; i++) {
        float2 uv = saturate(PS.TexCoord + offsets[i]);
        float4 sampleColor = tex2D(Sampler0, uv);
        sum.rgb += sampleColor.rgb * weights[i];
        sum.a += sampleColor.a * weights[i];  // Mantém transparência
        totalWeight += weights[i];
    }

    // Normalização
    sum /= totalWeight;

    return sum;
}

technique smoothBlur
{
    pass P0
    {
        AlphaBlendEnable = true;
        SrcBlend = SrcAlpha;
        DestBlend = InvSrcAlpha;
        ZWriteEnable = false; 
        PixelShader = compile ps_2_0 PixelShader_Background();
    }
}