sampler2D Tex0;	// basetex
sampler2D Tex2;	// shininessmap
sampler2D Tex7;	// bumpmap

samplerCUBE ReflectionTex;

float3 Half;
float3 FogColor;

struct PS_INPUT{
	float4 Diff				: COLOR0;
	float3 Depth			: COLOR1;
	
	float2 BaseTex			: TEXCOORD0;
	float3 ViewDir			: TEXCOORD1;
	
	float2 BumpTex0			: TEXCOORD2;
	float2 BumpTex1			: TEXCOORD3;
	
	float FogIntensity		: TEXCOORD4;
};

struct PS_OUTPUT{
    float4 Color			: COLOR;
};

PS_OUTPUT main(const PS_INPUT Input){
	// Compute normal
	float3 N0 = (tex2D(Tex7, Input.BumpTex0) - 0.5f) * 2;
	float3 N1 = (tex2D(Tex7, Input.BumpTex1) - 0.5f) * 2;
	
	float3 N = normalize(N0 + N1);
	float3 V = normalize(Input.ViewDir);

	// Compute lighting
	float3 R = 2 * dot(N, V) * N - V;
		
	// Compute result
	float3 ShininessMap = tex2D(Tex2, Input.BaseTex);
	
	R.z *= -1;
	float3 Result = texCUBE(ReflectionTex, R) * ShininessMap;
	
	float3 BaseTexColor = tex2D(Tex0, Input.BaseTex);
	
	float3 TexColor = BaseTexColor + Result;
	//TexColor += FogColor * Input.FogIntensity;
	//TexColor = lerp(TexColor, FogColor, Input.FogIntensity);

	PS_OUTPUT Out;
	Out.Color.rgb = TexColor;
	Out.Color.a = 0.5f;
	return Out;
}