////////////////////////////////////////////////////////////////////////////////////////////////////
// Includes
////////////////////////////////////////////////////////////////////////////////////////////////////

#include "../../../types.txt"

////////////////////////////////////////////////////////////////////////////////////////////////////
// Structures
////////////////////////////////////////////////////////////////////////////////////////////////////

struct PS_INPUT
{
#if MIX_SM_HIGH
	float4 pos : SV_POSITION;
#endif //MIX_SM_HIGH
	float2 tex : TEXCOORD0;
};

////////////////////////////////////////////////////////////////////////////////////////////////////
// Grobal values
////////////////////////////////////////////////////////////////////////////////////////////////////

#if MIX_SM_HIGH

	cbuffer cbInput : register( b0 )
	{
		float4 g_Kernel[3];
	};

	Texture2D g_ColorTexture : register( t0 );
	SamplerState g_ColorSampler : register( s0 );
	
#else //MIX_SM_HIGH

	float4 g_Kernel[3] : register( c0 ); // xy=Offset w=Weight

	sampler g_ColorSampler : register( s0 );

#endif //MIX_SM_HIGH

////////////////////////////////////////////////////////////////////////////////////////////////////
// Macros
////////////////////////////////////////////////////////////////////////////////////////////////////

#if MIX_SM_HIGH
	#define TEX_COLOR( uv ) g_ColorTexture.Sample( g_ColorSampler, uv )
#else //MIX_SM_HIGH
	#define TEX_COLOR( uv ) tex2D( g_ColorSampler, uv )
#endif //MIX_SM_HIGH

////////////////////////////////////////////////////////////////////////////////////////////////////
// Main function : Default
////////////////////////////////////////////////////////////////////////////////////////////////////

// X
float4 mainX( PS_INPUT input ) : MSV_TARGET0
{
	int i;
	float4 output = 0.0;

	for( i = 0; i < AMOUNT; i++ )
	{
		output += TEX_COLOR( float2( input.tex.x - g_Kernel[i].x, input.tex.y ) ) * g_Kernel[i].w;
	}

	#if ( AMOUNT < 3 )
		output += TEX_COLOR( float2( input.tex.x + g_Kernel[1].x, input.tex.y ) ) * g_Kernel[1].w;
	#else

		for( i = 1; i < AMOUNT; i++ )
		{
			output += TEX_COLOR( float2( input.tex.x + g_Kernel[i].x, input.tex.y ) ) * g_Kernel[i].w;
		}

	#endif

	return output;
}

// Y
float4 mainY( PS_INPUT input ) : MSV_TARGET0
{
	int i;
	float4 output = 0.0;

	for( i = 0; i < AMOUNT; i++ )
	{
		output += TEX_COLOR( float2( input.tex.x, input.tex.y - g_Kernel[i].y ) ) * g_Kernel[i].w;
	}

	#if ( AMOUNT < 3 )
		output += TEX_COLOR( float2( input.tex.x, input.tex.y + g_Kernel[1].y ) ) * g_Kernel[1].w;
	#else
		for( i = 1; i < AMOUNT; i++ )
		{
			output += TEX_COLOR( float2( input.tex.x, input.tex.y + g_Kernel[i].y ) ) * g_Kernel[i].w;
		}
	#endif

	return output;
}
