diff --git a/kraken/KRCamera.cpp b/kraken/KRCamera.cpp index ee9db4a..b9b4dcd 100755 --- a/kraken/KRCamera.cpp +++ b/kraken/KRCamera.cpp @@ -197,7 +197,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& compositeS // Start render pass KRRenderPass& deferredGBufferPass = compositeSurface.getDeferredGBufferPass(); - deferredGBufferPass.begin(commandBuffer, compositeSurface, Vector4::Zero()); + deferredGBufferPass.begin(commandBuffer, compositeSurface); // Render the geometry scene.render(commandBuffer, compositeSurface, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_DEFERRED_GBUFFER, false); @@ -234,7 +234,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& compositeS // Start render pass KRRenderPass& deferredOpaquePass = compositeSurface.getDeferredOpaquePass(); - deferredOpaquePass.begin(commandBuffer, compositeSurface, Vector4::Create(0.0f, 0.0f, 0.0f, 1.0f)); + deferredOpaquePass.begin(commandBuffer, compositeSurface); // Set source to buffers from pass 2 m_pContext->getTextureManager()->selectTexture(0 /*GL_TEXTURE_2D*/, 6, lightAccumulationTexture); @@ -253,7 +253,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& compositeS // Start render pass KRRenderPass& forwardOpaquePass = compositeSurface.getForwardOpaquePass(); - forwardOpaquePass.begin(commandBuffer, compositeSurface, Vector4::Create(0.0f, 0.0f, 0.0f, 1.0f)); + forwardOpaquePass.begin(commandBuffer, compositeSurface); // Render the geometry scene.render(commandBuffer, compositeSurface, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_FORWARD_OPAQUE, false); @@ -414,7 +414,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& compositeS GL_PUSH_GROUP_MARKER("Post Processing"); KRRenderPass& postCompositePass = compositeSurface.getPostCompositePass(); - postCompositePass.begin(commandBuffer, compositeSurface, Vector4::Create(0.0f, 0.0f, 0.0f, 1.0f)); + postCompositePass.begin(commandBuffer, compositeSurface); renderPost(commandBuffer, compositeSurface); @@ -774,7 +774,7 @@ void KRCamera::renderDebug(VkCommandBuffer& commandBuffer, KRSurface& surface) m_debug_text_vbo_data.load(commandBuffer); KRRenderPass& debugPass = surface.getDebugPass(); - debugPass.begin(commandBuffer, surface, Vector4::Create(0.0f, 0.0f, 0.0f, 1.0f)); + debugPass.begin(commandBuffer, surface); KRTexture* fontTexture = m_pContext->getTextureManager()->getTexture("font"); fontTexture->resetPoolExpiry(0.0f, KRTexture::TEXTURE_USAGE_UI); diff --git a/kraken/KRRenderPass.cpp b/kraken/KRRenderPass.cpp index c311ba6..e7f7530 100644 --- a/kraken/KRRenderPass.cpp +++ b/kraken/KRRenderPass.cpp @@ -75,8 +75,8 @@ void KRRenderPass::create(KRDevice& device, VkFormat swapChainImageFormat, VkFor depthAttachment.samples = VK_SAMPLE_COUNT_1_BIT; depthAttachment.loadOp = info.clearDepth ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD; depthAttachment.storeOp = info.keepDepth ? VK_ATTACHMENT_STORE_OP_STORE : VK_ATTACHMENT_STORE_OP_DONT_CARE; - depthAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; - depthAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; + depthAttachment.stencilLoadOp = info.clearStencil ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD; + depthAttachment.stencilStoreOp = info.keepStencil ? VK_ATTACHMENT_STORE_OP_STORE : VK_ATTACHMENT_STORE_OP_DONT_CARE; depthAttachment.initialLayout = info.clearDepth ? VK_IMAGE_LAYOUT_UNDEFINED : VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; depthAttachment.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; @@ -133,7 +133,8 @@ void KRRenderPass::begin(VkCommandBuffer& commandBuffer, KRSurface& surface) clearValues[0].color.float32[1] = m_info.clearColorValue[1]; clearValues[0].color.float32[2] = m_info.clearColorValue[2]; clearValues[0].color.float32[3] = m_info.clearColorValue[3]; - clearValues[1].depthStencil = { 1.0f, 0 }; + clearValues[1].depthStencil.depth = m_info.clearDepthValue; + clearValues[1].depthStencil.stencil = m_info.clearStencilValue; VkRenderPassBeginInfo renderPassInfo{}; renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; diff --git a/kraken/KRRenderPass.h b/kraken/KRRenderPass.h index ed851f3..2607274 100644 --- a/kraken/KRRenderPass.h +++ b/kraken/KRRenderPass.h @@ -48,15 +48,21 @@ public: bool keepColor; bool clearDepth; bool keepDepth; + bool clearStencil; + bool keepStencil; bool finalPass; + hydra::Vector4 clearColorValue; + float clearDepthValue; + uint32_t clearStencilValue; }; void create(KRDevice& device, VkFormat swapChainImageFormat, VkFormat depthImageFormat, const RenderPassInfo& info); void destroy(KRDevice& device); - void begin(VkCommandBuffer& commandBuffer, KRSurface& surface, const hydra::Vector4& clearColor); + void begin(VkCommandBuffer& commandBuffer, KRSurface& surface); void end(VkCommandBuffer& commandBuffer); // private: VkRenderPass m_renderPass; + RenderPassInfo m_info; }; diff --git a/kraken/KRSurface.cpp b/kraken/KRSurface.cpp index 33df9bd..4bd447a 100644 --- a/kraken/KRSurface.cpp +++ b/kraken/KRSurface.cpp @@ -201,10 +201,16 @@ KrResult KRSurface::createSwapChain() KRRenderPass::RenderPassInfo info{}; info.clearColor = true; info.keepColor = true; - info.clearDepth = true; - info.keepDepth = false; - info.finalPass = false; info.clearColorValue = Vector4::Zero(); + + info.clearDepth = true; + info.keepDepth = true; + info.clearDepthValue = 1.0f; + + info.clearStencil = true; + info.keepStencil = true; + info.clearStencilValue = 0; + info.finalPass = false; m_forwardOpaquePass->create(*device, selectedSurfaceFormat.format, depthImageFormat, info); info.clearColor = true;