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

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

////////////////////////////////////////////////////////////////////////////////////////////////////
// Constant
////////////////////////////////////////////////////////////////////////////////////////////////////

static const float  CA_INV_LEN = 1.4142135623730900976033774484367; // rcp( length( float2( 0.5, 0.5 ) ) );
static const float2 CA_TEX_CENTER = float2( 0.5, 0.5 );

////////////////////////////////////////////////////////////////////////////////////////////////////
// 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_Param;
	};

	//Color
	Texture2D    g_ColorTexture0 : register( t0 );
	SamplerState g_ColorSampler0 : register( s0 );

	//Color( shadings 1 )
	Texture2D    g_ColorTexture1 : register( t1 );
	SamplerState g_ColorSampler1 : register( s1 );

	//Depth
	#if ENABLE_DEPTH
		Texture2D    g_DepthTexture  : register( t2 );
		SamplerState g_DepthSampler  : register( s2 );
	#endif //ENABLE_DEPTH
	
#else //MIX_SM_HIGH

	float4 g_Param : register( c0 );

	//Color
	sampler g_ColorSampler0 : register( s0 );
	
	//Color( shadings 1 )
	sampler g_ColorSampler1 : register( s1 );

	//Depth
	#if ENABLE_DEPTH
		sampler g_DepthSampler  : register( s2 );
	#endif //ENABLE_DEPTH

#endif //MIX_SM_HIGH

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

#if MIX_SM_HIGH

	#define TEX_COLOR0( uv ) g_ColorTexture0.Sample( g_ColorSampler0, uv )
	#define TEX_COLOR1( uv ) g_ColorTexture1.Sample( g_ColorSampler1, uv )

	#if ENABLE_DEPTH
		#define TEX_DEPTH( uv )  g_DepthTexture.Sample( g_DepthSampler, uv )
	#endif //ENABLE_DEPTH

#else //MIX_SM_HIGH

	#define TEX_COLOR0( uv ) tex2D( g_ColorSampler0, uv )
	#define TEX_COLOR1( uv ) tex2D( g_ColorSampler1, uv )

	#if ENABLE_DEPTH
		#define TEX_DEPTH( uv )  tex2D( g_DepthSampler, uv )
	#endif //ENABLE_DEPTH

#endif //MIX_SM_HIGH

#define CS_WEIGHT g_Param.x
#define CA_FI_START g_Param.y
#define CA_FI_INV_DIST g_Param.z

////////////////////////////////////////////////////////////////////////////////////////////////////
// C֐̒`
////////////////////////////////////////////////////////////////////////////////////////////////////

float4 main( PS_INPUT input ) : MSV_TARGET0
{
	float intensity = clamp( length( input.tex - CA_TEX_CENTER ) * CA_INV_LEN, 0.0, 1.0 );
	float4 output;
	
#if ENABLE_DEPTH
	intensity *= clamp( ( TEX_DEPTH( input.tex ).r - CA_FI_START ) * CA_FI_INV_DIST, 0.0, 1.0 );
#endif //ENABLE_DEPTH

	intensity = pow( abs( intensity ), CS_WEIGHT );
	
	output = TEX_COLOR0( input.tex ) + ( TEX_COLOR1( input.tex ) * 2.0 - 1.0 ) * intensity;
	output = max( 0.0, output );

	return output;
}
