#version 300 es
precision highp float;
precision highp int;
//Uniform count: projectionMatrix(16) + modelViewMatrix(16) + MVPMatrix(16) + textureMatrix(16) + normalMatrix(9) + lightMVPMatrices(16*5) + nShadowLights(1) + boneMatrices(16*boneMax) = 73 + 1 + 16*shadowLightMax + 16*boneMax = (out of ~1024 components)
//GLSL ES (vectors): projectionMatrix(4) + modelViewMatrix(4) + MVPMatrix(4) + textureMatrix(4) + normalMatrix(3) + lightMVPMatrices(4*5) + nShadowLights(1) + boneMatrices(4*boneMax) = 19 + 4*shadowLightMax + 4*boneMax = 239 out of 256 vectors on Nexus 5 (shadowLightMax = 5, boneMax = 50, 17 vec4s remain, or 4 matrices and 1 vec4)
//Matrices
//uniform mat4 projectionMatrix;
uniform mat4 modelViewMatrix;
uniform mat4 MVPMatrix;
uniform mat4 textureMatrix;
uniform mat3 normalMatrix;
uniform mat4 lightMVPMatrices[5];
uniform int nShadowLights;
//Bones
uniform mat4 boneMatrices[50];
//Vertex information
in vec3 position;
in vec4 colour;
in vec2 texCoord;
in vec3 normal;
in vec3 boneWeights;
in ivec4 boneIndices;
out vec4 _colour;
out vec2 _texCoord;
out vec3 _normal;
out vec3 _eyePos;
out vec4 _lightPos[5];
void main(void)
{
vec4 positionSkinned;
vec4 normalSkinned;
mat4 matTransform = boneMatrices[boneIndices[0]] * boneWeights[0];
matTransform += boneMatrices[boneIndices[1]] * boneWeights[1];
matTransform += boneMatrices[boneIndices[2]] * boneWeights[2];
float finalWeight = 1.0 - (boneWeights[0] + boneWeights[1] + boneWeights[2]);
matTransform += boneMatrices[boneIndices[3]] * finalWeight;
positionSkinned = matTransform * vec4(position, 1.0);
//positionSkinned.w = 1.0;
normalSkinned = matTransform * vec4(normal, 0.0);
gl_Position = MVPMatrix * positionSkinned;
_colour = colour;
_texCoord = (textureMatrix * vec4(texCoord, 0.0, 1.0)).xy;
_normal = normalize(normalMatrix * normalize(normalSkinned.xyz));
_eyePos = (modelViewMatrix * positionSkinned).xyz;
for(int i = 0; i < nShadowLights; i++)
_lightPos[i] = lightMVPMatrices[i] * positionSkinned;
}
_colour = vec4(float(boneIndices[0]), float(boneIndices[1]), float(boneIndices[2]), float(boneIndices[3]));
gl_FragColor = _colour
_colour = vec4(boneWeights[0], boneWeights[1], boneWeights[2], finalWeight);