#include "dxEffectIncludes.h"


// Fragment shader for doing blur for source of blurred background effects

typedef struct
{
    float blurAmount;
    float pad[3];
} fxVars;


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


typedef struct
{
    float4 position : SV_POSITION;
    float2 tex0 : TEXCOORD0;
    float2 tex1 : TEXCOORD1;
    float2 tex2 : TEXCOORD2;
    float2 tex3 : TEXCOORD3;
    float2 tex4 : TEXCOORD4;
    float2 tex5 : TEXCOORD5;
    float2 tex6 : TEXCOORD6;
    float2 tex7 : TEXCOORD7;
} fsVertexOut;


fsVertexOut vertexShader(vertexPT input)
{
    fsVertexOut output;
    output.position = float4(input.position,1);

    float2 pixelOffset=vec2(1.0,1.0)/u.texSize;

    float2 center = input.tex1;
    vec2 halfpixel = pixelOffset * vec2(.5, .5);

    float offset = 3.;

    output.tex0 = center + vec2(-halfpixel.x * offset, 0.0);
    output.tex1 = center + vec2(-halfpixel.x, halfpixel.y);
    output.tex2 = center + vec2(0.0, halfpixel.y * offset);
    output.tex3 = center + vec2(halfpixel.x, halfpixel.y);
    output.tex4 = center + vec2(halfpixel.x * offset, 0.0);
    output.tex5 = center + vec2(halfpixel.x, -halfpixel.y);
    output.tex6 = center + vec2(0.0, -halfpixel.y * offset);
    output.tex7 = center + vec2(-halfpixel.x, -halfpixel.y);

    return output;
}

#define getTexture(a,b) a.Sample(blurSampler,b)

float4 pixelShader(fsVertexOut input) : SV_TARGET
{
    float weight = 3.;

    vec4 sum = getTexture(inputTex, input.tex0);
    sum += getTexture(inputTex, input.tex1) * weight;
    sum += getTexture(inputTex, input.tex2);
    sum += getTexture(inputTex, input.tex3) * weight;
    sum += getTexture(inputTex, input.tex4);
    sum += getTexture(inputTex, input.tex5) * weight;
    sum += getTexture(inputTex, input.tex6);
    sum += getTexture(inputTex, input.tex7) * weight;

    return sum / 12.0;
}
