Split model and view matrix for clarity, destroy Vulkan resources
This commit is contained in:
parent
d7725c9b79
commit
62cc1faf33
5 changed files with 29 additions and 21 deletions
|
|
@ -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;
|
||||
}
|
||||
Binary file not shown.
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue