uniform float4x4 	matViewProjection;
uniform float3x4	matArrayBones[60];

static const int  BONES_PER_VERTEX = 4;
static const int  NUM_LIGHTS = 2;

struct VS_INPUT 
{
	float4 position		: POSITION0;
	float2 uv			: TEXCOORD0;
	float3 normal 		: NORMAL0;
	
	float4 blendIdx		: BLENDINDICES;
	float4 blendWeight	: BLENDWEIGHT;
};

struct VS_OUTPUT 
{
	float4 position 					: POSITION0;
	float2 uv		 					: TEXCOORD0;
	float4 color						: COLOR0;
};

uniform float3 wsLightDir[NUM_LIGHTS];

VS_OUTPUT main_vs( VS_INPUT input )
{
	VS_OUTPUT output;
	
	output.uv = input.uv;
	
	// transform by indexed matrix
    float4 blendedPos = float4(0,0,0,0);
    for ( int i = 0; i < BONES_PER_VERTEX; ++i)
    {
         blendedPos += float4( mul(matArrayBones[ input.blendIdx[i] ], input.position ).xyz, 1.0 ) * input.blendWeight[i];
    }

	output.position = mul( matViewProjection, blendedPos );

    float3 wsNormal = float3(0,0,0);
    for (int i = 0; i < BONES_PER_VERTEX; ++i)
    {
		wsNormal += mul( (float3x3)matArrayBones[ input.blendIdx[i] ], input.normal) * input.blendWeight[i];
    }
    
	float3 normal = normalize(wsNormal);
	float3 lightDir = normalize(wsLightDir[0]);

	float nDotL = dot(normal, lightDir); // these must be normalized for this to work
	float f = 0.6f + nDotL*0.4f; // give the dark side some light
	output.color = float4(f, f, f, 1);

	return output;
}
