diff --git a/src/render/glTFModel.cpp b/src/render/glTFModel.cpp index 9382e89..2d04a02 100644 --- a/src/render/glTFModel.cpp +++ b/src/render/glTFModel.cpp @@ -455,20 +455,36 @@ void VulkanglTFModel::drawNode(VkCommandBuffer commandBuffer, VkPipelineLayout p // Get the texture index for this primitive if (textures.size() > 0) { - VulkanglTFModel::Texture texture = textures[materials[primitive.materialIndex].baseColorTextureIndex]; - auto normalMap = textures[materials[primitive.materialIndex].normalMapTextureIndex]; - auto roughMetalMap = textures[materials[primitive.materialIndex].matalicRoughTextureIndex]; + //binding base color texture + if (materials[primitive.materialIndex].baseColorTextureIndex < textures.size()) + { + 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]; 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 - 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); } vkCmdDrawIndexed(commandBuffer, primitive.indexCount, 1, primitive.firstIndex, 0, 0); diff --git a/src/render/glTFModel.h b/src/render/glTFModel.h index 2db486e..098a63c 100644 --- a/src/render/glTFModel.h +++ b/src/render/glTFModel.h @@ -6,6 +6,9 @@ #include #include +#include +#include + #define GLM_FORCE_RADIANS #define GLM_FORCE_DEPTH_ZERO_TO_ONE #include diff --git a/src/render/render.cpp b/src/render/render.cpp index 3453de1..47e5a56 100644 --- a/src/render/render.cpp +++ b/src/render/render.cpp @@ -1667,14 +1667,23 @@ PlumageRender::PlumageRender(): loadAssets(); } - if(overlay->button("select vertexShader")) + if(overlay->button("select vertex Shader")) { std::string strFilePath; strFilePath = guiFunc.openFileFolderDialog(); filePath.modelVertShaderPath = strFilePath; loadAssets(); + updateUniformBuffers(); + } + if (overlay->button("select fragment Shader")) + { + std::string strFilePath; + strFilePath = guiFunc.openFileFolderDialog(); + filePath.modelFragShaderPath = strFilePath; + loadAssets(); + updateUniformBuffers(); } } }