//================================================================
//大域設定値
//Texture
sampler sampler0_ : register(s0);

const float SCREEN_WIDTH = 640;
const float SCREEN_HEIGHT = 480;

texture textureMask_;
sampler samplerMask_ = sampler_state
{ 
	Texture = <textureMask_>;
};

//--------------------------------
float y_;	// エフェクト終了位置

//================================================================
//--------------------------------
//ピクセルシェーダ入力値
struct PS_INPUT
{
	float4 diffuse : COLOR0;  //ディフューズ色
	float2 texCoord : TEXCOORD0; //テクスチャ座標
	float2 vPos : VPOS; //描画先座標
};

//--------------------------------
//ピクセルシェーダ出力値
struct PS_OUTPUT
{
    float4 color : COLOR0; //出力色
};


//================================================================
// シェーダ
//--------------------------------
//ピクセルシェーダ
PS_OUTPUT PsLesstone( PS_INPUT In ) : COLOR0
{
	PS_OUTPUT Out;

	//テクスチャの色
	float4 colorTexture = tex2D(sampler0_, In.texCoord);

	//頂点ディフーズ色
	float4 colorDiffuse = In.diffuse;

	//合成
	float4 color = colorTexture * colorDiffuse;
	Out.color = color;

	if(color.a > 0)
	{
		//--------------------------------
		//マスク用のテクスチャから色成分を取得
		float2 maskUV  = float2(In.vPos.x/SCREEN_WIDTH+y_*2.0f, (In.vPos.y/SCREEN_HEIGHT+2.0f-y_*2.0f)/3.0f);
		float2 maskUV2 = float2(In.vPos.x/SCREEN_WIDTH-y_*2.0f, (In.vPos.y/SCREEN_HEIGHT+2.0f-y_*2.0f)/3.0f);

		//描画先からマスク用テクスチャの位置を計算
		float4 colorMask = max(tex2D(samplerMask_, maskUV), tex2D(samplerMask_, maskUV2));
		float4 power = ( colorMask.r + colorMask.g + colorMask.b ) * 0.3333f;

		Out.color.rgb = ((color.r*0.3f + color.g*0.7f) * power + color.rgb * (1.0f-power));
		Out.color.g *= (1.0f-power*0.3f);
		Out.color.b *= (1.0f-power*0.5f);
	}

	return Out;
}


//================================================================
//--------------------------------
//technique
technique TecLesstone
{
	pass P0
	{
		PixelShader = compile ps_3_0 PsLesstone();
	}
}

