From d1fbf8d00ab44a9b67bae8342ee52353354e8bfa Mon Sep 17 00:00:00 2001 From: Sascha Willems Date: Thu, 20 Feb 2020 14:25:29 +0100 Subject: [PATCH] Skeletalanimation fix (#671) * Fixed anc code cleanup for skeletal animation Refs #669 * Fix android build --- .../skeletalanimation/generate-spirv.bat | 4 -- data/shaders/skeletalanimation/mesh.frag | 2 +- data/shaders/skeletalanimation/mesh.frag.spv | Bin 2016 -> 2068 bytes data/shaders/skeletalanimation/mesh.vert | 2 +- data/shaders/skeletalanimation/mesh.vert.spv | Bin 4708 -> 4612 bytes .../skeletalanimation/texture.frag.spv | Bin 1840 -> 1840 bytes data/shaders/skeletalanimation/texture.vert | 4 +- .../skeletalanimation/texture.vert.spv | Bin 2656 -> 2404 bytes examples/computeheadless/computeheadless.cpp | 2 +- examples/renderheadless/renderheadless.cpp | 4 +- .../skeletalanimation/skeletalanimation.cpp | 45 ++++++++---------- 11 files changed, 26 insertions(+), 37 deletions(-) delete mode 100644 data/shaders/skeletalanimation/generate-spirv.bat diff --git a/data/shaders/skeletalanimation/generate-spirv.bat b/data/shaders/skeletalanimation/generate-spirv.bat deleted file mode 100644 index b39535ff..00000000 --- a/data/shaders/skeletalanimation/generate-spirv.bat +++ /dev/null @@ -1,4 +0,0 @@ -glslangvalidator -V mesh.vert -o mesh.vert.spv -glslangvalidator -V mesh.frag -o mesh.frag.spv -glslangvalidator -V texture.vert -o texture.vert.spv -glslangvalidator -V texture.frag -o texture.frag.spv \ No newline at end of file diff --git a/data/shaders/skeletalanimation/mesh.frag b/data/shaders/skeletalanimation/mesh.frag index d57b22ff..4b652205 100644 --- a/data/shaders/skeletalanimation/mesh.frag +++ b/data/shaders/skeletalanimation/mesh.frag @@ -18,7 +18,7 @@ void main() vec3 L = normalize(inLightVec); vec3 V = normalize(inViewVec); vec3 R = reflect(-L, N); - vec3 diffuse = max(dot(N, L), 0.0) * vec3(1.0);// * inColor; + vec3 diffuse = max(dot(N, L), 0.1) * vec3(1.0) * inColor; vec3 specular = pow(max(dot(R, V), 0.0), 32.0) * vec3(0.5); outFragColor = vec4(diffuse * color.rgb + specular, 1.0); } \ No newline at end of file diff --git a/data/shaders/skeletalanimation/mesh.frag.spv b/data/shaders/skeletalanimation/mesh.frag.spv index a7314f28db7b86b427fca2c003e34bed5418f1c4..9fb3b8a6d860569eb8eea3b6ac8c2a4c782eca3d 100644 GIT binary patch delta 587 zcmYk2y-EX75QXPvW1?WtLPZoIV4)BTJ7Z#gjJg{Cl7Jv$C1N3@@CWN)5iA5DY~Ccb zZxG+Xcd)V${Eprg?{c_j&di-Tv+ooA$xM(~Oq)3ynXmFDCuNsU=mfmtn%Yrk=2h3pi3OUZx8@@|JX z02r~NkHhFScy@(BJvpD~lo0he4`x6YLyFhI8jxP5#j4lh`XX@-#PJ4v3G{y!lCFVf z(#ILE1uDRSWuQC@cK(u^J~_v&!YX+2X13wlPBk*4e<&>;z6+N@#oBZajDZG!Udz$s?HDdiBVw)LHH~ayP!^j& U@2OwFr`asfZXvglU$n@BZZDn^~!Md7Jz(O z w23$Vrm+4APxO9D)b_|!M=$UqsY98kWd6eiB=sx}>lVKicm6%h_Uq(dW4;O$de*gdg diff --git a/data/shaders/skeletalanimation/mesh.vert b/data/shaders/skeletalanimation/mesh.vert index 16bc938e..b634de07 100644 --- a/data/shaders/skeletalanimation/mesh.vert +++ b/data/shaders/skeletalanimation/mesh.vert @@ -43,7 +43,7 @@ void main() gl_Position = ubo.projection * ubo.view * ubo.model * boneTransform * vec4(inPos.xyz, 1.0); vec4 pos = ubo.model * vec4(inPos, 1.0); - outNormal = mat3(inverse(transpose(ubo.model * boneTransform))) * inNormal; + outNormal = mat3(boneTransform) * inNormal; 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 c53bebb71802c074e066e0822a311826f46dc260..8f45b83334af71fde0f14b9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?b7t<$+`0Re{G5whq1A|pl88j5>&CmWvWQdw$9){82gAGG zJ)9}AWd=3`JokGq;{LwRGqe9t8$JzgnS&HtD&B{hRgV9yUeyW{mH`EnB^;EcZ)xB0 z-z;AxSabv7BgQJ@DfnefC&a? z6LV%CoOO61bLIe?IxvFyf9Mbz53!IrbOcVF;KzcDH}G`a;xWKsSe&`M1P43;xKS6E zpnnQ5mwH|bmh5Sfo8UUD05`!kvj}fq1E`x}>RPLL<7g_~fR~<#Ho>Viyv{!xdCH7RrcfWKy8eb?E-%X CdPFq< diff --git a/examples/computeheadless/computeheadless.cpp b/examples/computeheadless/computeheadless.cpp index afdb0dda..cab4bfed 100644 --- a/examples/computeheadless/computeheadless.cpp +++ b/examples/computeheadless/computeheadless.cpp @@ -365,7 +365,7 @@ public: shaderStage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; shaderStage.stage = VK_SHADER_STAGE_COMPUTE_BIT; #if defined(VK_USE_PLATFORM_ANDROID_KHR) - shaderStage.module = vks::tools::loadShader(androidapp->activity->assetManager, (getAssetPath() + "shaders/computeheadless/headless.comp.spv".c_str(), device); + shaderStage.module = vks::tools::loadShader(androidapp->activity->assetManager, (getAssetPath() + "shaders/computeheadless/headless.comp.spv").c_str(), device); #else shaderStage.module = vks::tools::loadShader((getAssetPath() + "shaders/computeheadless/headless.comp.spv").c_str(), device); #endif diff --git a/examples/renderheadless/renderheadless.cpp b/examples/renderheadless/renderheadless.cpp index 8d30d90f..ee279e29 100644 --- a/examples/renderheadless/renderheadless.cpp +++ b/examples/renderheadless/renderheadless.cpp @@ -598,8 +598,8 @@ public: shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; shaderStages[1].pName = "main"; #if defined(VK_USE_PLATFORM_ANDROID_KHR) - shaderStages[0].module = vks::tools::loadShader(androidapp->activity->assetManager, (getAssetPath() + "shaders/renderheadless/triangle.vert.spv".c_str(), device); - shaderStages[1].module = vks::tools::loadShader(androidapp->activity->assetManager, (getAssetPath() + "shaders/renderheadless/triangle.frag.spv".c_str(), device); + shaderStages[0].module = vks::tools::loadShader(androidapp->activity->assetManager, (getAssetPath() + "shaders/renderheadless/triangle.vert.spv").c_str(), device); + shaderStages[1].module = vks::tools::loadShader(androidapp->activity->assetManager, (getAssetPath() + "shaders/renderheadless/triangle.frag.spv").c_str(), device); #else shaderStages[0].module = vks::tools::loadShader((getAssetPath() + "shaders/renderheadless/triangle.vert.spv").c_str(), device); shaderStages[1].module = vks::tools::loadShader((getAssetPath() + "shaders/renderheadless/triangle.frag.spv").c_str(), device); diff --git a/examples/skeletalanimation/skeletalanimation.cpp b/examples/skeletalanimation/skeletalanimation.cpp index de2035be..c49ecb5f 100644 --- a/examples/skeletalanimation/skeletalanimation.cpp +++ b/examples/skeletalanimation/skeletalanimation.cpp @@ -367,8 +367,8 @@ public: struct { glm::mat4 projection; - glm::mat4 model; glm::mat4 view; + glm::mat4 model; glm::mat4 bones[MAX_BONES]; glm::vec4 lightPos = glm::vec4(0.0f, -250.0f, 250.0f, 1.0); glm::vec4 viewPos; @@ -376,8 +376,8 @@ public: struct { glm::mat4 projection; - glm::mat4 model; glm::mat4 view; + glm::mat4 model; glm::vec4 lightPos = glm::vec4(0.0, 0.0f, -25.0f, 1.0); glm::vec4 viewPos; glm::vec2 uvOffset; @@ -405,13 +405,13 @@ public: VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) { - zoom = -150.0f; - zoomSpeed = 2.5f; - rotationSpeed = 0.5f; - rotation = { -182.5f, -38.5f, 180.0f }; title = "Skeletal animation (GPU skinning)"; - cameraPos = { 0.0f, 0.0f, 12.0f }; settings.overlay = true; + camera.type = Camera::CameraType::lookat; + camera.setPerspective(60.0f, (float)width / (float)height, 1.0f, 512.0f); + camera.setRotation(glm::vec3(-182.5f, -38.5f, 180.0f)); + camera.setRotation(glm::vec3(0.0f, 135.0f, 0.0f)); + camera.setPosition(glm::vec3(0.0f, 0.0f, -20.0f)); } ~VulkanExample() @@ -933,27 +933,20 @@ public: { if (viewChanged) { - uboVS.projection = glm::perspective(glm::radians(60.0f), (float)width / (float)height, 0.1f, 1024.0f); + const glm::vec3 scale = glm::vec3(0.0025f); - glm::mat4 viewMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, zoom)); - 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.projection = camera.matrices.perspective; + uboVS.view = camera.matrices.view; + uboVS.viewPos = glm::vec4(camera.position, 0.0f) * glm::vec4(-1.0f); + uboVS.model = glm::rotate(glm::mat4(1.0f), glm::radians(90.0f), glm::vec3(1.0f, 0.0f, 0.0f)); + uboVS.model = glm::scale(uboVS.model, scale); - uboVS.view = viewMatrix * glm::translate(glm::mat4(1.0f), 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.view = viewMatrix; - uboFloor.model = glm::translate(glm::mat4(1.0f), 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)); - uboFloor.model = glm::translate(uboFloor.model, glm::vec3(0.0f, 0.0f, -1800.0f)); - uboFloor.viewPos = glm::vec4(0.0f, 0.0f, -zoom, 0.0f); + uboFloor.projection = camera.matrices.perspective; + uboFloor.view = camera.matrices.view; + uboFloor.model = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 4.5f, 0.0f)); + uboFloor.model = glm::rotate(uboFloor.model, glm::radians(90.0f), glm::vec3(1.0f, 0.0f, 0.0f)); + uboFloor.model = glm::scale(uboFloor.model, scale); + uboFloor.viewPos = glm::vec4(camera.position, 0.0f) * glm::vec4(-1.0f); } // Update bones