//Fragment Shader

// Note how the fragment struct was simply copied from our vertex shader code.
// This is necessary if we want to use a vertex and pixel shader together.

struct fragment
{
    float3 color0	:	COLOR0;
    float2 texcoord0	:	TEXCOORD0;
    float3 normal	:	TEXCOORD1;
    float4 objectPos	:	TEXCOORD2;
    float2 texcoord3	:	TEXCOORD3;
	float4 objectPos2	:	TEXCOORD4;
	float3 Light2color	:	TEXCOORD5;
};

struct pixel
{
    float4 color : COLOR;
};

pixel main( 
    fragment IN, 
    uniform float3	globalAmbient,
    uniform float3	paraLightColor,
    uniform float3	paraLightDirection,
    uniform float3	eyePosition,
	uniform float4x4 Worldmatrix,
//    uniform float3	Ke,
//    uniform float3	Ka,
//    uniform float3	Kd,
//    uniform float3	Ks,

//	uniform float	testnum,
//    uniform float	shininess,
    uniform sampler2D	testTexture,
    uniform sampler2D	ShadowMapTexture,
	uniform samplerCUBE	AmbientReflectiveTexture,
	uniform sampler2D	NormalMapTexture,
	uniform sampler2D	SpecularMapTexture
)
{

	float4 MainColor=tex2D( testTexture, IN.texcoord0 );
    float3 N =  normalize(IN.normal);

    float3 L = normalize(paraLightDirection);
	float DotNaL=dot(N, L);
    float diffuseLight = max(DotNaL, 0.0);
    float3 diffuse = paraLightColor * diffuseLight;

    float3 V = normalize(eyePosition);
    float3 H = normalize(L + V);
	float DotNaH=dot(N, H);
	float MaxNaH0=max(DotNaH,0.0);
    float specularLight = pow(MaxNaH0, 50.0);


    if(diffuseLight<=0.0) specularLight=0.0;
    float4 Ocolor;
    Ocolor.xyz = globalAmbient +IN.Light2color+ diffuse+specularLight*8.0;
    Ocolor.w = 1.0;
    pixel OUT;

	OUT.color = MainColor*Ocolor;
	OUT.color.w=0.5;

    return OUT;
}
