fix : camera position is the same with model position
pull/2/head
ink-soul 2023-06-07 16:16:53 +08:00
parent 377b509cc5
commit 5a246f00a5
4 changed files with 16 additions and 62 deletions

View File

@ -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;

View File

@ -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 {

View File

@ -17,8 +17,6 @@
//#include "VulkanUtils.hpp"
//#include "assetLoader.h"
#include <VulkanTexture.hpp>
PlumageRender::PlumageRender()
@ -190,6 +188,7 @@ PlumageRender::PlumageRender()
}
}
void PlumageRender::loadScene(std::string filename)
{
std::cout << "Loading scene from " << filename << std::endl;
@ -200,7 +199,7 @@ PlumageRender::PlumageRender()
models.scene.loadFromFile(filename, vulkanDevice, queue);
auto tFileLoad = std::chrono::duration<double, std::milli>(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<VkDynamicState> dynamicStateEnables = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
VkPipelineDynamicStateCreateInfo dynamicStateCI = vks::initializers::pipelineDynamicStateCreateInfo(dynamicStateEnables.data(), static_cast<uint32_t>(dynamicStateEnables.size()), 0);
VkPipelineVertexInputStateCreateInfo emptyInputState = vks::initializers::pipelineVertexInputStateCreateInfo();
const std::string fragPath = ToneMapping ? filePath.tonemappingEnableFragShaderPath : filePath.tonemappingDisableFragShaderPath;
std::array<VkPipelineShaderStageCreateInfo, 2> 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<uint32_t>(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);
@ -1686,10 +1644,13 @@ PlumageRender::PlumageRender()
}
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

View File

@ -14,9 +14,7 @@
#include <vulkan/vulkan.h>
#include "VulkanExampleBase.h"
#include "glTFModel.h"
//#include "VulkanUtils.hpp"
#include <VulkanTexture.hpp>
//#include "assetLoader.h"
#include "VulkanDevice.hpp"
#include "ui.hpp"
#include <VulkanUtils.hpp>
@ -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);
};