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

// simple outline. the outline will be the edges of your texture's visible portion, so it should be rendered on after your actual texture

float4 main(float4 position : TEXCOORD0) : COLOR0
{
	float2 step_size = float2(texel_size.x*outline_size, texel_size.y*outline_size);
	float alpha = 8.0*tex2D(Sampler, float2(position.x, position.y)).a;
	alpha -= tex2D(Sampler, float2(position.x + step_size.x, position.y)).a;
	alpha -= tex2D(Sampler, float2(position.x - step_size.x, position.y)).a;
	alpha -= tex2D(Sampler, float2(position.x, position.y + step_size.y)).a;
	alpha -= tex2D(Sampler, float2(position.x, position.y - step_size.y)).a;

	alpha -= tex2D(Sampler, float2(position.x + step_size.x, position.y + step_size.y)).a;
	alpha -= tex2D(Sampler, float2(position.x - step_size.x, position.y - step_size.y)).a;
	alpha -= tex2D(Sampler, float2(position.x - step_size.x, position.y + step_size.y)).a;
	alpha -= tex2D(Sampler, float2(position.x + step_size.x, position.y - step_size.y)).a;
	
    return float4(outline_color.r, outline_color.g, outline_color.b, alpha);
}