//BackGround BEGIN
float4 PosArr[16];
float4 ColArr[16];
int LCount = 0;
texture Tex0;
texture Tex0NM;
float Mag = 1;

sampler SampTex0 = sampler_state {
    Texture = <Tex0>;
};

sampler SampTex0Nm = sampler_state {
    Texture = <Tex0NM>;
};

struct TPSInput {
	float4 Pos: Position0;
	float4 Dif: Color0;
	float3 Tex0: TexCoord0;
	float3 Tex1: TexCoord1;
};

float4 PShaderBG (const in TPSInput Input, uniform int LightCount): COLOR0 {   
	float4 Tex1 = tex2D(SampTex0, Input.Tex0);
	float4 Tex1Nm = tex2D(SampTex0Nm, Input.Tex0);
	float3 Norm = float3(Tex1Nm.xyz * 2 - 1) * Mag;

	float3 Dir;
	float3 DirN;
	float Light;
	float Dist;
	float3 Col = float3(0, 0, 0);
	for (int i = 0; i < LightCount; i++) {
		Dir = PosArr[i].xyz - Input.Tex1;
		DirN = normalize(Dir);
		Light = saturate(dot(DirN, Norm));
		Dist = 1 - min(Dir.x * Dir.x + Dir.y * Dir.y, PosArr[i].w) / PosArr[i].w;
		Col += ColArr[i].xyz * Light * Dist;
	}

	return float4(Tex1.xyz * saturate(Col.xyz + 0.1), 1);
}

PixelShader psArray[6] = {
	compile ps_2_0 PShaderBG(0), 
    compile ps_2_0 PShaderBG(1),
    compile ps_2_0 PShaderBG(2),
    compile ps_2_0 PShaderBG(3),
	compile ps_2_0 PShaderBG(4),
	compile ps_2_0 PShaderBG(5)
};

technique RenderBG {
	pass P0 {
		PixelShader = (psArray[LCount]);
	}
}
//BackGround END