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 a7314f28..9fb3b8a6 100644 Binary files a/data/shaders/skeletalanimation/mesh.frag.spv and b/data/shaders/skeletalanimation/mesh.frag.spv differ 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 c53bebb7..8f45b833 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.frag.spv b/data/shaders/skeletalanimation/texture.frag.spv index 51fe7ddf..334dcfa4 100644 Binary files a/data/shaders/skeletalanimation/texture.frag.spv and b/data/shaders/skeletalanimation/texture.frag.spv differ diff --git a/data/shaders/skeletalanimation/texture.vert b/data/shaders/skeletalanimation/texture.vert index 9644f14e..88328eba 100644 --- a/data/shaders/skeletalanimation/texture.vert +++ b/data/shaders/skeletalanimation/texture.vert @@ -7,8 +7,8 @@ layout (location = 2) in vec2 inUV; layout (binding = 0) uniform UBO { mat4 projection; - mat4 model; mat4 view; + mat4 model; vec4 lightPos; vec4 viewPos; vec2 uvOffset; @@ -30,7 +30,7 @@ void main() vec4 pos = vec4(inPos, 1.0); gl_Position = ubo.projection * ubo.view * ubo.model * vec4(pos); - outNormal = mat3(ubo.model) * inNormal; + outNormal = 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 cf371af4..a8d7b980 100644 Binary files a/data/shaders/skeletalanimation/texture.vert.spv and b/data/shaders/skeletalanimation/texture.vert.spv differ 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