SamplerState samLin
{
    Filter = MIN_MAG_MIP_LINEAR;
    AddressU = Mirror;
    AddressV = Mirror;
};

Texture2D gTexture;

float gaussian[6] =
{
    0.198596f,
    0.175713f,
    0.121703f,
    0.065984f,
    0.028002f,
    0.0093f
};
int gStride = 3;

DepthStencilState stencilState
{
    DepthEnable = true;
};

RasterizerState backCulling
{
    CullMode = BACK;
};

struct VS_INPUT
{
    float3 Position : POSITION;
    float2 TexCoord : TEXCOORD0;

};

struct PS_INPUT
{
    float4 Position : SV_POSITION;
    float2 TexCoord : TEXCOORD1;
};


//VERTEX SHADER
//-------------
PS_INPUT VS(VS_INPUT input)
{
    PS_INPUT output = (PS_INPUT) 0;
    output.Position = float4(input.Position.xy, 0, 1);
    output.TexCoord = input.TexCoord;
    
    return output;
}

float4 PS_BLURH(PS_INPUT input) :SV_Target
{
    float2 textureSize;
    gTexture.GetDimensions(textureSize.x, textureSize.y);
    float2 pixelSize = 1.f / textureSize;
    
    float3 color = 0;
    for (int i = -5; i <= 5; ++i)
    {
        float gaussValue = gaussian[abs(i)];
        color += gTexture.Sample(samLin, input.TexCoord + float2(pixelSize.x * i * gStride, 0)).rgb * gaussValue;
    }
    
    return float4(color, 1);
}

float4 PS_BLURV(PS_INPUT input) :SV_Target
{
    float2 textureSize;
    gTexture.GetDimensions(textureSize.x, textureSize.y);
    float2 pixelSize = 1.f / textureSize;
    
    float3 color = 0;
    for (int i = -5; i <= 5; ++i)
    {
        float gaussValue = gaussian[abs(i)];
        color += gTexture.Sample(samLin, input.TexCoord + float2(0, pixelSize.y * i * gStride)).rgb * gaussValue;
    }
    
    return float4(color, 1);
}

technique11 BlurH
{
    pass P0
    {
        SetVertexShader(CompileShader(vs_4_0, VS()));
        SetGeometryShader(NULL);
        SetPixelShader(CompileShader(ps_4_0, PS_BLURH()));

        SetRasterizerState(backCulling);
        SetDepthStencilState(stencilState, 0);
    }
}

technique11 BlurV
{
    pass P0
    {
        SetVertexShader(CompileShader(vs_4_0, VS()));
        SetGeometryShader(NULL);
        SetPixelShader(CompileShader(ps_4_0, PS_BLURV()));

        SetRasterizerState(backCulling);
        SetDepthStencilState(stencilState, 0);
    }
}