//Texture
texture texDiffuse;
texture texOverlay;
float4x4 matWVP;
float blurAmount;

//Sampler
sampler DiffuseSampler = sampler_state
{
   Texture = (texDiffuse);
   MinFilter = Linear;   MagFilter = Linear;   MipFilter = Linear;
   AddressU  = Clamp;    AddressV  = Clamp;    AddressW  = Clamp;
   MaxAnisotropy = 16;
};

//Sampler
sampler OverlaySampler = sampler_state
{
   Texture = (texOverlay);
   MinFilter = Linear;   MagFilter = Linear;   MipFilter = Linear;
   AddressU  = Clamp;    AddressV  = Clamp;    AddressW  = Clamp;
   MaxAnisotropy = 16;
};

//Vertex Input
struct VS_INPUT
{
     float4 position : POSITION0;
     float3 normal   : NORMAL;
     float2 tex0     : TEXCOORD0;
};

//Vertex Output / Pixel Shader Input
struct VS_OUTPUT
{
     float4 position : POSITION0;
     float2 tex0     : TEXCOORD0;
     float  shade	 : TEXCOORD1;
};

VS_OUTPUT vs_base(VS_INPUT input)
{
	VS_OUTPUT output = (VS_OUTPUT)0;
	output.position = mul(input.position, matWVP);
	output.tex0 = input.tex0;
	
	
	return output;
}

//Pixel Shader
float4 ps_blur_vertical(VS_OUTPUT IN) : COLOR0
{
	
	float amount = blurAmount;
	 
	float4 color = (tex2D(DiffuseSampler, float2(IN.tex0.x-amount*1.0f, IN.tex0.y)) +
					tex2D(DiffuseSampler, float2(IN.tex0.x-amount*0.4f, IN.tex0.y)) +
					tex2D(DiffuseSampler, float2(IN.tex0.x+amount*0.4f, IN.tex0.y)) +
					tex2D(DiffuseSampler, float2(IN.tex0.x+amount*1.0f, IN.tex0.y)))*0.25f;
	return color*1.0f;
}

//Pixel Shader
float4 ps_blur_horizontal(VS_OUTPUT IN) : COLOR0
{
	float amount = blurAmount;
	 
	float4 color = (tex2D(DiffuseSampler, float2(IN.tex0.x, IN.tex0.y-amount*1.0f)) +
					tex2D(DiffuseSampler, float2(IN.tex0.x, IN.tex0.y-amount*0.4f)) +
					tex2D(DiffuseSampler, float2(IN.tex0.x, IN.tex0.y+amount*0.4f)) +
					tex2D(DiffuseSampler, float2(IN.tex0.x, IN.tex0.y+amount*1.0f)))*0.25f;
	return color*1.0f;
}
/*
//Pixel Shader
float4 ps_treshold(VS_OUTPUT IN) : COLOR0
{
	
	float treshold = 0.15;
	 
	float4 color = tex2D(DiffuseSampler, IN.tex0);
	float c = color.x + color.y + color.z * 0.3333f;
	if( c > treshold)
		c = 0.0f;
	else
		c = 1.0f;
	return c;
}
*/
//Pixel Shader
float4 ps_additive(VS_OUTPUT IN) : COLOR0
{
	float4 diffuse = tex2D(DiffuseSampler, IN.tex0);
	float4 overlay =  tex2D(OverlaySampler, IN.tex0);
	float4 org = tex2D(DiffuseSampler, IN.tex0)*0.5+ tex2D(OverlaySampler, IN.tex0)*0.4;
	float4 t = (overlay-diffuse);
	return   org ;
	//return tex2D(DiffuseSampler, IN.tex0)*0.5+ tex2D(OverlaySampler, IN.tex0)*0.4;
}

//Pixel Shader
float4 ps_dummy(VS_OUTPUT IN) : COLOR0
{
	return tex2D(DiffuseSampler, IN.tex0);
}

technique blur_2_0
{
    pass P0
    {
		CullMode = CW;
		ZWriteEnable = false;
        VertexShader = compile vs_2_0 vs_base();
        PixelShader  = compile ps_2_0 ps_blur_vertical();        
    }
    pass P1
    {
		CullMode = CW;
		ZWriteEnable = false;
        VertexShader = compile vs_2_0 vs_base();
        PixelShader  = compile ps_2_0 ps_blur_horizontal();        
    }    
}
/*
technique treshold_2_0
{
    pass P0
    {
		CullMode = CW;
		ZWriteEnable = false;
        VertexShader = compile vs_2_0 vs_base();
        PixelShader  = compile ps_2_0 ps_treshold();        
    }

}
*/
technique additive_2_0
{
    pass P0
    {
		CullMode = CW;
		ZWriteEnable = false;
        VertexShader = compile vs_2_0 vs_base();
        PixelShader  = compile ps_2_0 ps_additive();        
    }

}

technique additive_1_1
{
    pass P0
    {
		CullMode = CW;
		ZWriteEnable = false;
        VertexShader = compile vs_1_1 vs_base();
        PixelShader  = compile ps_1_1 ps_dummy();        
    }
}

technique blur_1_1
{
    pass P0
    {
		CullMode = CW;
		ZWriteEnable = false;
        VertexShader = compile vs_1_1 vs_base();
        PixelShader  = compile ps_1_1 ps_dummy();        
    }
}

technique additive_FFP
{
	pass P0
	{        
		Lighting = false;
		ZWriteEnable = true;
		//WorldTransform[0] = <matW>;
		//ViewTransform = <matV>;
		//ProjectionTransform = <matP>;
		Texture[0] = <texDiffuse>;
	}
}

technique blur_FFP
{
	pass P0
	{        
		Lighting = false;
		ZWriteEnable = true;
		//WorldTransform[0] = <matW>;
		//ViewTransform = <matV>;
		//ProjectionTransform = <matP>;
		Texture[0] = <texDiffuse>;
	}
}