diff --git a/data/shaders/skeletalanimation/mesh.vert b/data/shaders/skeletalanimation/mesh.vert index 073de04d..79abee9b 100644 --- a/data/shaders/skeletalanimation/mesh.vert +++ b/data/shaders/skeletalanimation/mesh.vert @@ -15,6 +15,7 @@ layout (location = 5) in ivec4 inBoneIDs; layout (binding = 0) uniform UBO { mat4 projection; + mat4 view; mat4 model; mat4 bones[MAX_BONES]; vec4 lightPos; @@ -29,24 +30,24 @@ layout (location = 4) out vec3 outLightVec; out gl_PerVertex { - vec4 gl_Position; + vec4 gl_Position; }; void main() { - mat4 boneTransform = ubo.bones[inBoneIDs[0]] * inBoneWeights[0]; - boneTransform += ubo.bones[inBoneIDs[1]] * inBoneWeights[1]; - boneTransform += ubo.bones[inBoneIDs[2]] * inBoneWeights[2]; - boneTransform += ubo.bones[inBoneIDs[3]] * inBoneWeights[3]; - + mat4 boneTransform = ubo.bones[inBoneIDs[0]] * inBoneWeights[0]; + boneTransform += ubo.bones[inBoneIDs[1]] * inBoneWeights[1]; + boneTransform += ubo.bones[inBoneIDs[2]] * inBoneWeights[2]; + boneTransform += ubo.bones[inBoneIDs[3]] * inBoneWeights[3]; + outNormal = inNormal; outColor = inColor; outUV = inUV; - gl_Position = ubo.projection * ubo.model * boneTransform * vec4(inPos.xyz, 1.0); + gl_Position = ubo.projection * ubo.view * ubo.model * boneTransform * vec4(inPos.xyz, 1.0); - vec4 pos = ubo.model * vec4(inPos, 1.0); + vec4 pos = ubo.model * vec4(inPos, 1.0); outNormal = mat3(inverse(transpose(ubo.model))) * inNormal; - outLightVec = ubo.lightPos.xyz - pos.xyz; - outViewVec = ubo.viewPos.xyz - pos.xyz; + outLightVec = ubo.lightPos.xyz - pos.xyz; + outViewVec = ubo.viewPos.xyz - pos.xyz; } \ No newline at end of file diff --git a/data/shaders/skeletalanimation/mesh.vert.spv b/data/shaders/skeletalanimation/mesh.vert.spv index d06ec857..76d380cf 100644 Binary files a/data/shaders/skeletalanimation/mesh.vert.spv and b/data/shaders/skeletalanimation/mesh.vert.spv differ diff --git a/data/shaders/skeletalanimation/texture.vert b/data/shaders/skeletalanimation/texture.vert index c194772d..fcddff4d 100644 --- a/data/shaders/skeletalanimation/texture.vert +++ b/data/shaders/skeletalanimation/texture.vert @@ -11,6 +11,7 @@ layout (binding = 0) uniform UBO { mat4 projection; mat4 model; + mat4 view; vec4 lightPos; vec4 viewPos; vec2 uvOffset; @@ -23,16 +24,16 @@ layout (location = 3) out vec3 outLightVec; out gl_PerVertex { - vec4 gl_Position; + vec4 gl_Position; }; void main() { outUV = inUV * 2.0 + ubo.uvOffset; vec4 pos = vec4(inPos, 1.0); - gl_Position = ubo.projection * ubo.model * vec4(pos); + gl_Position = ubo.projection * ubo.view * ubo.model * vec4(pos); - outNormal = mat3(ubo.model) * inNormal; - outLightVec = ubo.lightPos.xyz - pos.xyz; - outViewVec = ubo.viewPos.xyz - pos.xyz; + outNormal = mat3(ubo.model) * inNormal; + outLightVec = ubo.lightPos.xyz - pos.xyz; + outViewVec = ubo.viewPos.xyz - pos.xyz; } diff --git a/data/shaders/skeletalanimation/texture.vert.spv b/data/shaders/skeletalanimation/texture.vert.spv index c96943eb..ef7fae6f 100644 Binary files a/data/shaders/skeletalanimation/texture.vert.spv and b/data/shaders/skeletalanimation/texture.vert.spv differ diff --git a/skeletalanimation/skeletalanimation.cpp b/skeletalanimation/skeletalanimation.cpp index 4bccb211..e2858866 100644 --- a/skeletalanimation/skeletalanimation.cpp +++ b/skeletalanimation/skeletalanimation.cpp @@ -358,6 +358,7 @@ public: struct { glm::mat4 projection; glm::mat4 model; + glm::mat4 view; glm::mat4 bones[MAX_BONES]; glm::vec4 lightPos = glm::vec4(0.0f, -250.0f, 250.0f, 1.0); glm::vec4 viewPos; @@ -366,6 +367,7 @@ public: struct { glm::mat4 projection; glm::mat4 model; + glm::mat4 view; glm::vec4 lightPos = glm::vec4(0.0, 0.0f, -25.0f, 1.0); glm::vec4 viewPos; glm::vec2 uvOffset; @@ -407,16 +409,19 @@ public: // Clean up used Vulkan resources // Note : Inherited destructor cleans up resources stored in base class vkDestroyPipeline(device, pipelines.skinning, nullptr); + vkDestroyPipeline(device, pipelines.texture, nullptr); vkDestroyPipelineLayout(device, pipelineLayout, nullptr); vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr); - textureLoader->destroyTexture(textures.colorMap); + textureLoader->destroyTexture(textures.floor); vkTools::destroyUniformData(device, &uniformData.vsScene); + vkTools::destroyUniformData(device, &uniformData.floor); // Destroy and free mesh resources + vkMeshLoader::freeMeshBufferResources(device, &meshes.floor); vkMeshLoader::freeMeshBufferResources(device, &skinnedMesh->meshBuffer); delete(skinnedMesh->meshLoader); delete(skinnedMesh); @@ -951,15 +956,16 @@ public: viewMatrix = glm::rotate(viewMatrix, glm::radians(90.0f), glm::vec3(1.0f, 0.0f, 0.0f)); viewMatrix = glm::scale(viewMatrix, glm::vec3(0.025f)); - uboVS.model = viewMatrix * glm::translate(glm::mat4(), glm::vec3(cameraPos.x, -cameraPos.z, cameraPos.y) * 100.0f); - uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f)); - uboVS.model = glm::rotate(uboVS.model, glm::radians(rotation.z), glm::vec3(0.0f, 1.0f, 0.0f)); - uboVS.model = glm::rotate(uboVS.model, glm::radians(-rotation.y), glm::vec3(0.0f, 0.0f, 1.0f)); + uboVS.view = viewMatrix * glm::translate(glm::mat4(), glm::vec3(cameraPos.x, -cameraPos.z, cameraPos.y) * 100.0f); + uboVS.view = glm::rotate(uboVS.view, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f)); + uboVS.view = glm::rotate(uboVS.view, glm::radians(rotation.z), glm::vec3(0.0f, 1.0f, 0.0f)); + uboVS.view = glm::rotate(uboVS.view, glm::radians(-rotation.y), glm::vec3(0.0f, 0.0f, 1.0f)); uboVS.viewPos = glm::vec4(0.0f, 0.0f, -zoom, 0.0f); uboFloor.projection = uboVS.projection; - uboFloor.model = viewMatrix * glm::translate(glm::mat4(), glm::vec3(cameraPos.x, -cameraPos.z, cameraPos.y) * 100.0f); + uboFloor.view = viewMatrix; + uboFloor.model = glm::translate(glm::mat4(), glm::vec3(cameraPos.x, -cameraPos.z, cameraPos.y) * 100.0f); uboFloor.model = glm::rotate(uboFloor.model, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f)); uboFloor.model = glm::rotate(uboFloor.model, glm::radians(rotation.z), glm::vec3(0.0f, 1.0f, 0.0f)); uboFloor.model = glm::rotate(uboFloor.model, glm::radians(-rotation.y), glm::vec3(0.0f, 0.0f, 1.0f));