Texture2D source;
Texture2D mask;
SamplerState sourceSampler;

struct PixelInputType
{
    float4 position : SV_POSITION;
    float2 uv : TEXCOORD0;
};

cbuffer PerPassBuffer 
{
	uint passNumber;
	float3 padding;
};

static const float PixelKernel[12] =
{
    -6,
    -5,
    -4,
    -3,
    -2,
    -1,
     1,
     2,
     3,
     4,
     5,
     6,
};

static const float BlurWeights[12] = 
{
    0.002216,
    0.008764,
    0.026995,
    0.064759,
    0.120985,
    0.176033,
    0.176033,
    0.120985,
    0.064759,
    0.026995,
    0.008764,
    0.002216,
};

////////////////////////////////////////////////////////////////////////////////
// Pixel Shader
////////////////////////////////////////////////////////////////////////////////
float4 BlurHFragmentShader(PixelInputType input) : SV_TARGET
{
	float4 color = {0, 0, 0, 0};
	color = source.Sample(sourceSampler, input.uv);
	color.a = 1.0f;
	
	if (mask.Sample(sourceSampler, input.uv).r <= passNumber*0.1)
		return color;
				
	// Pixel width
	float TextureWidth = 800.0;
    float pixelWidth = 1.0/TextureWidth;

	color.rgb *= 0.199471;
    float2 blur = input.uv;
			
	[unroll]
	for (int i = 0; i < 12; i++) 
	{
		blur.x = input.uv.x + PixelKernel[i] * pixelWidth;
		color.rgb += source.SampleLevel(sourceSampler, blur, 0).rgb * BlurWeights[i];
	}

    return float4(color.rgb,1);
}

float4 BlurVFragmentShader(PixelInputType input) : SV_TARGET
{
	float4 color = {0, 0, 0, 0};
	color = source.Sample(sourceSampler, input.uv);
	color.a = 1.0f;
	if (mask.Sample(sourceSampler, input.uv).r <= passNumber*0.1)
		return color;
		
    // Pixel width
	float TextureHeight = 600.0;
    float pixelHeight = 1.0/TextureHeight;

	color.rgb *= 0.199471;
    float2 blur = input.uv;

	[unroll]
	for (int i = 0; i < 12; i++) 
	{
		blur.y = input.uv.y + PixelKernel[i] * pixelHeight;
		color.rgb += source.SampleLevel(sourceSampler, blur, 0).rgb * BlurWeights[i];
	}
	
    return float4(color.rgb,1);
}

