Skeletalanimation fix (#671)

* Fixed anc code cleanup for skeletal animation

Refs #669

* Fix android build
This commit is contained in:
Sascha Willems 2020-02-20 14:25:29 +01:00 committed by GitHub
parent fcb0a2a46a
commit d1fbf8d00a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 26 additions and 37 deletions

View file

@ -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

View file

@ -18,7 +18,7 @@ void main()
vec3 L = normalize(inLightVec); vec3 L = normalize(inLightVec);
vec3 V = normalize(inViewVec); vec3 V = normalize(inViewVec);
vec3 R = reflect(-L, N); 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); vec3 specular = pow(max(dot(R, V), 0.0), 32.0) * vec3(0.5);
outFragColor = vec4(diffuse * color.rgb + specular, 1.0); outFragColor = vec4(diffuse * color.rgb + specular, 1.0);
} }

View file

@ -43,7 +43,7 @@ void main()
gl_Position = ubo.projection * ubo.view * 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 * boneTransform))) * inNormal; outNormal = mat3(boneTransform) * inNormal;
outLightVec = ubo.lightPos.xyz - pos.xyz; outLightVec = ubo.lightPos.xyz - pos.xyz;
outViewVec = ubo.viewPos.xyz - pos.xyz; outViewVec = ubo.viewPos.xyz - pos.xyz;
} }

View file

@ -7,8 +7,8 @@ layout (location = 2) in vec2 inUV;
layout (binding = 0) uniform UBO layout (binding = 0) uniform UBO
{ {
mat4 projection; mat4 projection;
mat4 model;
mat4 view; mat4 view;
mat4 model;
vec4 lightPos; vec4 lightPos;
vec4 viewPos; vec4 viewPos;
vec2 uvOffset; vec2 uvOffset;
@ -30,7 +30,7 @@ void main()
vec4 pos = vec4(inPos, 1.0); vec4 pos = vec4(inPos, 1.0);
gl_Position = ubo.projection * ubo.view * ubo.model * vec4(pos); gl_Position = ubo.projection * ubo.view * ubo.model * vec4(pos);
outNormal = mat3(ubo.model) * inNormal; outNormal = inNormal;
outLightVec = ubo.lightPos.xyz - pos.xyz; outLightVec = ubo.lightPos.xyz - pos.xyz;
outViewVec = ubo.viewPos.xyz - pos.xyz; outViewVec = ubo.viewPos.xyz - pos.xyz;
} }

View file

@ -365,7 +365,7 @@ public:
shaderStage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; shaderStage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
shaderStage.stage = VK_SHADER_STAGE_COMPUTE_BIT; shaderStage.stage = VK_SHADER_STAGE_COMPUTE_BIT;
#if defined(VK_USE_PLATFORM_ANDROID_KHR) #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 #else
shaderStage.module = vks::tools::loadShader((getAssetPath() + "shaders/computeheadless/headless.comp.spv").c_str(), device); shaderStage.module = vks::tools::loadShader((getAssetPath() + "shaders/computeheadless/headless.comp.spv").c_str(), device);
#endif #endif

View file

@ -598,8 +598,8 @@ public:
shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
shaderStages[1].pName = "main"; shaderStages[1].pName = "main";
#if defined(VK_USE_PLATFORM_ANDROID_KHR) #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[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[1].module = vks::tools::loadShader(androidapp->activity->assetManager, (getAssetPath() + "shaders/renderheadless/triangle.frag.spv").c_str(), device);
#else #else
shaderStages[0].module = vks::tools::loadShader((getAssetPath() + "shaders/renderheadless/triangle.vert.spv").c_str(), device); 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); shaderStages[1].module = vks::tools::loadShader((getAssetPath() + "shaders/renderheadless/triangle.frag.spv").c_str(), device);

View file

@ -367,8 +367,8 @@ public:
struct { struct {
glm::mat4 projection; glm::mat4 projection;
glm::mat4 model;
glm::mat4 view; glm::mat4 view;
glm::mat4 model;
glm::mat4 bones[MAX_BONES]; glm::mat4 bones[MAX_BONES];
glm::vec4 lightPos = glm::vec4(0.0f, -250.0f, 250.0f, 1.0); glm::vec4 lightPos = glm::vec4(0.0f, -250.0f, 250.0f, 1.0);
glm::vec4 viewPos; glm::vec4 viewPos;
@ -376,8 +376,8 @@ public:
struct { struct {
glm::mat4 projection; glm::mat4 projection;
glm::mat4 model;
glm::mat4 view; glm::mat4 view;
glm::mat4 model;
glm::vec4 lightPos = glm::vec4(0.0, 0.0f, -25.0f, 1.0); glm::vec4 lightPos = glm::vec4(0.0, 0.0f, -25.0f, 1.0);
glm::vec4 viewPos; glm::vec4 viewPos;
glm::vec2 uvOffset; glm::vec2 uvOffset;
@ -405,13 +405,13 @@ public:
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION) 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)"; title = "Skeletal animation (GPU skinning)";
cameraPos = { 0.0f, 0.0f, 12.0f };
settings.overlay = true; 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() ~VulkanExample()
@ -933,27 +933,20 @@ public:
{ {
if (viewChanged) 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)); uboVS.projection = camera.matrices.perspective;
viewMatrix = glm::rotate(viewMatrix, glm::radians(90.0f), glm::vec3(1.0f, 0.0f, 0.0f)); uboVS.view = camera.matrices.view;
viewMatrix = glm::scale(viewMatrix, glm::vec3(0.025f)); 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); uboFloor.projection = camera.matrices.perspective;
uboVS.view = glm::rotate(uboVS.view, glm::radians(rotation.x), glm::vec3(1.0f, 0.0f, 0.0f)); uboFloor.view = camera.matrices.view;
uboVS.view = glm::rotate(uboVS.view, glm::radians(rotation.z), glm::vec3(0.0f, 1.0f, 0.0f)); uboFloor.model = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 4.5f, 0.0f));
uboVS.view = glm::rotate(uboVS.view, glm::radians(-rotation.y), glm::vec3(0.0f, 0.0f, 1.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);
uboVS.viewPos = glm::vec4(0.0f, 0.0f, -zoom, 0.0f); uboFloor.viewPos = glm::vec4(camera.position, 0.0f) * glm::vec4(-1.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);
} }
// Update bones // Update bones