varying vec2 TexCoord0;
varying vec4 ViewCoords;
varying vec3 LightDir, HalfVec;

uniform vec3 Eng_LocalLighting;
uniform vec3 Eng_LocalCameraPos;
uniform mat4 Eng_Bones[16];

attribute vec3 TSM0, TSM1, TSM2;
attribute float Bone1, Bone2, Bone1Weight;

void main()
{
	TexCoord0 = gl_MultiTexCoord0.xy;
	mat3 TangentSpaceMatrix = mat3(TSM0, TSM1, TSM2);

 	vec4 v1 = gl_Vertex;
	vec4 v2 = gl_Vertex;

/*	if (Bone1 > -0.1)
	{*/
		int b1 = int(Bone1);
        v1 = Eng_Bones[b1] * gl_Vertex;
 /*	}

	if (Bone2 > -0.1)
	{*/
		int b2 = int(Bone2);
        v2 = Eng_Bones[b2] * gl_Vertex;
 /*	}

	if (Bone1Weight >= 0.0)*/
		v1 = mix(v2, v1, Bone1Weight);



	/*Clr = vec4(0.0);
	if (int(Bone1) == 0)
		Clr.x = Bone1Weight;
	if (int(Bone1) == 1)
  		Clr.y = Bone1Weight;
	if (int(Bone1) == 2)
  		Clr.z = Bone1Weight;

	if (int(Bone2) == 0)
		Clr.x += 1.0 - Bone1Weight;
	if (int(Bone2) == 1)
  		Clr.y += 1.0 - Bone1Weight;
	if (int(Bone2) == 2)
  		Clr.z += 1.0 - Bone1Weight; */

	vec3 CamDir = TangentSpaceMatrix * normalize(Eng_LocalCameraPos - gl_Vertex.xyz);
	LightDir = TangentSpaceMatrix * Eng_LocalLighting;

	HalfVec = CamDir + LightDir;
	
	gl_Position = gl_ModelViewProjectionMatrix * v1;
	ViewCoords = gl_Position;
}
