From 1b73a3a540b42d90114274d36dd740ca9ff2722c Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 27 Apr 2024 16:05:20 -0400 Subject: [PATCH] Reuse the depth buffer in composite pass --- renderer/src/gamerenderer.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/renderer/src/gamerenderer.cpp b/renderer/src/gamerenderer.cpp index ed69f38..c2747a6 100644 --- a/renderer/src/gamerenderer.cpp +++ b/renderer/src/gamerenderer.cpp @@ -677,7 +677,7 @@ void GameRenderer::beginPass(uint32_t imageIndex, VkCommandBuffer commandBuffer, colorAttachments.push_back(attachmentInfo); } } else if (passName == "PASS_COMPOSITE_SEMITRANSPARENCY") { - // normals, it seems like + // composite { VkRenderingAttachmentInfo attachmentInfo{VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO}; attachmentInfo.imageView = m_compositeBuffer.imageView; @@ -692,6 +692,17 @@ void GameRenderer::beginPass(uint32_t imageIndex, VkCommandBuffer commandBuffer, colorAttachments.push_back(attachmentInfo); } + + // depth buffer for depth testing + { + VkRenderingAttachmentInfo attachmentInfo{VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO}; + attachmentInfo.imageView = m_depthBuffer.imageView; + attachmentInfo.imageLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL; + attachmentInfo.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; + attachmentInfo.storeOp = VK_ATTACHMENT_STORE_OP_STORE; + + depthStencilAttachment = attachmentInfo; + } } renderingInfo.layerCount = 1; @@ -967,8 +978,10 @@ GameRenderer::bindPipeline(VkCommandBuffer commandBuffer, std::string_view passN VkPipelineDepthStencilStateCreateInfo depthStencil = {}; depthStencil.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO; depthStencil.depthTestEnable = VK_TRUE; - depthStencil.depthWriteEnable = VK_TRUE; - depthStencil.depthCompareOp = VK_COMPARE_OP_LESS; + if (passName == "PASS_G_OPAQUE") { + depthStencil.depthWriteEnable = VK_TRUE; + } + depthStencil.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL; depthStencil.maxDepthBounds = 1.0f; std::array colorAttachmentFormats = {VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED};