#version 150 in vec3 position; in vec2 texCoord; in vec3 normal; in vec4 tangent; in vec4 color; in vec4 boneID; in vec4 boneWeight; #define BONE_COUNT_MAX 120 uniform mat4 projectionTransform; uniform mat4 viewTransform; uniform mat4 modelTransform; uniform mat3 normalMatrix; uniform vec4 materialColor; layout (std140) uniform boneTransformBlock { mat4 boneTransforms[BONE_COUNT_MAX]; }; out vec3 vertPosition; out vec2 vertTexCoord; out mat3 vertTBNMatrix; out vec4 vertColor; void main() { vec4 weightedPosition = boneTransforms[int(boneID.x)] * vec4(position, 1.0) * boneWeight.x; weightedPosition += boneTransforms[int(boneID.y)] * vec4(position, 1.0) * boneWeight.y; weightedPosition += boneTransforms[int(boneID.z)] * vec4(position, 1.0) * boneWeight.z; weightedPosition += boneTransforms[int(boneID.w)] * vec4(position, 1.0) * boneWeight.w; weightedPosition /= weightedPosition.w; vertPosition = vec3(modelTransform * weightedPosition); vec3 weightedNormal = mat3(boneTransforms[int(boneID.x)]) * normal * boneWeight.x; weightedNormal += mat3(boneTransforms[int(boneID.y)]) * normal * boneWeight.y; weightedNormal += mat3(boneTransforms[int(boneID.z)]) * normal * boneWeight.z; weightedNormal += mat3(boneTransforms[int(boneID.w)]) * normal * boneWeight.w; vec3 orientedNormal = normalMatrix * weightedNormal; vec3 tangentXYZ = normalMatrix * tangent.xyz; vec3 bitangent = tangent.w * cross(orientedNormal, tangentXYZ); vertTBNMatrix = mat3(tangentXYZ, bitangent, orientedNormal); vertTexCoord = texCoord; vertColor = color * materialColor; gl_Position = projectionTransform * viewTransform * modelTransform * weightedPosition; }