uniform sampler2D Sampler;

uniform	float2 	texel_size;									// set automatically by gfx engine
uniform	float	outline_size = 2;							// pixels, set by code
uniform	float4	outline_color = float4(1.f, 0.f, 0.f, 1.f);	// r g b a, set by code
uniform	float	alpha_mul = 3;								// affects the overall thickness and opacity of blur. can set to a high number to produce a solid outline instead.

float4 main(float4 position : TEXCOORD0) : COLOR0
{
    //this will be our RGBA sum
    float sum = 0.0;

    float hstep = 0.f;
    float vstep = texel_size.y * outline_size;

    //apply blurring, using a 9-tap filter with predefined gaussian weights

    sum += tex2D(Sampler, float2(position.x - 4.0*hstep, position.y - 4.0*vstep)).a * 0.0162162162;
    sum += tex2D(Sampler, float2(position.x - 3.0*hstep, position.y - 3.0*vstep)).a * 0.0540540541;
    sum += tex2D(Sampler, float2(position.x - 2.0*hstep, position.y - 2.0*vstep)).a * 0.1216216216;
    sum += tex2D(Sampler, float2(position.x - 1.0*hstep, position.y - 1.0*vstep)).a * 0.1945945946;

    sum += tex2D(Sampler, float2(position.x, position.y)).a * 0.2270270270;

    sum += tex2D(Sampler, float2(position.x + 1.0*hstep, position.y + 1.0*vstep)).a * 0.1945945946;
    sum += tex2D(Sampler, float2(position.x + 2.0*hstep, position.y + 2.0*vstep)).a * 0.1216216216;
    sum += tex2D(Sampler, float2(position.x + 3.0*hstep, position.y + 3.0*vstep)).a * 0.0540540541;
    sum += tex2D(Sampler, float2(position.x + 4.0*hstep, position.y + 4.0*vstep)).a * 0.0162162162;

    //discard alpha for our simple demo, multiply by vertex color and return
    return float4(outline_color.rgb, sum*alpha_mul);
}