//-----------------------------------------------------------------------------
// Blur the image vertically. Combine with blur_horizontal to accomplish full blur.
//-----------------------------------------------------------------------------


float4x4 TotalMatrix;
float4 VectorFromObject; // y=pixel_height (1 / viewport_height), z=blur factor 
float4 TextureFactor; // object rgba
float4 VectorFromShader; // xy=uvmax

texture g_Texture0;
texture g_Texture1;


sampler2D TextureSampler : register(s0) =
sampler_state
{
    Texture = <g_Texture0>;
    AddressU = Clamp;
    AddressV = Clamp;
    MinFilter = linear;
    MagFilter = Linear;
    MipFilter = Linear;
};

sampler2D g_Sampler1 : register(s1) =
sampler_state
{
    Texture = <g_Texture1>;
    AddressU = Clamp;
    AddressV = Clamp;
    MinFilter = Point;
    MagFilter = Linear;
    MipFilter = Linear;
};


#define KERNEL0 0.20f
#define KERNEL1 0.30f
#define KERNEL2 0.50f
#define KERNEL3 0.75f
#define KERNEL4 0.90f
#define KERNEL5 1.00f
#define KERNEL6 0.90f
#define KERNEL7 0.75f
#define KERNEL8 0.50f
#define KERNEL9 0.30f
#define KERNEL10 0.20f


float4 PostProcessPS(float2 tex : TEXCOORD0, float2 tex1 : TEXCOORD1) : COLOR0
{
	float4 color1 = tex2D(g_Sampler1, tex1);

	float4 color = 0;

	float pixel_height = VectorFromObject.y * VectorFromObject.z * (1-color1.a);
	
	tex.y -= 5 * pixel_height;
	float4 c = tex2D(TextureSampler, tex.xy) * KERNEL0;
	color += c;
	tex.y += pixel_height;
	c = tex2D(TextureSampler, tex.xy) * KERNEL1;
	color += c;
	tex.y += pixel_height;
	c = tex2D(TextureSampler, tex.xy) * KERNEL2;
	color += c;
	tex.y += pixel_height;
	c = tex2D(TextureSampler, tex.xy) * KERNEL3;
	color += c;
	tex.y += pixel_height;
	c = tex2D(TextureSampler, tex.xy) * KERNEL4;
	color += c;
	tex.y += pixel_height;
	c = tex2D(TextureSampler, tex.xy) * KERNEL5;
	color += c;
	tex.y = min(tex.y + pixel_height, VectorFromShader.y);
	c = tex2D(TextureSampler, tex.xy) * KERNEL6;
	color += c;
	tex.y = min(tex.y + pixel_height, VectorFromShader.y);
	c = tex2D(TextureSampler, tex.xy) * KERNEL7;
	color += c;
	tex.y = min(tex.y + pixel_height, VectorFromShader.y);
	c = tex2D(TextureSampler, tex.xy) * KERNEL8;
	color += c;
	tex.y = min(tex.y + pixel_height, VectorFromShader.y);
	c = tex2D(TextureSampler, tex.xy) * KERNEL9;
	color += c;
	tex.y = min(tex.y + pixel_height, VectorFromShader.y);
	c = tex2D(TextureSampler, tex.xy) * KERNEL10;
	color += c;

	color *= TextureFactor;

	color /= KERNEL0 + KERNEL1 + KERNEL2 + KERNEL3 + KERNEL4 + KERNEL5 + KERNEL6 + KERNEL7 + KERNEL8 + KERNEL9 + KERNEL10;

	return float4(color.r, color.g, color.b, 1.0); // RGBA
}




//-----------------------------------------------------------------------------
// Technique: PostProcess
// Desc: Performs post-processing effect that inverts the image
//-----------------------------------------------------------------------------
technique PostProcess
{
    pass p0
    {
        VertexShader = null;
        PixelShader = compile ps_2_0 PostProcessPS();
        ZEnable = false;
    }
}

















