From 5a246f00a56fab833235b8002766e1c3d2212dd9 Mon Sep 17 00:00:00 2001 From: ink-soul Date: Wed, 7 Jun 2023 16:16:53 +0800 Subject: [PATCH] bug fix fix : camera position is the same with model position --- src/render/glTFModel.cpp | 1 + src/render/glTFModel.h | 2 +- src/render/render.cpp | 69 +++++++--------------------------------- src/render/render.h | 6 ++-- 4 files changed, 16 insertions(+), 62 deletions(-) diff --git a/src/render/glTFModel.cpp b/src/render/glTFModel.cpp index 332dcf7..ca51294 100644 --- a/src/render/glTFModel.cpp +++ b/src/render/glTFModel.cpp @@ -71,6 +71,7 @@ vkDestroySampler(device->logicalDevice, sampler, nullptr); } + void glTFModel::Texture::fromglTfImage(tinygltf::Image& gltfimage, glTFModel::TextureSampler textureSampler, vks::VulkanDevice* device, VkQueue copyQueue) { this->device = device; diff --git a/src/render/glTFModel.h b/src/render/glTFModel.h index bfcf0e5..65caf3f 100644 --- a/src/render/glTFModel.h +++ b/src/render/glTFModel.h @@ -77,7 +77,7 @@ namespace glTFModel void updateDescriptor(); void destroy(); // Load a texture from a glTF image (stored as vector of chars loaded via stb_image) and generate a full mip chaing for it - void fromglTfImage(tinygltf::Image& gltfimage, TextureSampler textureSampler, vks::VulkanDevice* device, VkQueue copyQueue); + void fromglTfImage(tinygltf::Image& gltfimage, glTFModel::TextureSampler textureSampler, vks::VulkanDevice* device, VkQueue copyQueue); }; struct Material { diff --git a/src/render/render.cpp b/src/render/render.cpp index fea4723..4df1473 100644 --- a/src/render/render.cpp +++ b/src/render/render.cpp @@ -17,8 +17,6 @@ //#include "VulkanUtils.hpp" //#include "assetLoader.h" -#include - PlumageRender::PlumageRender() @@ -189,6 +187,7 @@ PlumageRender::PlumageRender() VK_CHECK_RESULT(vkEndCommandBuffer(currentCB)); } } + void PlumageRender::loadScene(std::string filename) { @@ -200,7 +199,7 @@ PlumageRender::PlumageRender() models.scene.loadFromFile(filename, vulkanDevice, queue); auto tFileLoad = std::chrono::duration(std::chrono::high_resolution_clock::now() - tStart).count(); std::cout << "Loading took " << tFileLoad << " ms" << std::endl; - camera.setPosition({ 0.0f, 0.0f, 1.0f }); + camera.setPosition({ 0.0f, 0.0f, -1.0f }); camera.setRotation({ 0.0f, 0.0f, 0.0f }); } @@ -654,47 +653,6 @@ PlumageRender::PlumageRender() //Create Tone Mapping render pipeline //CreateToneMappingPipeline(); } - /* TODO :reconstruct with new pipeline - void PlumageRender::CreateToneMappingPipeline() - { - if (pipelines.toneMapping != VK_NULL_HANDLE) - { - vkDestroyPipeline(device, pipelines.toneMapping, nullptr); - pipelines.toneMapping = VK_NULL_HANDLE; - } - VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateCI = vks::initializers::pipelineInputAssemblyStateCreateInfo(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, 0, VK_FALSE); - VkPipelineRasterizationStateCreateInfo rasterizationStateCI = vks::initializers::pipelineRasterizationStateCreateInfo(VK_POLYGON_MODE_FILL, VK_CULL_MODE_NONE, VK_FRONT_FACE_COUNTER_CLOCKWISE, 0); - VkPipelineColorBlendAttachmentState blendAttachmentStateCI = vks::initializers::pipelineColorBlendAttachmentState(0xf, VK_FALSE); - VkPipelineColorBlendStateCreateInfo colorBlendStateCI = vks::initializers::pipelineColorBlendStateCreateInfo(1, &blendAttachmentStateCI); - VkPipelineDepthStencilStateCreateInfo depthStencilStateCI = vks::initializers::pipelineDepthStencilStateCreateInfo(VK_FALSE, VK_FALSE, VK_COMPARE_OP_LESS_OR_EQUAL); - VkPipelineViewportStateCreateInfo viewportStateCI = vks::initializers::pipelineViewportStateCreateInfo(1, 1, 0); - VkPipelineMultisampleStateCreateInfo multisampleStateCI = vks::initializers::pipelineMultisampleStateCreateInfo(VK_SAMPLE_COUNT_1_BIT, 0); - const std::vector dynamicStateEnables = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR }; - VkPipelineDynamicStateCreateInfo dynamicStateCI = vks::initializers::pipelineDynamicStateCreateInfo(dynamicStateEnables.data(), static_cast(dynamicStateEnables.size()), 0); - VkPipelineVertexInputStateCreateInfo emptyInputState = vks::initializers::pipelineVertexInputStateCreateInfo(); - - - const std::string fragPath = ToneMapping ? filePath.tonemappingEnableFragShaderPath : filePath.tonemappingDisableFragShaderPath; - std::array shaderStages = { - loadShader(device,filePath.tonemappingVertShaderPath, VK_SHADER_STAGE_VERTEX_BIT), - loadShader(device,fragPath, VK_SHADER_STAGE_FRAGMENT_BIT) - }; - - VkGraphicsPipelineCreateInfo pipelineCI = vks::initializers::pipelineCreateInfo(pipelineLayouts.tonemappingLayout, renderPass, 0); - pipelineCI.pVertexInputState = &emptyInputState; - pipelineCI.pInputAssemblyState = &inputAssemblyStateCI; - pipelineCI.pRasterizationState = &rasterizationStateCI; - pipelineCI.pColorBlendState = &colorBlendStateCI; - pipelineCI.pMultisampleState = &multisampleStateCI; - pipelineCI.pViewportState = &viewportStateCI; - pipelineCI.pDepthStencilState = &depthStencilStateCI; - pipelineCI.pDynamicState = &dynamicStateCI; - pipelineCI.stageCount = static_cast(shaderStages.size()); - pipelineCI.pStages = shaderStages.data(); - - VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCI, nullptr, &pipelines.toneMapping)); - } - */ // generate two cube maps // irradiance cube map @@ -1561,7 +1519,7 @@ PlumageRender::PlumageRender() camera.setPerspective(45.0f, (float)width / (float)height, 0.1f, 256.0f); camera.rotationSpeed = 0.25f; camera.movementSpeed = 0.1f; - camera.setPosition({ 0.0f, 0.0f, 1.0f }); + camera.setPosition({ 0.0f, 0.0f, -1.0f }); camera.setRotation({ 0.0f, 0.0f, 0.0f }); waitFences.resize(renderAhead); @@ -1683,13 +1641,16 @@ PlumageRender::PlumageRender() if (camera.updated) { updateUniformBuffers(); } - + } - void PlumageRender::viewChanged() - { - updateUniformBuffers(); - } + void PlumageRender::fileDropped(std::string filename) + { + vkDeviceWaitIdle(device); + loadScene(filename); + setupDescriptors(); + buildCommandBuffers(); + } void PlumageRender::updateUIOverlay() { @@ -1853,13 +1814,7 @@ PlumageRender::PlumageRender() } - void PlumageRender::fileDropped(std::string filename) - { - vkDeviceWaitIdle(device); - loadScene(filename); - setupDescriptors(); - buildCommandBuffers(); - } + PlumageRender* plumageRender; // OS specific macros for the example main entry points diff --git a/src/render/render.h b/src/render/render.h index 817160e..004807b 100644 --- a/src/render/render.h +++ b/src/render/render.h @@ -14,9 +14,7 @@ #include #include "VulkanExampleBase.h" #include "glTFModel.h" -//#include "VulkanUtils.hpp" #include -//#include "assetLoader.h" #include "VulkanDevice.hpp" #include "ui.hpp" #include @@ -307,7 +305,7 @@ public: void windowResized(); void prepare(); virtual void render(); - virtual void viewChanged(); + //virtual void viewChanged(); virtual void updateUIOverlay(); - void fileDropped(std::string filename); + virtual void fileDropped(std::string filename); }; \ No newline at end of file