Move third party libraries to 3rdparty folder
This commit is contained in:
parent
2a1575c5cc
commit
886e488a26
9 changed files with 120 additions and 102 deletions
2
3rdparty/CMakeLists.txt
vendored
Normal file
2
3rdparty/CMakeLists.txt
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
add_subdirectory(nlohmann)
|
||||||
|
add_subdirectory(stb)
|
4
3rdparty/nlohmann/CMakeLists.txt
vendored
Normal file
4
3rdparty/nlohmann/CMakeLists.txt
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
add_library(nlohmann INTERFACE)
|
||||||
|
target_include_directories(nlohmann INTERFACE include)
|
||||||
|
|
||||||
|
add_library(nlohmann::json ALIAS nlohmann)
|
5
3rdparty/stb/CMakeLists.txt
vendored
Normal file
5
3rdparty/stb/CMakeLists.txt
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
add_library(stb
|
||||||
|
src/stb.c)
|
||||||
|
target_include_directories(stb PUBLIC include)
|
||||||
|
|
||||||
|
add_library(stb::stb ALIAS stb)
|
2
3rdparty/stb/src/stb.c
vendored
Normal file
2
3rdparty/stb/src/stb.c
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
#include "stb_image.h"
|
|
@ -3,6 +3,8 @@ project(Graph)
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
|
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
|
||||||
|
|
||||||
|
add_subdirectory(3rdparty)
|
||||||
|
|
||||||
include(cmake/BuildShaders.cmake)
|
include(cmake/BuildShaders.cmake)
|
||||||
include(cmake/CopyData.cmake)
|
include(cmake/CopyData.cmake)
|
||||||
|
|
||||||
|
@ -22,7 +24,13 @@ add_executable(Graph
|
||||||
src/worldpass.cpp
|
src/worldpass.cpp
|
||||||
src/postpass.cpp
|
src/postpass.cpp
|
||||||
src/dofpass.cpp)
|
src/dofpass.cpp)
|
||||||
target_link_libraries(Graph PUBLIC SDL2::SDL2 SDL2::SDL2main Vulkan::Vulkan assimp::assimp)
|
target_link_libraries(Graph PUBLIC
|
||||||
|
SDL2::SDL2
|
||||||
|
SDL2::SDL2main
|
||||||
|
Vulkan::Vulkan
|
||||||
|
assimp::assimp
|
||||||
|
nlohmann::json
|
||||||
|
stb::stb)
|
||||||
target_include_directories(Graph PUBLIC include)
|
target_include_directories(Graph PUBLIC include)
|
||||||
|
|
||||||
add_shaders(Graph
|
add_shaders(Graph
|
||||||
|
|
192
src/dofpass.cpp
192
src/dofpass.cpp
|
@ -2,9 +2,7 @@
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
#include <stb_image.h>
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
|
||||||
#include "stb_image.h"
|
|
||||||
|
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
|
|
||||||
|
@ -20,12 +18,12 @@ DoFPass::~DoFPass() {
|
||||||
vkDestroyImageView(renderer_.getDevice(), bokehImageView_, nullptr);
|
vkDestroyImageView(renderer_.getDevice(), bokehImageView_, nullptr);
|
||||||
vkFreeMemory(renderer_.getDevice(), bokehMemory_, nullptr);
|
vkFreeMemory(renderer_.getDevice(), bokehMemory_, nullptr);
|
||||||
vkDestroyImage(renderer_.getDevice(), bokehImage_, nullptr);
|
vkDestroyImage(renderer_.getDevice(), bokehImage_, nullptr);
|
||||||
|
|
||||||
vkDestroyPipeline(renderer_.getDevice(), pipeline_, nullptr);
|
vkDestroyPipeline(renderer_.getDevice(), pipeline_, nullptr);
|
||||||
vkDestroyPipelineLayout(renderer_.getDevice(), pipelineLayout_, nullptr);
|
vkDestroyPipelineLayout(renderer_.getDevice(), pipelineLayout_, nullptr);
|
||||||
|
|
||||||
vkDestroyDescriptorSetLayout(renderer_.getDevice(), setLayout_, nullptr);
|
vkDestroyDescriptorSetLayout(renderer_.getDevice(), setLayout_, nullptr);
|
||||||
|
|
||||||
vkDestroyRenderPass(renderer_.getDevice(), renderPass_, nullptr);
|
vkDestroyRenderPass(renderer_.getDevice(), renderPass_, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,17 +32,17 @@ void DoFPass::render(VkCommandBuffer commandBuffer, RenderTarget* target) {
|
||||||
viewport.width = target->extent.width / 2;
|
viewport.width = target->extent.width / 2;
|
||||||
viewport.height = target->extent.height / 2;
|
viewport.height = target->extent.height / 2;
|
||||||
viewport.maxDepth = 1.0f;
|
viewport.maxDepth = 1.0f;
|
||||||
|
|
||||||
vkCmdSetViewport(commandBuffer, 0, 1, &viewport);
|
vkCmdSetViewport(commandBuffer, 0, 1, &viewport);
|
||||||
|
|
||||||
VkRect2D scissor = {};
|
VkRect2D scissor = {};
|
||||||
scissor.extent.width = target->extent.width / 2;
|
scissor.extent.width = target->extent.width / 2;
|
||||||
scissor.extent.height = target->extent.height / 2;
|
scissor.extent.height = target->extent.height / 2;
|
||||||
|
|
||||||
vkCmdSetScissor(commandBuffer, 0, 1, &scissor);
|
vkCmdSetScissor(commandBuffer, 0, 1, &scissor);
|
||||||
|
|
||||||
VkClearValue clearColor = {};
|
VkClearValue clearColor = {};
|
||||||
|
|
||||||
VkRenderPassBeginInfo renderPassBeginInfo = {};
|
VkRenderPassBeginInfo renderPassBeginInfo = {};
|
||||||
renderPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
renderPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
||||||
renderPassBeginInfo.framebuffer = target->farFieldFramebuffers[target->currentImage];
|
renderPassBeginInfo.framebuffer = target->farFieldFramebuffers[target->currentImage];
|
||||||
|
@ -53,41 +51,41 @@ void DoFPass::render(VkCommandBuffer commandBuffer, RenderTarget* target) {
|
||||||
renderPassBeginInfo.renderArea.extent.height = target->extent.height / 2;
|
renderPassBeginInfo.renderArea.extent.height = target->extent.height / 2;
|
||||||
renderPassBeginInfo.clearValueCount = 1;
|
renderPassBeginInfo.clearValueCount = 1;
|
||||||
renderPassBeginInfo.pClearValues = &clearColor;
|
renderPassBeginInfo.pClearValues = &clearColor;
|
||||||
|
|
||||||
// far field
|
// far field
|
||||||
vkCmdBeginRenderPass(commandBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
|
vkCmdBeginRenderPass(commandBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
|
||||||
|
|
||||||
glm::vec4 dpack;
|
glm::vec4 dpack;
|
||||||
dpack[0] = 0;
|
dpack[0] = 0;
|
||||||
dpack[1] = 0.9581;
|
dpack[1] = 0.9581;
|
||||||
dpack[2] = target->extent.width / 2;
|
dpack[2] = target->extent.width / 2;
|
||||||
dpack[3] = target->extent.height / 2;
|
dpack[3] = target->extent.height / 2;
|
||||||
|
|
||||||
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_);
|
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_);
|
||||||
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout_, 0, 1, &target->dofSets[target->currentImage], 0, nullptr);
|
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout_, 0, 1, &target->dofSets[target->currentImage], 0, nullptr);
|
||||||
|
|
||||||
vkCmdPushConstants(commandBuffer, pipelineLayout_, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(glm::vec4), &dpack);
|
vkCmdPushConstants(commandBuffer, pipelineLayout_, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(glm::vec4), &dpack);
|
||||||
|
|
||||||
vkCmdDraw(commandBuffer, 3, (target->extent.width / 2) * (target->extent.height / 2), 0, 0);
|
vkCmdDraw(commandBuffer, 3, (target->extent.width / 2) * (target->extent.height / 2), 0, 0);
|
||||||
|
|
||||||
vkCmdEndRenderPass(commandBuffer);
|
vkCmdEndRenderPass(commandBuffer);
|
||||||
|
|
||||||
//near field
|
//near field
|
||||||
renderPassBeginInfo.framebuffer = target->nearFieldFramebuffers[target->currentImage];
|
renderPassBeginInfo.framebuffer = target->nearFieldFramebuffers[target->currentImage];
|
||||||
|
|
||||||
vkCmdBeginRenderPass(commandBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
|
vkCmdBeginRenderPass(commandBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
|
||||||
|
|
||||||
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_);
|
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_);
|
||||||
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout_, 0, 1, &target->dofSets[target->currentImage], 0, nullptr);
|
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout_, 0, 1, &target->dofSets[target->currentImage], 0, nullptr);
|
||||||
|
|
||||||
dpack[0] = 1;
|
dpack[0] = 1;
|
||||||
dpack[1] = 0.9581;
|
dpack[1] = 0.9581;
|
||||||
|
|
||||||
vkCmdPushConstants(commandBuffer, pipelineLayout_, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(glm::vec4), &dpack);
|
vkCmdPushConstants(commandBuffer, pipelineLayout_, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(glm::vec4), &dpack);
|
||||||
|
|
||||||
//FIXME: near field is bugged
|
//FIXME: near field is bugged
|
||||||
//vkCmdDraw(commandBuffer, 3, (target->extent.width / 2) * (target->extent.height / 2), 0, 0);
|
//vkCmdDraw(commandBuffer, 3, (target->extent.width / 2) * (target->extent.height / 2), 0, 0);
|
||||||
|
|
||||||
vkCmdEndRenderPass(commandBuffer);
|
vkCmdEndRenderPass(commandBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,42 +94,42 @@ void DoFPass::createDescriptorSet(RenderTarget* target) {
|
||||||
allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
||||||
allocInfo.descriptorPool = renderer_.getDescriptorPool();
|
allocInfo.descriptorPool = renderer_.getDescriptorPool();
|
||||||
allocInfo.descriptorSetCount = target->numImages;
|
allocInfo.descriptorSetCount = target->numImages;
|
||||||
|
|
||||||
// FIXME: lol what
|
// FIXME: lol what
|
||||||
auto layouts = new VkDescriptorSetLayout[target->numImages];
|
auto layouts = new VkDescriptorSetLayout[target->numImages];
|
||||||
for(uint32_t i = 0; i < target->numImages; i++)
|
for(uint32_t i = 0; i < target->numImages; i++)
|
||||||
layouts[i] = setLayout_;
|
layouts[i] = setLayout_;
|
||||||
|
|
||||||
allocInfo.pSetLayouts = layouts;
|
allocInfo.pSetLayouts = layouts;
|
||||||
|
|
||||||
target->dofSets = new VkDescriptorSet[target->numImages];
|
target->dofSets = new VkDescriptorSet[target->numImages];
|
||||||
vkAllocateDescriptorSets(renderer_.getDevice(), &allocInfo, target->dofSets);
|
vkAllocateDescriptorSets(renderer_.getDevice(), &allocInfo, target->dofSets);
|
||||||
|
|
||||||
delete[] layouts;
|
delete[] layouts;
|
||||||
|
|
||||||
for(uint32_t i = 0; i < target->numImages; i++) {
|
for(uint32_t i = 0; i < target->numImages; i++) {
|
||||||
VkDescriptorImageInfo bokehImageInfo = {};
|
VkDescriptorImageInfo bokehImageInfo = {};
|
||||||
bokehImageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
bokehImageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||||
bokehImageInfo.imageView = bokehImageView_;
|
bokehImageInfo.imageView = bokehImageView_;
|
||||||
bokehImageInfo.sampler = bokehSampler_;
|
bokehImageInfo.sampler = bokehSampler_;
|
||||||
|
|
||||||
VkDescriptorImageInfo sceneImageInfo = {};
|
VkDescriptorImageInfo sceneImageInfo = {};
|
||||||
sceneImageInfo.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
sceneImageInfo.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||||
sceneImageInfo.imageView = target->offscreenColorImageViews[i];
|
sceneImageInfo.imageView = target->offscreenColorImageViews[i];
|
||||||
sceneImageInfo.sampler = bokehSampler_;
|
sceneImageInfo.sampler = bokehSampler_;
|
||||||
|
|
||||||
VkDescriptorImageInfo depthImageInfo = {};
|
VkDescriptorImageInfo depthImageInfo = {};
|
||||||
depthImageInfo.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;;
|
depthImageInfo.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;;
|
||||||
depthImageInfo.imageView = target->offscreenDepthImageViews[i];
|
depthImageInfo.imageView = target->offscreenDepthImageViews[i];
|
||||||
depthImageInfo.sampler = bokehSampler_;
|
depthImageInfo.sampler = bokehSampler_;
|
||||||
|
|
||||||
VkWriteDescriptorSet bokehDescriptorWrite = {};
|
VkWriteDescriptorSet bokehDescriptorWrite = {};
|
||||||
bokehDescriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
bokehDescriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
||||||
bokehDescriptorWrite.descriptorCount = 1;
|
bokehDescriptorWrite.descriptorCount = 1;
|
||||||
bokehDescriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
bokehDescriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||||
bokehDescriptorWrite.dstSet = target->dofSets[i];
|
bokehDescriptorWrite.dstSet = target->dofSets[i];
|
||||||
bokehDescriptorWrite.pImageInfo = &bokehImageInfo;
|
bokehDescriptorWrite.pImageInfo = &bokehImageInfo;
|
||||||
|
|
||||||
VkWriteDescriptorSet sceneDescriptorWrite = {};
|
VkWriteDescriptorSet sceneDescriptorWrite = {};
|
||||||
sceneDescriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
sceneDescriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
||||||
sceneDescriptorWrite.descriptorCount = 1;
|
sceneDescriptorWrite.descriptorCount = 1;
|
||||||
|
@ -139,7 +137,7 @@ void DoFPass::createDescriptorSet(RenderTarget* target) {
|
||||||
sceneDescriptorWrite.dstBinding = 1;
|
sceneDescriptorWrite.dstBinding = 1;
|
||||||
sceneDescriptorWrite.dstSet = target->dofSets[i];
|
sceneDescriptorWrite.dstSet = target->dofSets[i];
|
||||||
sceneDescriptorWrite.pImageInfo = &sceneImageInfo;
|
sceneDescriptorWrite.pImageInfo = &sceneImageInfo;
|
||||||
|
|
||||||
VkWriteDescriptorSet depthDescriptorWrite = {};
|
VkWriteDescriptorSet depthDescriptorWrite = {};
|
||||||
depthDescriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
depthDescriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
||||||
depthDescriptorWrite.descriptorCount = 1;
|
depthDescriptorWrite.descriptorCount = 1;
|
||||||
|
@ -147,13 +145,13 @@ void DoFPass::createDescriptorSet(RenderTarget* target) {
|
||||||
depthDescriptorWrite.dstBinding = 2;
|
depthDescriptorWrite.dstBinding = 2;
|
||||||
depthDescriptorWrite.dstSet = target->dofSets[i];
|
depthDescriptorWrite.dstSet = target->dofSets[i];
|
||||||
depthDescriptorWrite.pImageInfo = &depthImageInfo;
|
depthDescriptorWrite.pImageInfo = &depthImageInfo;
|
||||||
|
|
||||||
const std::array<VkWriteDescriptorSet, 3> descriptorWrites = {
|
const std::array<VkWriteDescriptorSet, 3> descriptorWrites = {
|
||||||
bokehDescriptorWrite,
|
bokehDescriptorWrite,
|
||||||
sceneDescriptorWrite,
|
sceneDescriptorWrite,
|
||||||
depthDescriptorWrite
|
depthDescriptorWrite
|
||||||
};
|
};
|
||||||
|
|
||||||
vkUpdateDescriptorSets(renderer_.getDevice(), descriptorWrites.size(), descriptorWrites.data(), 0, nullptr);
|
vkUpdateDescriptorSets(renderer_.getDevice(), descriptorWrites.size(), descriptorWrites.data(), 0, nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -168,10 +166,10 @@ void DoFPass::createRenderPass() {
|
||||||
colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||||
|
|
||||||
VkAttachmentReference colorAttachmentRef = {};
|
VkAttachmentReference colorAttachmentRef = {};
|
||||||
colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||||
|
|
||||||
VkSubpassDescription subpass = {};
|
VkSubpassDescription subpass = {};
|
||||||
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
||||||
subpass.colorAttachmentCount = 1;
|
subpass.colorAttachmentCount = 1;
|
||||||
|
@ -183,7 +181,7 @@ void DoFPass::createRenderPass() {
|
||||||
renderPassInfo.pAttachments = &colorAttachment;
|
renderPassInfo.pAttachments = &colorAttachment;
|
||||||
renderPassInfo.subpassCount = 1;
|
renderPassInfo.subpassCount = 1;
|
||||||
renderPassInfo.pSubpasses = &subpass;
|
renderPassInfo.pSubpasses = &subpass;
|
||||||
|
|
||||||
vkCreateRenderPass(renderer_.getDevice(), &renderPassInfo, nullptr, &renderPass_);
|
vkCreateRenderPass(renderer_.getDevice(), &renderPassInfo, nullptr, &renderPass_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,74 +190,74 @@ void DoFPass::createDescriptorSetLayout() {
|
||||||
bokehSamplerBinding.descriptorCount = 1;
|
bokehSamplerBinding.descriptorCount = 1;
|
||||||
bokehSamplerBinding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
bokehSamplerBinding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||||
bokehSamplerBinding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
|
bokehSamplerBinding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||||
|
|
||||||
VkDescriptorSetLayoutBinding sceneSamplerBinding = {};
|
VkDescriptorSetLayoutBinding sceneSamplerBinding = {};
|
||||||
sceneSamplerBinding.binding = 1;
|
sceneSamplerBinding.binding = 1;
|
||||||
sceneSamplerBinding.descriptorCount = 1;
|
sceneSamplerBinding.descriptorCount = 1;
|
||||||
sceneSamplerBinding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
sceneSamplerBinding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||||
sceneSamplerBinding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
|
sceneSamplerBinding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||||
|
|
||||||
VkDescriptorSetLayoutBinding depthSamplerBinding = {};
|
VkDescriptorSetLayoutBinding depthSamplerBinding = {};
|
||||||
depthSamplerBinding.binding = 2;
|
depthSamplerBinding.binding = 2;
|
||||||
depthSamplerBinding.descriptorCount = 1;
|
depthSamplerBinding.descriptorCount = 1;
|
||||||
depthSamplerBinding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
depthSamplerBinding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||||
depthSamplerBinding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT;
|
depthSamplerBinding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||||
|
|
||||||
const std::array<VkDescriptorSetLayoutBinding, 3> bindings = {
|
const std::array<VkDescriptorSetLayoutBinding, 3> bindings = {
|
||||||
bokehSamplerBinding,
|
bokehSamplerBinding,
|
||||||
sceneSamplerBinding,
|
sceneSamplerBinding,
|
||||||
depthSamplerBinding
|
depthSamplerBinding
|
||||||
};
|
};
|
||||||
|
|
||||||
VkDescriptorSetLayoutCreateInfo createInfo = {};
|
VkDescriptorSetLayoutCreateInfo createInfo = {};
|
||||||
createInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
|
createInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
|
||||||
createInfo.bindingCount = bindings.size();
|
createInfo.bindingCount = bindings.size();
|
||||||
createInfo.pBindings = bindings.data();
|
createInfo.pBindings = bindings.data();
|
||||||
|
|
||||||
vkCreateDescriptorSetLayout(renderer_.getDevice(), &createInfo, nullptr, &setLayout_);
|
vkCreateDescriptorSetLayout(renderer_.getDevice(), &createInfo, nullptr, &setLayout_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoFPass::createPipeline() {
|
void DoFPass::createPipeline() {
|
||||||
VkShaderModule vertShaderModule = renderer_.createShader("shaders/gfield.vert.spv");
|
VkShaderModule vertShaderModule = renderer_.createShader("shaders/gfield.vert.spv");
|
||||||
VkShaderModule fragShaderModule = renderer_.createShader("shaders/gfield.frag.spv");
|
VkShaderModule fragShaderModule = renderer_.createShader("shaders/gfield.frag.spv");
|
||||||
|
|
||||||
VkPipelineShaderStageCreateInfo vertShaderStageInfo = {};
|
VkPipelineShaderStageCreateInfo vertShaderStageInfo = {};
|
||||||
vertShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
vertShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||||
vertShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT;
|
vertShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT;
|
||||||
vertShaderStageInfo.module = vertShaderModule;
|
vertShaderStageInfo.module = vertShaderModule;
|
||||||
vertShaderStageInfo.pName = "main";
|
vertShaderStageInfo.pName = "main";
|
||||||
|
|
||||||
VkPipelineShaderStageCreateInfo fragShaderStageInfo = {};
|
VkPipelineShaderStageCreateInfo fragShaderStageInfo = {};
|
||||||
fragShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
fragShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||||
fragShaderStageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT;
|
fragShaderStageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||||
fragShaderStageInfo.module = fragShaderModule;
|
fragShaderStageInfo.module = fragShaderModule;
|
||||||
fragShaderStageInfo.pName = "main";
|
fragShaderStageInfo.pName = "main";
|
||||||
|
|
||||||
const std::array<VkPipelineShaderStageCreateInfo, 2> shaderStages = {vertShaderStageInfo, fragShaderStageInfo};
|
const std::array<VkPipelineShaderStageCreateInfo, 2> shaderStages = {vertShaderStageInfo, fragShaderStageInfo};
|
||||||
|
|
||||||
VkPipelineVertexInputStateCreateInfo vertexInputInfo = {};
|
VkPipelineVertexInputStateCreateInfo vertexInputInfo = {};
|
||||||
vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
||||||
|
|
||||||
VkPipelineInputAssemblyStateCreateInfo inputAssembly = {};
|
VkPipelineInputAssemblyStateCreateInfo inputAssembly = {};
|
||||||
inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
|
inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
|
||||||
inputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
inputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
||||||
|
|
||||||
VkPipelineViewportStateCreateInfo viewportState = {};
|
VkPipelineViewportStateCreateInfo viewportState = {};
|
||||||
viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
|
viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
|
||||||
viewportState.viewportCount = 1;
|
viewportState.viewportCount = 1;
|
||||||
viewportState.scissorCount = 1;
|
viewportState.scissorCount = 1;
|
||||||
|
|
||||||
VkPipelineRasterizationStateCreateInfo rasterizer = {};
|
VkPipelineRasterizationStateCreateInfo rasterizer = {};
|
||||||
rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
|
rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
|
||||||
rasterizer.polygonMode = VK_POLYGON_MODE_FILL;
|
rasterizer.polygonMode = VK_POLYGON_MODE_FILL;
|
||||||
rasterizer.lineWidth = 1.0f;
|
rasterizer.lineWidth = 1.0f;
|
||||||
rasterizer.cullMode = VK_CULL_MODE_FRONT_BIT;
|
rasterizer.cullMode = VK_CULL_MODE_FRONT_BIT;
|
||||||
rasterizer.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
|
rasterizer.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
|
||||||
|
|
||||||
VkPipelineMultisampleStateCreateInfo multisampling = {};
|
VkPipelineMultisampleStateCreateInfo multisampling = {};
|
||||||
multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
|
multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
|
||||||
multisampling.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
|
multisampling.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
|
|
||||||
VkPipelineColorBlendAttachmentState colorBlendAttachment = {};
|
VkPipelineColorBlendAttachmentState colorBlendAttachment = {};
|
||||||
colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
|
colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
|
||||||
colorBlendAttachment.blendEnable = VK_TRUE;
|
colorBlendAttachment.blendEnable = VK_TRUE;
|
||||||
|
@ -269,35 +267,35 @@ void DoFPass::createPipeline() {
|
||||||
colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD;
|
colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD;
|
||||||
colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
|
colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||||
colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
|
colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
|
||||||
|
|
||||||
VkPipelineColorBlendStateCreateInfo colorBlending = {};
|
VkPipelineColorBlendStateCreateInfo colorBlending = {};
|
||||||
colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
|
colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
|
||||||
colorBlending.attachmentCount = 1;
|
colorBlending.attachmentCount = 1;
|
||||||
colorBlending.pAttachments = &colorBlendAttachment;
|
colorBlending.pAttachments = &colorBlendAttachment;
|
||||||
|
|
||||||
const std::array<VkDynamicState, 2> dynamicStates = {
|
const std::array<VkDynamicState, 2> dynamicStates = {
|
||||||
VK_DYNAMIC_STATE_VIEWPORT,
|
VK_DYNAMIC_STATE_VIEWPORT,
|
||||||
VK_DYNAMIC_STATE_SCISSOR
|
VK_DYNAMIC_STATE_SCISSOR
|
||||||
};
|
};
|
||||||
|
|
||||||
VkPipelineDynamicStateCreateInfo dynamicState = {};
|
VkPipelineDynamicStateCreateInfo dynamicState = {};
|
||||||
dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
|
dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
|
||||||
dynamicState.dynamicStateCount = dynamicStates.size();
|
dynamicState.dynamicStateCount = dynamicStates.size();
|
||||||
dynamicState.pDynamicStates = dynamicStates.data();
|
dynamicState.pDynamicStates = dynamicStates.data();
|
||||||
|
|
||||||
VkPushConstantRange pushConstant = {};
|
VkPushConstantRange pushConstant = {};
|
||||||
pushConstant.size = sizeof(glm::vec4);
|
pushConstant.size = sizeof(glm::vec4);
|
||||||
pushConstant.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT;
|
pushConstant.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||||
|
|
||||||
VkPipelineLayoutCreateInfo pipelineLayoutInfo = {};
|
VkPipelineLayoutCreateInfo pipelineLayoutInfo = {};
|
||||||
pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
|
pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
|
||||||
pipelineLayoutInfo.setLayoutCount = 1;
|
pipelineLayoutInfo.setLayoutCount = 1;
|
||||||
pipelineLayoutInfo.pSetLayouts = &setLayout_;
|
pipelineLayoutInfo.pSetLayouts = &setLayout_;
|
||||||
pipelineLayoutInfo.pushConstantRangeCount = 1;
|
pipelineLayoutInfo.pushConstantRangeCount = 1;
|
||||||
pipelineLayoutInfo.pPushConstantRanges = &pushConstant;
|
pipelineLayoutInfo.pPushConstantRanges = &pushConstant;
|
||||||
|
|
||||||
vkCreatePipelineLayout(renderer_.getDevice(), &pipelineLayoutInfo, nullptr, &pipelineLayout_);
|
vkCreatePipelineLayout(renderer_.getDevice(), &pipelineLayoutInfo, nullptr, &pipelineLayout_);
|
||||||
|
|
||||||
VkGraphicsPipelineCreateInfo pipelineInfo = {};
|
VkGraphicsPipelineCreateInfo pipelineInfo = {};
|
||||||
pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
|
pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
|
||||||
pipelineInfo.stageCount = shaderStages.size();
|
pipelineInfo.stageCount = shaderStages.size();
|
||||||
|
@ -311,9 +309,9 @@ void DoFPass::createPipeline() {
|
||||||
pipelineInfo.pDynamicState = &dynamicState;
|
pipelineInfo.pDynamicState = &dynamicState;
|
||||||
pipelineInfo.layout = pipelineLayout_;
|
pipelineInfo.layout = pipelineLayout_;
|
||||||
pipelineInfo.renderPass = renderPass_;
|
pipelineInfo.renderPass = renderPass_;
|
||||||
|
|
||||||
vkCreateGraphicsPipelines(renderer_.getDevice(), nullptr, 1, &pipelineInfo, nullptr, &pipeline_);
|
vkCreateGraphicsPipelines(renderer_.getDevice(), nullptr, 1, &pipelineInfo, nullptr, &pipeline_);
|
||||||
|
|
||||||
vkDestroyShaderModule(renderer_.getDevice(), fragShaderModule, nullptr);
|
vkDestroyShaderModule(renderer_.getDevice(), fragShaderModule, nullptr);
|
||||||
vkDestroyShaderModule(renderer_.getDevice(), vertShaderModule, nullptr);
|
vkDestroyShaderModule(renderer_.getDevice(), vertShaderModule, nullptr);
|
||||||
}
|
}
|
||||||
|
@ -323,7 +321,7 @@ void DoFPass::createBokehImage() {
|
||||||
stbi_uc* pixels = stbi_load("data/bokeh.png", &width, &height, &channels, STBI_rgb_alpha);
|
stbi_uc* pixels = stbi_load("data/bokeh.png", &width, &height, &channels, STBI_rgb_alpha);
|
||||||
if(pixels == nullptr)
|
if(pixels == nullptr)
|
||||||
return; // haha what
|
return; // haha what
|
||||||
|
|
||||||
VkImageCreateInfo imageCreateInfo = {};
|
VkImageCreateInfo imageCreateInfo = {};
|
||||||
imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
||||||
imageCreateInfo.imageType = VK_IMAGE_TYPE_2D;
|
imageCreateInfo.imageType = VK_IMAGE_TYPE_2D;
|
||||||
|
@ -338,61 +336,61 @@ void DoFPass::createBokehImage() {
|
||||||
imageCreateInfo.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
|
imageCreateInfo.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
|
||||||
imageCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
imageCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||||
imageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT;
|
imageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
|
|
||||||
vkCreateImage(renderer_.getDevice(), &imageCreateInfo, nullptr, &bokehImage_);
|
vkCreateImage(renderer_.getDevice(), &imageCreateInfo, nullptr, &bokehImage_);
|
||||||
|
|
||||||
VkMemoryRequirements memRequirements;
|
VkMemoryRequirements memRequirements;
|
||||||
vkGetImageMemoryRequirements(renderer_.getDevice(), bokehImage_, &memRequirements);
|
vkGetImageMemoryRequirements(renderer_.getDevice(), bokehImage_, &memRequirements);
|
||||||
|
|
||||||
VkMemoryAllocateInfo allocInfo = {};
|
VkMemoryAllocateInfo allocInfo = {};
|
||||||
allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
||||||
allocInfo.allocationSize = memRequirements.size;
|
allocInfo.allocationSize = memRequirements.size;
|
||||||
allocInfo.memoryTypeIndex = renderer_.findMemoryType(memRequirements.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
allocInfo.memoryTypeIndex = renderer_.findMemoryType(memRequirements.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
||||||
|
|
||||||
vkAllocateMemory(renderer_.getDevice(), &allocInfo, nullptr, &bokehMemory_);
|
vkAllocateMemory(renderer_.getDevice(), &allocInfo, nullptr, &bokehMemory_);
|
||||||
vkBindImageMemory(renderer_.getDevice(), bokehImage_, bokehMemory_, 0);
|
vkBindImageMemory(renderer_.getDevice(), bokehImage_, bokehMemory_, 0);
|
||||||
|
|
||||||
VkBuffer stagingBuffer;
|
VkBuffer stagingBuffer;
|
||||||
VkDeviceMemory stagingMemory;
|
VkDeviceMemory stagingMemory;
|
||||||
|
|
||||||
VkBufferCreateInfo bufferInfo = {};
|
VkBufferCreateInfo bufferInfo = {};
|
||||||
bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
|
bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
|
||||||
bufferInfo.size = width * height * 4;
|
bufferInfo.size = width * height * 4;
|
||||||
bufferInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
|
bufferInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
|
||||||
bufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
bufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||||
|
|
||||||
vkCreateBuffer(renderer_.getDevice(), &bufferInfo, nullptr, &stagingBuffer);
|
vkCreateBuffer(renderer_.getDevice(), &bufferInfo, nullptr, &stagingBuffer);
|
||||||
|
|
||||||
vkGetBufferMemoryRequirements(renderer_.getDevice(), stagingBuffer, &memRequirements);
|
vkGetBufferMemoryRequirements(renderer_.getDevice(), stagingBuffer, &memRequirements);
|
||||||
|
|
||||||
allocInfo = {};
|
allocInfo = {};
|
||||||
allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
||||||
allocInfo.allocationSize = memRequirements.size;
|
allocInfo.allocationSize = memRequirements.size;
|
||||||
allocInfo.memoryTypeIndex = renderer_.findMemoryType(memRequirements.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
|
allocInfo.memoryTypeIndex = renderer_.findMemoryType(memRequirements.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
|
||||||
|
|
||||||
vkAllocateMemory(renderer_.getDevice(), &allocInfo, nullptr, &stagingMemory);
|
vkAllocateMemory(renderer_.getDevice(), &allocInfo, nullptr, &stagingMemory);
|
||||||
vkBindBufferMemory(renderer_.getDevice(), stagingBuffer, stagingMemory, 0);
|
vkBindBufferMemory(renderer_.getDevice(), stagingBuffer, stagingMemory, 0);
|
||||||
|
|
||||||
void* data;
|
void* data;
|
||||||
vkMapMemory(renderer_.getDevice(), stagingMemory, 0, width * height * 4, 0, &data);
|
vkMapMemory(renderer_.getDevice(), stagingMemory, 0, width * height * 4, 0, &data);
|
||||||
memcpy(data, pixels, width * height * 4);
|
memcpy(data, pixels, width * height * 4);
|
||||||
vkUnmapMemory(renderer_.getDevice(), stagingMemory);
|
vkUnmapMemory(renderer_.getDevice(), stagingMemory);
|
||||||
|
|
||||||
stbi_image_free(pixels);
|
stbi_image_free(pixels);
|
||||||
|
|
||||||
VkCommandBufferAllocateInfo bufferAllocateInfo = {};
|
VkCommandBufferAllocateInfo bufferAllocateInfo = {};
|
||||||
bufferAllocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
bufferAllocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
||||||
bufferAllocateInfo.commandPool = renderer_.getCommandPool();
|
bufferAllocateInfo.commandPool = renderer_.getCommandPool();
|
||||||
bufferAllocateInfo.commandBufferCount = 1;
|
bufferAllocateInfo.commandBufferCount = 1;
|
||||||
|
|
||||||
VkCommandBuffer commandBuffer = nullptr;
|
VkCommandBuffer commandBuffer = nullptr;
|
||||||
vkAllocateCommandBuffers(renderer_.getDevice(), &bufferAllocateInfo, &commandBuffer);
|
vkAllocateCommandBuffers(renderer_.getDevice(), &bufferAllocateInfo, &commandBuffer);
|
||||||
|
|
||||||
VkCommandBufferBeginInfo beginInfo = {};
|
VkCommandBufferBeginInfo beginInfo = {};
|
||||||
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
||||||
|
|
||||||
vkBeginCommandBuffer(commandBuffer, &beginInfo);
|
vkBeginCommandBuffer(commandBuffer, &beginInfo);
|
||||||
|
|
||||||
// change layout to transfer dst
|
// change layout to transfer dst
|
||||||
{
|
{
|
||||||
VkImageMemoryBarrier imageMemoryBarrier = {};
|
VkImageMemoryBarrier imageMemoryBarrier = {};
|
||||||
|
@ -403,7 +401,7 @@ void DoFPass::createBokehImage() {
|
||||||
imageMemoryBarrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
imageMemoryBarrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
imageMemoryBarrier.subresourceRange.layerCount = 1;
|
imageMemoryBarrier.subresourceRange.layerCount = 1;
|
||||||
imageMemoryBarrier.subresourceRange.levelCount = 1;
|
imageMemoryBarrier.subresourceRange.levelCount = 1;
|
||||||
|
|
||||||
vkCmdPipelineBarrier(
|
vkCmdPipelineBarrier(
|
||||||
commandBuffer,
|
commandBuffer,
|
||||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||||
|
@ -413,14 +411,14 @@ void DoFPass::createBokehImage() {
|
||||||
0, nullptr,
|
0, nullptr,
|
||||||
1, &imageMemoryBarrier);
|
1, &imageMemoryBarrier);
|
||||||
}
|
}
|
||||||
|
|
||||||
VkBufferImageCopy region = {};
|
VkBufferImageCopy region = {};
|
||||||
region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
region.imageSubresource.layerCount = 1;
|
region.imageSubresource.layerCount = 1;
|
||||||
region.imageExtent.width = width;
|
region.imageExtent.width = width;
|
||||||
region.imageExtent.height = height;
|
region.imageExtent.height = height;
|
||||||
region.imageExtent.depth = 1;
|
region.imageExtent.depth = 1;
|
||||||
|
|
||||||
vkCmdCopyBufferToImage(
|
vkCmdCopyBufferToImage(
|
||||||
commandBuffer,
|
commandBuffer,
|
||||||
stagingBuffer,
|
stagingBuffer,
|
||||||
|
@ -429,7 +427,7 @@ void DoFPass::createBokehImage() {
|
||||||
1,
|
1,
|
||||||
®ion
|
®ion
|
||||||
);
|
);
|
||||||
|
|
||||||
// change layout to shader read only
|
// change layout to shader read only
|
||||||
{
|
{
|
||||||
VkImageMemoryBarrier imageMemoryBarrier = {};
|
VkImageMemoryBarrier imageMemoryBarrier = {};
|
||||||
|
@ -442,7 +440,7 @@ void DoFPass::createBokehImage() {
|
||||||
imageMemoryBarrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
imageMemoryBarrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
imageMemoryBarrier.subresourceRange.layerCount = 1;
|
imageMemoryBarrier.subresourceRange.layerCount = 1;
|
||||||
imageMemoryBarrier.subresourceRange.levelCount = 1;
|
imageMemoryBarrier.subresourceRange.levelCount = 1;
|
||||||
|
|
||||||
vkCmdPipelineBarrier(
|
vkCmdPipelineBarrier(
|
||||||
commandBuffer,
|
commandBuffer,
|
||||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||||
|
@ -452,30 +450,30 @@ void DoFPass::createBokehImage() {
|
||||||
0, nullptr,
|
0, nullptr,
|
||||||
1, &imageMemoryBarrier);
|
1, &imageMemoryBarrier);
|
||||||
}
|
}
|
||||||
|
|
||||||
vkEndCommandBuffer(commandBuffer);
|
vkEndCommandBuffer(commandBuffer);
|
||||||
|
|
||||||
VkSubmitInfo submitInfo = {};
|
VkSubmitInfo submitInfo = {};
|
||||||
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||||
submitInfo.commandBufferCount = 1;
|
submitInfo.commandBufferCount = 1;
|
||||||
submitInfo.pCommandBuffers = &commandBuffer;
|
submitInfo.pCommandBuffers = &commandBuffer;
|
||||||
|
|
||||||
VkFenceCreateInfo fenceCreateInfo = {};
|
VkFenceCreateInfo fenceCreateInfo = {};
|
||||||
fenceCreateInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
|
fenceCreateInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
|
||||||
|
|
||||||
VkFence fence = nullptr;
|
VkFence fence = nullptr;
|
||||||
vkCreateFence(renderer_.getDevice(), &fenceCreateInfo, nullptr, &fence);
|
vkCreateFence(renderer_.getDevice(), &fenceCreateInfo, nullptr, &fence);
|
||||||
|
|
||||||
vkQueueSubmit(renderer_.getGraphicsQueue(), 1, &submitInfo, fence);
|
vkQueueSubmit(renderer_.getGraphicsQueue(), 1, &submitInfo, fence);
|
||||||
|
|
||||||
vkWaitForFences(renderer_.getDevice(), 1, &fence, VK_TRUE, -1);
|
vkWaitForFences(renderer_.getDevice(), 1, &fence, VK_TRUE, -1);
|
||||||
vkDestroyFence(renderer_.getDevice(), fence, nullptr);
|
vkDestroyFence(renderer_.getDevice(), fence, nullptr);
|
||||||
|
|
||||||
vkFreeCommandBuffers(renderer_.getDevice(), renderer_.getCommandPool(), 1, &commandBuffer);
|
vkFreeCommandBuffers(renderer_.getDevice(), renderer_.getCommandPool(), 1, &commandBuffer);
|
||||||
|
|
||||||
vkFreeMemory(renderer_.getDevice(), stagingMemory, nullptr);
|
vkFreeMemory(renderer_.getDevice(), stagingMemory, nullptr);
|
||||||
vkDestroyBuffer(renderer_.getDevice(), stagingBuffer, nullptr);
|
vkDestroyBuffer(renderer_.getDevice(), stagingBuffer, nullptr);
|
||||||
|
|
||||||
VkImageViewCreateInfo createInfo = {};
|
VkImageViewCreateInfo createInfo = {};
|
||||||
createInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
createInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
||||||
createInfo.image = bokehImage_;
|
createInfo.image = bokehImage_;
|
||||||
|
@ -484,9 +482,9 @@ void DoFPass::createBokehImage() {
|
||||||
createInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
createInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
createInfo.subresourceRange.levelCount = 1;
|
createInfo.subresourceRange.levelCount = 1;
|
||||||
createInfo.subresourceRange.layerCount = 1;
|
createInfo.subresourceRange.layerCount = 1;
|
||||||
|
|
||||||
vkCreateImageView(renderer_.getDevice(), &createInfo, nullptr, &bokehImageView_);
|
vkCreateImageView(renderer_.getDevice(), &createInfo, nullptr, &bokehImageView_);
|
||||||
|
|
||||||
VkSamplerCreateInfo samplerInfo = {};
|
VkSamplerCreateInfo samplerInfo = {};
|
||||||
samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
|
samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
|
||||||
samplerInfo.magFilter = VK_FILTER_LINEAR;
|
samplerInfo.magFilter = VK_FILTER_LINEAR;
|
||||||
|
@ -496,6 +494,6 @@ void DoFPass::createBokehImage() {
|
||||||
samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
|
samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
|
||||||
samplerInfo.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK;
|
samplerInfo.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK;
|
||||||
samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
|
samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
|
||||||
|
|
||||||
vkCreateSampler(renderer_.getDevice(), &samplerInfo, nullptr, &bokehSampler_);
|
vkCreateSampler(renderer_.getDevice(), &samplerInfo, nullptr, &bokehSampler_);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <json.hpp>
|
||||||
#include <assimp/Importer.hpp>
|
#include <assimp/Importer.hpp>
|
||||||
#include <assimp/scene.h>
|
#include <assimp/scene.h>
|
||||||
#include <assimp/postprocess.h>
|
#include <assimp/postprocess.h>
|
||||||
|
@ -15,7 +15,6 @@
|
||||||
#include "light.h"
|
#include "light.h"
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
#include "cinematic.h"
|
#include "cinematic.h"
|
||||||
#include "json.hpp"
|
|
||||||
|
|
||||||
SDL_Window* window = nullptr;
|
SDL_Window* window = nullptr;
|
||||||
Renderer* renderer = nullptr;
|
Renderer* renderer = nullptr;
|
||||||
|
@ -106,7 +105,7 @@ Mesh* loadMesh(const char* path) {
|
||||||
unsigned int indexOffset = 0;
|
unsigned int indexOffset = 0;
|
||||||
for(unsigned mi = 0; mi < scene->mNumMeshes; mi++) {
|
for(unsigned mi = 0; mi < scene->mNumMeshes; mi++) {
|
||||||
aiMesh* m = scene->mMeshes[mi];
|
aiMesh* m = scene->mMeshes[mi];
|
||||||
|
|
||||||
for(unsigned int i = 0; i < m->mNumVertices; i++) {
|
for(unsigned int i = 0; i < m->mNumVertices; i++) {
|
||||||
Vertex vertex;
|
Vertex vertex;
|
||||||
vertex.position = glm::vec3(m->mVertices[i].x, m->mVertices[i].y, m->mVertices[i].z);
|
vertex.position = glm::vec3(m->mVertices[i].x, m->mVertices[i].y, m->mVertices[i].z);
|
||||||
|
@ -120,7 +119,7 @@ Mesh* loadMesh(const char* path) {
|
||||||
for(unsigned int j = 0; j < face.mNumIndices; j++)
|
for(unsigned int j = 0; j < face.mNumIndices; j++)
|
||||||
mesh->indices.push_back(indexOffset + face.mIndices[j]);
|
mesh->indices.push_back(indexOffset + face.mIndices[j]);
|
||||||
}
|
}
|
||||||
|
|
||||||
indexOffset += m->mNumVertices;
|
indexOffset += m->mNumVertices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue