bug fix : crush when loading model with no material

pull/2/head
ink-soul 2023-06-02 16:40:03 +08:00
parent e1a8de6147
commit 5aeb1c1efc
3 changed files with 36 additions and 8 deletions

View File

@ -455,20 +455,36 @@ void VulkanglTFModel::drawNode(VkCommandBuffer commandBuffer, VkPipelineLayout p
// Get the texture index for this primitive // Get the texture index for this primitive
if (textures.size() > 0) if (textures.size() > 0)
{ {
VulkanglTFModel::Texture texture = textures[materials[primitive.materialIndex].baseColorTextureIndex]; //binding base color texture
auto normalMap = textures[materials[primitive.materialIndex].normalMapTextureIndex]; if (materials[primitive.materialIndex].baseColorTextureIndex < textures.size())
auto roughMetalMap = textures[materials[primitive.materialIndex].matalicRoughTextureIndex]; {
VulkanglTFModel::Texture texture = textures[materials[primitive.materialIndex].baseColorTextureIndex];
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 1, 1, &images[texture.imageIndex].descriptorSet, 0, nullptr);
if (materials[primitive.materialIndex].emissiveTextureIndex >= 0) }
//normal map binding
if (materials[primitive.materialIndex].normalMapTextureIndex < textures.size())
{
auto normalMap = textures[materials[primitive.materialIndex].normalMapTextureIndex];
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 2, 1, &images[normalMap.imageIndex].descriptorSet, 0, nullptr);
}
//rough map binding
if (materials[primitive.materialIndex].matalicRoughTextureIndex < textures.size())
{
auto roughMetalMap = textures[materials[primitive.materialIndex].matalicRoughTextureIndex];
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 3, 1, &images[roughMetalMap.imageIndex].descriptorSet, 0, nullptr);
}
//emissive texture binding
if (materials[primitive.materialIndex].emissiveTextureIndex >= 0 && materials[primitive.materialIndex].emissiveTextureIndex < textures.size())
{ {
auto emissiveMap = textures[materials[primitive.materialIndex].emissiveTextureIndex]; auto emissiveMap = textures[materials[primitive.materialIndex].emissiveTextureIndex];
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 4, 1, &images[emissiveMap.imageIndex].descriptorSet, 0, nullptr); vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 4, 1, &images[emissiveMap.imageIndex].descriptorSet, 0, nullptr);
} }
// Bind the descriptor for the current primitive's texture // Bind the descriptor for the current primitive's texture
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 1, 1, &images[texture.imageIndex].descriptorSet, 0, nullptr);
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 2, 1, &images[normalMap.imageIndex].descriptorSet, 0, nullptr);
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 3, 1, &images[roughMetalMap.imageIndex].descriptorSet, 0, nullptr);
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 5, 1, &materials[primitive.materialIndex].materialData.descriptorSet, 0, nullptr); vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 5, 1, &materials[primitive.materialIndex].materialData.descriptorSet, 0, nullptr);
} }
vkCmdDrawIndexed(commandBuffer, primitive.indexCount, 1, primitive.firstIndex, 0, 0); vkCmdDrawIndexed(commandBuffer, primitive.indexCount, 1, primitive.firstIndex, 0, 0);

View File

@ -6,6 +6,9 @@
#include <string.h> #include <string.h>
#include <vector> #include <vector>
#include <ktx.h>
#include <ktxvulkan.h>
#define GLM_FORCE_RADIANS #define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE #define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/glm.hpp> #include <glm/glm.hpp>

View File

@ -1667,14 +1667,23 @@ PlumageRender::PlumageRender():
loadAssets(); loadAssets();
} }
if(overlay->button("select vertexShader")) if(overlay->button("select vertex Shader"))
{ {
std::string strFilePath; std::string strFilePath;
strFilePath = guiFunc.openFileFolderDialog(); strFilePath = guiFunc.openFileFolderDialog();
filePath.modelVertShaderPath = strFilePath; filePath.modelVertShaderPath = strFilePath;
loadAssets(); loadAssets();
updateUniformBuffers();
}
if (overlay->button("select fragment Shader"))
{
std::string strFilePath;
strFilePath = guiFunc.openFileFolderDialog();
filePath.modelFragShaderPath = strFilePath;
loadAssets();
updateUniformBuffers();
} }
} }
} }