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.

// 5x5 kernel basic 1 pass blur. 

float4 main(float4 position : TEXCOORD0) : COLOR0
{
	float2 step_size = float2(texel_size.x*outline_size, texel_size.y*outline_size);
	float alpha = 0.f;
		
	alpha += tex2D(Sampler, float2(position.x + (step_size.x * -2), position.y + (step_size.y * -2))).a;
	alpha += tex2D(Sampler, float2(position.x + (step_size.x * -1), position.y + (step_size.y * -2))).a;
	alpha += tex2D(Sampler, float2(position.x + (step_size.x * 0), position.y + (step_size.y * -2))).a;
	alpha += tex2D(Sampler, float2(position.x + (step_size.x * 1), position.y + (step_size.y * -2))).a;
	alpha += tex2D(Sampler, float2(position.x + (step_size.x * 2), position.y + (step_size.y * -2))).a;
	
	alpha += tex2D(Sampler, float2(position.x + (step_size.x * -2), position.y + (step_size.y * -1))).a;
	alpha += tex2D(Sampler, float2(position.x + (step_size.x * -1), position.y + (step_size.y * -1))).a;
	alpha += tex2D(Sampler, float2(position.x + (step_size.x * 0), position.y + (step_size.y * -1))).a;
	alpha += tex2D(Sampler, float2(position.x + (step_size.x * 1), position.y + (step_size.y * -1))).a;
	alpha += tex2D(Sampler, float2(position.x + (step_size.x * 2), position.y + (step_size.y * -1))).a;
	
	alpha += tex2D(Sampler, float2(position.x + (step_size.x * -2), position.y + (step_size.y * 0))).a;
	alpha += tex2D(Sampler, float2(position.x + (step_size.x * -1), position.y + (step_size.y * 0))).a;
	alpha += tex2D(Sampler, float2(position.x + (step_size.x * 0), position.y + (step_size.y * 0))).a;
	alpha += tex2D(Sampler, float2(position.x + (step_size.x * 1), position.y + (step_size.y * 0))).a;
	alpha += tex2D(Sampler, float2(position.x + (step_size.x * 2), position.y + (step_size.y * 0))).a;
	
	alpha += tex2D(Sampler, float2(position.x + (step_size.x * -2), position.y + (step_size.y * 1))).a;
	alpha += tex2D(Sampler, float2(position.x + (step_size.x * -1), position.y + (step_size.y * 1))).a;
	alpha += tex2D(Sampler, float2(position.x + (step_size.x * 0), position.y + (step_size.y * 1))).a;
	alpha += tex2D(Sampler, float2(position.x + (step_size.x * 1), position.y + (step_size.y * 1))).a;
	alpha += tex2D(Sampler, float2(position.x + (step_size.x * 2), position.y + (step_size.y * 1))).a;
	
	alpha += tex2D(Sampler, float2(position.x + (step_size.x * -2), position.y + (step_size.y * 2))).a;
	alpha += tex2D(Sampler, float2(position.x + (step_size.x * -1), position.y + (step_size.y * 2))).a;
	alpha += tex2D(Sampler, float2(position.x + (step_size.x * 0), position.y + (step_size.y * 2))).a;
	alpha += tex2D(Sampler, float2(position.x + (step_size.x * 1), position.y + (step_size.y * 2))).a;
	alpha += tex2D(Sampler, float2(position.x + (step_size.x * 2), position.y + (step_size.y * 2))).a;
	
	alpha /= 25.f;
	
    return float4(outline_color.r, outline_color.g, outline_color.b, alpha*alpha_mul);
}