
//================================================================
//ݒl
//Texture
sampler sampler0_ : register(s0);

//--------------------------------
//䂪ݐpp[^
static const float RENDER_WIDTH = 512; //_OeNX`̕
static const float RENDER_HEIGHT = 512; //_OeNX`̍

const float ALPHA_MAX = 255;
float frame_; //t[
float enemyX_; //G̈ʒuX
float enemyY_; //G̈ʒuY
float waveRadius_; //GtFNg̔a

float waveC_R; //GtFNg̐FXCb` 
float waveC_G; //GtFNg̐FXCb` 
float waveC_B; //GtFNg̐FXCb` 


//================================================================
//--------------------------------
//sNZVF[_͒l
struct PS_INPUT
{
	float4 diffuse : COLOR0;  //fBt[YF
	float2 texCoord : TEXCOORD0; //eNX`W
	float2 vPos : VPOS; //`W
};

//--------------------------------
//sNZVF[_o͒l
struct PS_OUTPUT
{
    float4 color : COLOR0; //o͐F
};


//================================================================
// VF[_
//--------------------------------
//sNZVF[_
PS_OUTPUT PsWave( PS_INPUT In ) : COLOR0
{
	PS_OUTPUT Out;

		//--------------------------------
		//炬vZ
		float dist = sqrt((enemyX_-In.vPos.x+0.5)*(enemyX_-In.vPos.x+0.5) + (enemyY_-In.vPos.y+0.5)*(enemyY_-In.vPos.y+0.5)+waveRadius_);
		float distY = enemyY_ - In.vPos.y + 0.5;
		float cosTheta = (In.vPos.x - enemyX_) / dist;
		float sinTheta = (In.vPos.y - enemyY_) / dist;
	
		//cݍ쐬psinɎgppxp[^
		float angle = In.vPos.y - enemyY_ + In.vPos.x - enemyX_ - frame_*5;
		float angle2 = angle;
		angle = radians(angle);
		
	
		//S狗قǉe
		float powerRatio = ( waveRadius_ - dist) / waveRadius_;
		if(powerRatio >= 0.6){powerRatio = 0.6;}
		if(powerRatio < 0){powerRatio = 0;}
		//YsNZ̘c݂̔avZ
		//GtFNga1/16ő̘cݕƂ
		float waveRadius_Circle =  powerRatio*1.2+sin(angle)+exp(pow((1.5,dist)*5,2)*(-3));
		float waveRadius = waveRadius_* waveRadius_Circle;
		
		
		//F擾ʒũoCAXl(炬̋Œ)
		float biasRadiusX = -4-abs(cos(angle)*waveRadius/2 * (1/8 - powerRatio/8))*powerRatio;
		float biasRadiusY = -4-abs(sin(angle)*waveRadius/2 * (1/8 - powerRatio/8))*powerRatio;
		float biasX = biasRadiusX * cosTheta*powerRatio*2;
		float biasY = biasRadiusY * sinTheta*powerRatio*2;
	
		//eNX`̐F擾ʒu
		float2 texUV;
		texUV.x = biasX / RENDER_WIDTH + In.texCoord.x;
		texUV.y = biasY / RENDER_HEIGHT + In.texCoord.y;
		texUV.y = texUV.y+sin(angle)*powerRatio/32;
	
		//--------------------------------
		//eNX`̐F
		float4 colorTexture = tex2D(sampler0_, texUV);
	
		//_fBt[YF
		float4 colorDiffuse = In.diffuse;
	
		//
		float4 color = colorTexture * colorDiffuse;
		
		//xϊ
		waveC_R = (1-waveC_R/255);
		waveC_G = (1-waveC_G/255);
		waveC_B = (1-waveC_B/255);
		
		//FԂۂω
		if(powerRatio > 0)
		{
			color.r = color.r * (1 - waveC_R)-waveRadius_Circle*powerRatio/32;
			color.g = color.g * (1 - waveC_G)-waveRadius_Circle*powerRatio/32;
			color.b = color.b * (1 - waveC_B)-waveRadius_Circle*powerRatio/32;
		}
		Out.color = color;
		float Alpha = powerRatio*2*color.a;
		
		if(Alpha>=ALPHA_MAX)
		{
			Alpha = ALPHA_MAX;
		}
		Out.color.a = Alpha;

	return Out;
}


//================================================================
//--------------------------------
//technique
technique TecWave
{
	pass P0
	{
		PixelShader = compile ps_3_0 PsWave();
	}
}

