#version 330 layout (location = 0) in vec3 inPosition; layout (location = 1) in vec2 inCoord; layout (location = 2) in vec3 inNormal; layout (location = 3) in ivec4 BoneIDs; layout (location = 4) in vec4 Weights; smooth out vec3 vNormal; smooth out vec2 vTexCoord; smooth out vec3 vWorldPos; smooth out vec4 vEyeSpacePos; uniform struct Matrices { mat4 projMatrix; mat4 modelMatrix; mat4 viewMatrix; mat4 normalMatrix; } matrices; const int MAX_BONES = 100; uniform mat4 gBones[MAX_BONES]; void main() { mat4 BoneTransform = gBones[BoneIDs[0]] * Weights[0]; BoneTransform += gBones[BoneIDs[1]] * Weights[1]; BoneTransform += gBones[BoneIDs[2]] * Weights[2]; BoneTransform += gBones[BoneIDs[3]] * Weights[3]; mat4 m_MV = matrices.viewMatrix*matrices.modelMatrix; mat4 m_MVP = matrices.projMatrix*matrices.viewMatrix*matrices.modelMatrix; vTexCoord = inCoord; vec4 m_transPos = BoneTransform * vec4(inPosition, 1.0); vEyeSpacePos = m_MV * m_transPos; gl_Position = m_MVP * m_transPos; vec4 m_normal = BoneTransform * vec4(inNormal, 1.0); vNormal = (matrices.modelMatrix * m_normal).xyz; vWorldPos = (matrices.modelMatrix * m_transPos).xyz; }

void Sprite::Draw() { glBindVertexArray(g_VAO); g_mainSP.UseProgram(); g_mainSP.SetUniform("matrices.projMatrix", g_projMat); g_mainSP.SetUniform("matrices.viewMatrix", g_viewMat); g_mainSP.SetModelAndNormalMatrix("matrices.modelMatrix", "matrices.normalMatrix", g_modelMat); for (uint i = 0; i < g_transforms.size(); i++) { g_mainSP.SetBoneTransform(i, g_transforms[i]); } g_mainSP.SetUniform("gSampler", 0); g_mainSP.SetUniform("vColor", glm::vec4(1, 1, 1, 1)); g_ambient.SetUniformData(&g_mainSP, "sunLight"); if (!g_loaded)return; for (uint i = 0; i < g_subMeshes.size(); i++) { const uint m_matIndex = g_subMeshes[i].materialIndex; g_textures[m_matIndex].BindTexture(); aiMesh* m_mesh = g_scene->mMeshes[i]; glDrawElementsBaseVertex(GL_TRIANGLES, g_subMeshes[i].numIndices, GL_UNSIGNED_INT, (void*)(sizeof(uint)* g_subMeshes[i].baseIndex), g_subMeshes[i].baseVertex); } glBindVertexArray(0); }

void ShaderProgram::SetBoneTransform(glm::uint p_index, const glm::mat4& p_transform) { glUniformMatrix4fv(g_boneLoc[p_index], 1, GL_TRUE, glm::value_ptr<GLfloat>(p_transform)); }