#include "dxEffectIncludes.h"
// Fragment shader for doing blur for source of blurred background effects

typedef struct
{
    float blurAmount;
} fxVars;

cbuffer variableBuffer : register(b2)
{
    fxVars vars;
}

struct fsVertexOut
{
    float4 position : SV_POSITION;
    float2 texMask  : TEXCOORD0;
    float2 normPos  : TEXCOORD1;
    float2 texSize  : TEXCOORD2;
    float2 tex0     : TEXCOORD3;
    float2 tex1     : TEXCOORD4;
    float2 tex2     : TEXCOORD5;
    float2 tex3     : TEXCOORD6;
};

fsVertexOut vertexShader(fxShaderVerts input)
{
    fsVertexOut output;

    output.normPos   = input.position.xy * vec2(.5, .5) + vec2(.5, .5);
    output.position  = float4(input.position, 1.0);

    output.texMask   = input.texMask;
    output.texSize   = u.texSize;                    // assuming u.texSize is available

    float scale = (u.renderPass + 1.0) * (vars.blurAmount * .8 + .2);
    float2 pixelOffset = vec2(1.0 / output.texSize.x, 1.0 / output.texSize.y);

    output.tex0 = input.tex1 + pixelOffset * vec2(-.5,  .5) * scale;
    output.tex1 = input.tex1 + pixelOffset * vec2( .5, -.5) * scale;
    output.tex2 = input.tex1 + pixelOffset * vec2( .5,  .5) * scale;
    output.tex3 = input.tex1 + pixelOffset * vec2(-.5, -.5) * scale;

    return output;
}

float4 pixelShader(fsVertexOut input) : SV_TARGET
{
    float4 outColor = inputTex.Sample(linearSampler, input.tex0);   // using your default linearSampler
    outColor += inputTex.Sample(linearSampler, input.tex1);
    outColor += inputTex.Sample(linearSampler, input.tex2);
    outColor += inputTex.Sample(linearSampler, input.tex3);
    outColor *= 0.25;

    return outColor;
}
