diff --git a/base/vulkanexamplebase.h b/base/vulkanexamplebase.h index 2805225..8a7b941 100644 --- a/base/vulkanexamplebase.h +++ b/base/vulkanexamplebase.h @@ -82,8 +82,7 @@ public: static std::vector args; uint32_t selectedPhysicalDeviceIndex = 0; bool prepared = false; - uint32_t width = 1280; - uint32_t height = 720; + float frameTimer = 1.0f; Camera camera; glm::vec2 mousePos; @@ -102,6 +101,8 @@ public: }signal; struct Settings { + uint32_t width = 1280; + uint32_t height = 720; bool validation = true; // 校验层开关 bool fullscreen = false; // 全屏开关 bool vsync = false; // 垂直同步开关 @@ -118,6 +119,60 @@ public: VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_4_BIT; // 多重采样倍率 } settings; + + struct FilePath + { //model path + std::string glTFModelFilePath = getAssetPath() + "models/DamagedHelmet/DamagedHelmet.gltf"; + std::string modelVertShaderPath = getAssetPath() + "buster_drone/shaders/glsl/mesh.vert.spv"; + std::string modelFragShaderPath = getAssetPath() + "buster_drone/shaders/glsl/mesh.frag.spv"; + + //ui + std::string uiVertShaderPath = getAssetPath() + "shaders/ui.vert.spv"; + std::string uiFragShaderPath = getAssetPath() + "shaders/ui.frag.spv"; + + // skybox path + std::string skyboxModleFilePath = getAssetPath() + "models/cube.gltf"; + std::string skyboxVertShaderPath = getAssetPath() + "shaders/skybox.vert.spv"; + std::string skyboxFragShaderPath = getAssetPath() + "shaders/skybox.frag.spv"; + + std::string iblTexturesFilePath = getAssetPath() + "textures/hdr/gcanyon_cube.ktx"; + //tonemapping + std::string tonemappingVertShaderPath = getAssetPath() + "buster_drone/shaders/glsl/genbrdflut.vert.spv"; + std::string tonemappingEnableFragShaderPath = getAssetPath() + "buster_drone/shaders/glsl/tonemapping_enable.frag.spv"; + std::string tonemappingDisableFragShaderPath = getAssetPath() + "buster_drone/shaders/glsl/tonemapping_disable.frag.spv"; + + + // cube map + std::string irradianceFragShaderPath = getAssetPath() + "shaders/irradiancecube.frag.spv"; + + std::string filterVertShaderPath = getAssetPath() + "shaders/filtercube.vert.spv"; + + std::string prefilterEnvmapFragShaderPath = getAssetPath() + "shaders/prefilterenvmap.frag.spv"; + //brdf cube map + std::string brdfVertShaderPath = getAssetPath() + "shaders/genbrdflut.vert.spv"; + std::string brdfFragShaderPath = getAssetPath() + "shaders/genbrdflut.frag.spv"; + // environment map texture + std::string envMapFilePath = getAssetPath() + "environments/metro_noord_4k_hdr16f_cube.ktx"; + std::string emptyEnvmapFilePath = getAssetPath() + "textures/empty.ktx"; + // pbr shader + std::string pbrVertShaderPath = getAssetPath() + "shaders/pbr.vert.spv"; + std::string pbrFragShaderPath = getAssetPath() + "shaders/pbr_khr.frag.spv"; + + //ttf file path + std::string ttfFilePath = getAssetPath() + "/data/Roboto-Medium.ttf"; + + // output file path + + std::string imageOutputPath = getAssetPath() + "output/imageSequence"; + std::string videoOutputPath = getAssetPath() + "output/video"; + std::string totalImageOutputPath; + std::string deviceSpecFilePath; + + // script file path + std::string image2videoBatFilePath = getAssetPath() + "script/image2video.bat"; + std::string image2videoShFilePath = getAssetPath() + "script/image2video.sh"; + + } filePath; struct DepthStencil { VkImage image; diff --git a/data/config/config.json b/data/config/config.json new file mode 100644 index 0000000..54b49f2 --- /dev/null +++ b/data/config/config.json @@ -0,0 +1,12 @@ +{ + "setting":{ + "width":1280, + "height":720 + }, + "filePath":{ + "glTFModelFilePath":"models/DamagedHelmet/DamagedHelmet.gltf", + "envMapFilePath":"environments/metro_noord_4k_hdr16f_cube.ktx", + "imageOutputPath":"output/imageSequence", + "videoOutputPath":"output/video" + } +} \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b76bdd3..662877a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -34,7 +34,7 @@ function(buildHomework HOMEWORK_NAME) "render/glTFModel.h" "render/glTFModel.cpp" - "render/renderFoundation.h" "render/renderFoundation.cpp") + "render/renderFoundation.h" "render/renderFoundation.cpp" "render/renderConfig.cpp" "render/renderConfig.h") target_link_libraries(${HOMEWORK_NAME} base ${Vulkan_LIBRARY}) else(WIN32) add_executable(${HOMEWORK_NAME} ${MAIN_CPP} ${SOURCE} ${MAIN_HEADER} ${SHADERS_GLSL} ${SHADERS_HLSL} ${README_FILES}) diff --git a/src/render/render.cpp b/src/render/render.cpp index e841a33..ac844b4 100644 --- a/src/render/render.cpp +++ b/src/render/render.cpp @@ -125,8 +125,8 @@ PlumageRender::PlumageRender() renderPassBeginInfo.renderPass = renderPass; renderPassBeginInfo.renderArea.offset.x = 0; renderPassBeginInfo.renderArea.offset.y = 0; - renderPassBeginInfo.renderArea.extent.width = width; - renderPassBeginInfo.renderArea.extent.height = height; + renderPassBeginInfo.renderArea.extent.width = settings.width; + renderPassBeginInfo.renderArea.extent.height = settings.height; renderPassBeginInfo.clearValueCount = settings.multiSampling ? 3 : 2; renderPassBeginInfo.pClearValues = clearValues; @@ -141,14 +141,14 @@ PlumageRender::PlumageRender() vkCmdBeginRenderPass(currentCB, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE); VkViewport viewport{}; - viewport.width = (float)width; - viewport.height = (float)height; + viewport.width = (float)settings.width; + viewport.height = (float)settings.height; viewport.minDepth = 0.0f; viewport.maxDepth = 1.0f; vkCmdSetViewport(currentCB, 0, 1, &viewport); VkRect2D scissor{}; - scissor.extent = { width, height }; + scissor.extent = { settings.width, settings.height }; vkCmdSetScissor(currentCB, 0, 1, &scissor); VkDeviceSize offsets[1] = { 0 }; @@ -1544,7 +1544,7 @@ PlumageRender::PlumageRender() camera.type = Camera::CameraType::lookat; - camera.setPerspective(45.0f, (float)width / (float)height, 0.1f, 256.0f); + camera.setPerspective(45.0f, (float)settings.width / (float)settings.height, 0.1f, 256.0f); camera.rotationSpeed = 0.25f; camera.movementSpeed = 0.1f; @@ -1647,8 +1647,8 @@ PlumageRender::PlumageRender() imageCreateCI.imageType = VK_IMAGE_TYPE_2D; // Note that vkCmdBlitImage (if supported) will also do format conversions if the swapchain color format would differ imageCreateCI.format = colorFormat; - imageCreateCI.extent.width = width; - imageCreateCI.extent.height = height; + imageCreateCI.extent.width = settings.width; + imageCreateCI.extent.height = settings.height; imageCreateCI.extent.depth = 1; imageCreateCI.arrayLayers = 1; imageCreateCI.mipLevels = 1; @@ -1702,8 +1702,8 @@ PlumageRender::PlumageRender() { // Define the region to blit (we will blit the whole swapchain image) VkOffset3D blitSize; - blitSize.x = width; - blitSize.y = height; + blitSize.x = settings.width; + blitSize.y = settings.height; blitSize.z = 1; VkImageBlit imageBlitRegion{}; imageBlitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; @@ -1730,8 +1730,8 @@ PlumageRender::PlumageRender() imageCopyRegion.srcSubresource.layerCount = 1; imageCopyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; imageCopyRegion.dstSubresource.layerCount = 1; - imageCopyRegion.extent.width = width; - imageCopyRegion.extent.height = height; + imageCopyRegion.extent.width = settings.width; + imageCopyRegion.extent.height = settings.height; imageCopyRegion.extent.depth = 1; // Issue the copy command @@ -1782,14 +1782,14 @@ PlumageRender::PlumageRender() if (settings.outputPNGimage) { - stbi_write_png(filePath.c_str(), width, height, 4, data, static_cast(subResourceLayout.rowPitch)); + stbi_write_png(filePath.c_str(), settings.width, settings.height, 4, data, static_cast(subResourceLayout.rowPitch)); } else { std::ofstream file(filePath, std::ios::out | std::ios::binary); // ppm header - file << "P6\n" << width << "\n" << height << "\n" << 255 << "\n"; + file << "P6\n" << settings.width << "\n" << settings.height << "\n" << 255 << "\n"; // If source is BGR (destination is always RGB) and we can't use blit (which does automatic conversion), we'll have to manually swizzle color components bool colorSwizzle = false; @@ -1803,10 +1803,10 @@ PlumageRender::PlumageRender() } // ppm binary pixel data - for (uint32_t y = 0; y < height; y++) + for (uint32_t y = 0; y < settings.height; y++) { unsigned int* row = (unsigned int*)data; - for (uint32_t x = 0; x < width; x++) + for (uint32_t x = 0; x < settings.width; x++) { if (colorSwizzle) { @@ -2082,7 +2082,7 @@ PlumageRender::PlumageRender() ImGuiIO& io = ImGui::GetIO(); ImVec2 lastDisplaySize = io.DisplaySize; - io.DisplaySize = ImVec2((float)width, (float)height); + io.DisplaySize = ImVec2((float)settings.width, (float)settings.height); io.DeltaTime = frameTimer; io.MousePos = ImVec2(mousePos.x, mousePos.y); diff --git a/src/render/render.h b/src/render/render.h index 119bae7..17c112b 100644 --- a/src/render/render.h +++ b/src/render/render.h @@ -127,59 +127,7 @@ public: float alphaMaskCutoff; } pushConstBlockMaterial; - struct FilePath - { //model path - std::string glTFModelFilePath = getAssetPath() + "models/DamagedHelmet/DamagedHelmet.gltf"; - std::string modelVertShaderPath = getAssetPath() + "buster_drone/shaders/glsl/mesh.vert.spv"; - std::string modelFragShaderPath = getAssetPath() + "buster_drone/shaders/glsl/mesh.frag.spv"; - - //ui - std::string uiVertShaderPath = getAssetPath() + "shaders/ui.vert.spv"; - std::string uiFragShaderPath = getAssetPath() + "shaders/ui.frag.spv"; - - // skybox path - std::string skyboxModleFilePath = getAssetPath() + "models/cube.gltf"; - std::string skyboxVertShaderPath = getAssetPath() + "shaders/skybox.vert.spv"; - std::string skyboxFragShaderPath = getAssetPath() + "shaders/skybox.frag.spv"; - - std::string iblTexturesFilePath = getAssetPath() + "textures/hdr/gcanyon_cube.ktx"; - //tonemapping - std::string tonemappingVertShaderPath = getAssetPath() + "buster_drone/shaders/glsl/genbrdflut.vert.spv"; - std::string tonemappingEnableFragShaderPath = getAssetPath() + "buster_drone/shaders/glsl/tonemapping_enable.frag.spv"; - std::string tonemappingDisableFragShaderPath = getAssetPath() + "buster_drone/shaders/glsl/tonemapping_disable.frag.spv"; - - - // cube map - std::string irradianceFragShaderPath = getAssetPath() + "shaders/irradiancecube.frag.spv"; - - std::string filterVertShaderPath = getAssetPath() + "shaders/filtercube.vert.spv"; - - std::string prefilterEnvmapFragShaderPath = getAssetPath() + "shaders/prefilterenvmap.frag.spv"; - //brdf cube map - std::string brdfVertShaderPath = getAssetPath() + "shaders/genbrdflut.vert.spv"; - std::string brdfFragShaderPath = getAssetPath() + "shaders/genbrdflut.frag.spv"; - // environment map texture - std::string envMapFilePath = getAssetPath() + "environments/metro_noord_4k_hdr16f_cube.ktx"; - std::string emptyEnvmapFilePath = getAssetPath() + "textures/empty.ktx"; - // pbr shader - std::string pbrVertShaderPath = getAssetPath() + "shaders/pbr.vert.spv"; - std::string pbrFragShaderPath = getAssetPath() + "shaders/pbr_khr.frag.spv"; - - //ttf file path - std::string ttfFilePath = getAssetPath() + "/data/Roboto-Medium.ttf"; - - // output file path - - std::string imageOutputPath = getAssetPath() + "output/imageSequence"; - std::string videoOutputPath = getAssetPath() + "output/video"; - std::string totalImageOutputPath; - std::string deviceSpecFilePath; - - // script file path - std::string image2videoBatFilePath = getAssetPath() + "script/image2video.bat"; - std::string image2videoShFilePath = getAssetPath() + "script/image2video.sh"; - - } filePath; + float modelrot = 0.0f; diff --git a/src/render/renderConfig.cpp b/src/render/renderConfig.cpp new file mode 100644 index 0000000..262ed3c --- /dev/null +++ b/src/render/renderConfig.cpp @@ -0,0 +1,32 @@ +#include "renderConfig.h" + +void PlumageConfig::PlumageConfiguration::writrConfigurationToJson() +{ + nlohmann::json configJsonFile = nlohmann::json + { + {"width",settings.width}, + {"height",settings.height}, + {"validation",settings.validation}, + {"fullscreen",settings.fullscreen}, + {"vsync",settings.vsync}, + {"multiSampling",settings.multiSampling}, + {"rotateModel",settings.rotateModel}, + {"headless",settings.headless}, + {"outputPNGimage",settings.outputPNGimage}, + {"enableSaveToImageSequeue",settings.enableSaveToImageSequeue}, + {"outputFrameCount",settings.outputFrameCount}, + {"takeScreenShot",settings.takeScreenShot}, + {"startFrameCount",settings.startFrameCount}, + {"videoFrameRate",settings.videoFrameRate}, + {"sampleCount",settings.sampleCount}, + {"",settings.}, + {"",settings.} + }; +} + +void PlumageConfig::PlumageConfiguration::readConfigurationToJson(std::string configFilePath) +{ + nlohmann::json configJsonFile; + std::ifstream jfile("test.json"); + jfile >> configJsonFile; +} diff --git a/src/render/renderConfig.h b/src/render/renderConfig.h new file mode 100644 index 0000000..4b76611 --- /dev/null +++ b/src/render/renderConfig.h @@ -0,0 +1,114 @@ +#pragma once + +#include +#include +#include + +#include +#include +#include + + +namespace PlumageConfig +{ + class PlumageConfiguration + { + public: + PlumageConfiguration(); + ~PlumageConfiguration(); + + struct Settings { + uint32_t width = 1280; + uint32_t height = 720; + bool validation = true; // У㿪 + bool fullscreen = false; // ȫ + bool vsync = false; // ֱͬ + bool multiSampling = false; // ز + bool rotateModel = true; // ģת(ʱʧЧ) + bool headless = false; // ͷ + bool outputPNGimage = false; + bool enableSaveToImageSequeue = true; // ͼƬпأʱã + uint32_t outputFrameCount = 50; // ͼƬн֡ + bool takeScreenShot = false; // ʱã + uint32_t startFrameCount = 1; // ͼƬпʼ֡ + + uint32_t videoFrameRate = 25; + + VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_4_BIT; // ز + } settings; + + struct FilePath + { //model path + std::string glTFModelFilePath = getAssetPath() + "models/DamagedHelmet/DamagedHelmet.gltf"; + std::string modelVertShaderPath = getAssetPath() + "buster_drone/shaders/glsl/mesh.vert.spv"; + std::string modelFragShaderPath = getAssetPath() + "buster_drone/shaders/glsl/mesh.frag.spv"; + + //ui + std::string uiVertShaderPath = getAssetPath() + "shaders/ui.vert.spv"; + std::string uiFragShaderPath = getAssetPath() + "shaders/ui.frag.spv"; + + // skybox path + std::string skyboxModleFilePath = getAssetPath() + "models/cube.gltf"; + std::string skyboxVertShaderPath = getAssetPath() + "shaders/skybox.vert.spv"; + std::string skyboxFragShaderPath = getAssetPath() + "shaders/skybox.frag.spv"; + + std::string iblTexturesFilePath = getAssetPath() + "textures/hdr/gcanyon_cube.ktx"; + //tonemapping + std::string tonemappingVertShaderPath = getAssetPath() + "buster_drone/shaders/glsl/genbrdflut.vert.spv"; + std::string tonemappingEnableFragShaderPath = getAssetPath() + "buster_drone/shaders/glsl/tonemapping_enable.frag.spv"; + std::string tonemappingDisableFragShaderPath = getAssetPath() + "buster_drone/shaders/glsl/tonemapping_disable.frag.spv"; + + + // cube map + std::string irradianceFragShaderPath = getAssetPath() + "shaders/irradiancecube.frag.spv"; + + std::string filterVertShaderPath = getAssetPath() + "shaders/filtercube.vert.spv"; + + std::string prefilterEnvmapFragShaderPath = getAssetPath() + "shaders/prefilterenvmap.frag.spv"; + //brdf cube map + std::string brdfVertShaderPath = getAssetPath() + "shaders/genbrdflut.vert.spv"; + std::string brdfFragShaderPath = getAssetPath() + "shaders/genbrdflut.frag.spv"; + // environment map texture + std::string envMapFilePath = getAssetPath() + "environments/metro_noord_4k_hdr16f_cube.ktx"; + std::string emptyEnvmapFilePath = getAssetPath() + "textures/empty.ktx"; + // pbr shader + std::string pbrVertShaderPath = getAssetPath() + "shaders/pbr.vert.spv"; + std::string pbrFragShaderPath = getAssetPath() + "shaders/pbr_khr.frag.spv"; + + //ttf file path + std::string ttfFilePath = getAssetPath() + "/data/Roboto-Medium.ttf"; + + // output file path + + std::string imageOutputPath = getAssetPath() + "output/imageSequence"; + std::string videoOutputPath = getAssetPath() + "output/video"; + std::string totalImageOutputPath; + std::string deviceSpecFilePath; + + // script file path + std::string image2videoBatFilePath = getAssetPath() + "script/image2video.bat"; + std::string image2videoShFilePath = getAssetPath() + "script/image2video.sh"; + + std::string configFilePath = getAssetPath() + "config/config.json"; + + } filePath; + + void writrConfigurationToJson(); + + void readConfigurationToJson(std::string configFilePath); + + private: + + }; + + PlumageConfiguration::PlumageConfiguration() + { + } + + PlumageConfiguration::~PlumageConfiguration() + { + } +} + + +