
void SkinningFourWeightsTangentNormal_vp(
	float4 position : POSITION,
	float3 normal   : NORMAL,
	float3 tangent  : TANGENT,
	float2 uv       : TEXCOORD0,
	float4  blendIdx : BLENDINDICES,
	float4  blendWgt : BLENDWEIGHT,
	out float4 oPosition : POSITION,
	out float2 oUv       : TEXCOORD0,
	out float3 oLightDir : TEXCOORD1,
	out float3 oCamDir   : TEXCOORD2,
			uniform float3x4   worldMatrix3x4Array[24],
	uniform float4x4 viewProjectionMatrix,
	uniform float4   lightPos,
	uniform float4 camPos)
{
		float4 blendPos = float4(0,0,0,0);
	float3 norm = float3(0,0,0);
	float3 tang = float3(0,0,0);
	int i=0;
	for (i = 0; i < 4; i++)
	{
		blendPos += float4(mul(worldMatrix3x4Array[blendIdx[i]], position).xyz, 1.0) * blendWgt[i];
		norm += mul((float3x3)worldMatrix3x4Array[blendIdx[i]], normal) * blendWgt[i];
		tang += mul((float3x3)worldMatrix3x4Array[blendIdx[i]], tangent) * blendWgt[i];
	}
	norm = normalize(norm);
	tang = normalize(tang);
		oPosition = mul(viewProjectionMatrix, blendPos);
		
	
		float3 binormal = cross(tang, norm);
	float3 lightDir = lightPos.xyz -  (blendPos.xyz * lightPos.w);
	oLightDir = mul(float3x3(tang,binormal,norm),lightDir);
	float3 camDir = camPos.xyz - blendPos.xyz;
	oCamDir = mul(float3x3(tang,binormal,norm),camDir);
	oUv = uv;
}	
void SkinningFourWeightsTangentNormal_fp(
	float2 uv		: TEXCOORD0,
	float3 lightDir	: TEXCOORD1,
	float3 camDir	: TEXCOORD2,
	
	out float4 color	: COLOR,
	
	uniform float4 lightDiffuse,
	uniform float4 lightSpec,
	uniform float4 ambient,
	uniform sampler2D normalMap,
	uniform sampler2D diffuseMap,
	uniform sampler2D specMap
	)
{
	float3 lightVec = normalize(lightDir);
	float3 bumpVec = tex2D(normalMap, uv).xyz * 2.0f - 1.0f;
	float4 diffuseColor = tex2D(diffuseMap, uv);
	float NdotL = dot(bumpVec, lightVec);
   	float3 reflection = normalize(  (2.0f * bumpVec * NdotL ) - lightVec ); 
   	float3 viewDir = normalize( camDir );
   	float RdotV = max( 0.0f, dot( reflection, viewDir ) );
   	float4 specMod = tex2D(specMap, uv);
	float4 totalDiffuse = diffuseColor * NdotL * lightDiffuse;
	float4 totalAmbient = ambient * diffuseColor;
	float4 totalSpecular = lightSpec * pow(RdotV, 25.0f) * specMod;
	color = saturate(totalAmbient + totalDiffuse + totalSpecular);
}
void SkinningFourWeightsShadowCaster(
	float4 position : POSITION,
	float4  blendIdx : BLENDINDICES,
	float4  blendWgt : BLENDWEIGHT,
	out float4 oPosition : POSITION,
	out float4 colour    : COLOR,
			uniform float3x4   worldMatrix3x4Array[24],
	uniform float4x4 viewProjectionMatrix,
	uniform float4   ambient)
{
		float4 blendPos = float4(0,0,0,0);
	int i=0;
	for (i = 0; i < 4; i++)
	{
		blendPos += float4(mul(worldMatrix3x4Array[blendIdx[i]], position).xyz, 1.0) * blendWgt[i];
	}
		oPosition = mul(viewProjectionMatrix, blendPos);
	
	colour = ambient;
	
}