//precision mediump float;
//precision lowp int;
uniform mat4 u_mvpMatrix;
uniform mat4 u_mvMatrix;
uniform mat4 u_mBonePalette[64];
uniform vec3 u_LightPos;		// light in eye space.
attribute vec4 a_vertex;
attribute vec2 a_texture;
attribute vec4 a_infIdx;
attribute vec3 a_normal;
varying vec4	v_col;
varying vec2	v_texture;
void main()
	{
	// --- Skinning
	ivec4 iCurIndex = ivec4(a_infIdx);
	vec4 vTP = u_mBonePalette[iCurIndex.x] * a_vertex;
	vec3 vTN = vec3(u_mBonePalette[iCurIndex.x] * vec4(a_normal, 0.0));

	// --- Lighting
	vec3 V = vec3(u_mvMatrix * vTP);
	vec3 N = vec3(u_mvMatrix * vec4(vTN, 0));
	vec3 L = normalize(u_LightPos - V);
	float d = max(dot(N, L), 0.2) + 0.2;
	
	// --- Send to Frag
	v_texture = a_texture;
	v_col = vec4(d,d,d,1);
	
	gl_Position = u_mvpMatrix * vTP;
	}