precision highp float; uniform mat4 ModelMatrix; // uniform mat4 Modelview; uniform mat4 View; uniform mat4 Projection; //uniform mat4 MVP; #ifdef HAS_JOINTS // The client should pass in an appropriate value for MAX_JOINTS. // #define MAX_JOINTS 96 // // matnxm -- n columns and m rows, different convention from math. // We don't need the last row of [0, 0, 0, 1], so drop it to pack the matrices // as tightly as possible. // 256 joints * 4x4 matrix * 4 bytes/float = 16.0KB // 256 joints * 4x3 matrix * 4 bytes/float = 12.0KB // 96 joints * 4x4 matrix * 4 bytes/float = 6.0KB // 96 joints * 4x3 matrix * 4 bytes/float = 4.5KB //uniform mat4x3 Joints[MAX_JOINTS]; uniform mat4 JointMatrices[MAX_JOINTS]; // Use 4x4 for now to keep it simple. #endif layout (location = 0) in vec3 vPosition; #ifdef HAS_NORMALS layout (location = 1) in vec3 vNormal; #endif #ifdef HAS_TANGENTS layout (location = 2) in vec4 vTangent; #endif #ifdef HAS_TEXCOORDS layout (location = 3) in vec2 vTexcoord; #endif #ifdef HAS_JOINTS layout (location = 4) in uvec4 vJoint; layout (location = 5) in vec4 vWeight; #endif // World-space position, normal and tangent. out vec3 Position; #ifdef HAS_NORMALS out vec3 Normal; #endif #ifdef HAS_TANGENTS out vec4 Tangent; #endif #ifdef HAS_TEXCOORDS out vec2 Texcoord; #endif void main() { #ifdef HAS_JOINTS mat4 skinMatrix = vWeight.x * JointMatrices[vJoint.x] + vWeight.y * JointMatrices[vJoint.y] + vWeight.z * JointMatrices[vJoint.z] + vWeight.w * JointMatrices[vJoint.w]; Position = vec3(ModelMatrix * skinMatrix * vec4(vPosition, 1.0)); #else Position = vec3(ModelMatrix * vec4(vPosition, 1.0)); #endif #ifdef HAS_NORMALS Normal = mat3(ModelMatrix) * vNormal; //Normal = normalize(ModelMatrix * vec4(vNormal, 0.0)).xyz; #endif #ifdef HAS_TANGENTS Tangent = vec4(mat3(ModelMatrix) * vTangent.xyz, vTangent.w); #endif #ifdef HAS_TEXCOORDS Texcoord = vTexcoord; #endif gl_Position = Projection * View * vec4(Position, 1.0); //gl_Position = Projection * vec4(Position, 1.0); //gl_Position = MVP * vec4(vPosition, 1.0); }