//varying vec3 normal;
//varying vec4 color;

#vertexshader

const int NUMBONES = 40;
uniform mat4 Bones[NUMBONES];
uniform vec4 Colors[NUMBONES];

//attribute vec4 Vertex;

varying vec3 NormalOut;
varying vec3 VertexToLight;
varying vec4 ColorOut;

void main()
{
	vec4 Pos0 = vec4(gl_Vertex.xyz, 1.0);
	int index = int(gl_Vertex.w);

	mat4 Bone = Bones[index];
	vec4 Pos = Bone * Pos0;

	gl_Position = gl_ModelViewProjectionMatrix * Pos;
	Bone[3][0] = 0.0;
	Bone[3][1] = 0.0;
	Bone[3][2] = 0.0;
	NormalOut = gl_NormalMatrix * normalize((Bone * vec4(gl_Normal,1)).xyz);
	
	ColorOut = Colors[index];
	gl_TexCoord[0] = gl_MultiTexCoord0;
	gl_TexCoord[1] = gl_MultiTexCoord1;
	
	vec4 VertexModelView = gl_ModelViewMatrix * Pos;
	VertexToLight = (gl_ModelViewMatrix * vec4(100.0,100.0,100.0,1.0) - VertexModelView).xyz;
	gl_TexCoord[0] = gl_MultiTexCoord0;
}

#fragmentshader

varying vec3 NormalOut;
varying vec3 VertexToLight;
varying vec4 ColorOut;
//uniform sampler2D texture;
//uniform float texfade;

void main()
{
	vec3 LightDir = normalize(VertexToLight);
	vec3 Normal = normalize(NormalOut);
	vec3 Col = ColorOut.xyz;//lerp(ColorOut.xyz,texture2D(texture, gl_TexCoord[0].xy).xyz,texfade);
	vec3 c = clamp(dot(LightDir, Normal),0.0,1.0) * 0.3 + Col.xyz * 0.7;
	gl_FragColor = vec4(c,1);
}
