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
|
layout (binding = 0) uniform UBO
|
||||||
{
|
{
|
||||||
mat4 projection;
|
mat4 projection;
|
||||||
|
mat4 view;
|
||||||
mat4 model;
|
mat4 model;
|
||||||
mat4 bones[MAX_BONES];
|
mat4 bones[MAX_BONES];
|
||||||
vec4 lightPos;
|
vec4 lightPos;
|
||||||
|
|
@ -43,7 +44,7 @@ void main()
|
||||||
outColor = inColor;
|
outColor = inColor;
|
||||||
outUV = inUV;
|
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;
|
outNormal = mat3(inverse(transpose(ubo.model))) * inNormal;
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -11,6 +11,7 @@ layout (binding = 0) uniform UBO
|
||||||
{
|
{
|
||||||
mat4 projection;
|
mat4 projection;
|
||||||
mat4 model;
|
mat4 model;
|
||||||
|
mat4 view;
|
||||||
vec4 lightPos;
|
vec4 lightPos;
|
||||||
vec4 viewPos;
|
vec4 viewPos;
|
||||||
vec2 uvOffset;
|
vec2 uvOffset;
|
||||||
|
|
@ -30,7 +31,7 @@ void main()
|
||||||
{
|
{
|
||||||
outUV = inUV * 2.0 + ubo.uvOffset;
|
outUV = inUV * 2.0 + ubo.uvOffset;
|
||||||
vec4 pos = vec4(inPos, 1.0);
|
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;
|
outNormal = mat3(ubo.model) * inNormal;
|
||||||
outLightVec = ubo.lightPos.xyz - pos.xyz;
|
outLightVec = ubo.lightPos.xyz - pos.xyz;
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -358,6 +358,7 @@ public:
|
||||||
struct {
|
struct {
|
||||||
glm::mat4 projection;
|
glm::mat4 projection;
|
||||||
glm::mat4 model;
|
glm::mat4 model;
|
||||||
|
glm::mat4 view;
|
||||||
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;
|
||||||
|
|
@ -366,6 +367,7 @@ public:
|
||||||
struct {
|
struct {
|
||||||
glm::mat4 projection;
|
glm::mat4 projection;
|
||||||
glm::mat4 model;
|
glm::mat4 model;
|
||||||
|
glm::mat4 view;
|
||||||
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;
|
||||||
|
|
@ -407,16 +409,19 @@ public:
|
||||||
// Clean up used Vulkan resources
|
// Clean up used Vulkan resources
|
||||||
// Note : Inherited destructor cleans up resources stored in base class
|
// Note : Inherited destructor cleans up resources stored in base class
|
||||||
vkDestroyPipeline(device, pipelines.skinning, nullptr);
|
vkDestroyPipeline(device, pipelines.skinning, nullptr);
|
||||||
|
vkDestroyPipeline(device, pipelines.texture, nullptr);
|
||||||
|
|
||||||
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
|
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
|
||||||
vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr);
|
vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr);
|
||||||
|
|
||||||
|
|
||||||
textureLoader->destroyTexture(textures.colorMap);
|
textureLoader->destroyTexture(textures.colorMap);
|
||||||
|
textureLoader->destroyTexture(textures.floor);
|
||||||
|
|
||||||
vkTools::destroyUniformData(device, &uniformData.vsScene);
|
vkTools::destroyUniformData(device, &uniformData.vsScene);
|
||||||
|
vkTools::destroyUniformData(device, &uniformData.floor);
|
||||||
|
|
||||||
// Destroy and free mesh resources
|
// Destroy and free mesh resources
|
||||||
|
vkMeshLoader::freeMeshBufferResources(device, &meshes.floor);
|
||||||
vkMeshLoader::freeMeshBufferResources(device, &skinnedMesh->meshBuffer);
|
vkMeshLoader::freeMeshBufferResources(device, &skinnedMesh->meshBuffer);
|
||||||
delete(skinnedMesh->meshLoader);
|
delete(skinnedMesh->meshLoader);
|
||||||
delete(skinnedMesh);
|
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::rotate(viewMatrix, glm::radians(90.0f), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||||
viewMatrix = glm::scale(viewMatrix, glm::vec3(0.025f));
|
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.view = 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.view = glm::rotate(uboVS.view, 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.view = glm::rotate(uboVS.view, 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 = 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);
|
uboVS.viewPos = glm::vec4(0.0f, 0.0f, -zoom, 0.0f);
|
||||||
|
|
||||||
uboFloor.projection = uboVS.projection;
|
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.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.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::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