Now properly clearing depth textures

This commit is contained in:
antopilo
2025-03-23 16:56:57 -04:00
parent e8fda9c544
commit b30f3192b6
3 changed files with 15 additions and 10 deletions

View File

@@ -38,21 +38,25 @@ void RenderPass::Execute(PassRenderContext& ctx, PassAttachments& inputs)
void RenderPass::ClearAttachments(PassRenderContext& ctx, PassAttachments& inputs)
{
// Clear all color attachments
for (int i = 0; i < std::size(Attachments); i++)
int attachmentIndex = 0;
for (int i = 0; i < std::size(inputs); i++)
{
auto& texture = inputs[i];
auto& spec = Attachments[i];
if (spec.ClearOnLoad)
Ref<VulkanImage> input = inputs[i];
if (input->GetUsage() == ImageUsage::Depth)
{
if (texture->GetUsage() != ImageUsage::Depth)
if (DepthAttachment.ClearOnLoad)
{
ctx.commandBuffer.ClearColorImage(texture, this->ClearColor);
ctx.commandBuffer.ClearDepthImage(input);
}
else
}
else if(input->GetUsage() != ImageUsage::Depth)
{
if (Attachments[attachmentIndex].ClearOnLoad)
{
ctx.commandBuffer.ClearDepthImage(texture);
ctx.commandBuffer.ClearColorImage(input, this->ClearColor);
}
attachmentIndex++;
}
}
}

View File

@@ -22,7 +22,7 @@ ShadowRenderPipeline::ShadowRenderPipeline()
ShadowPipeline = RenderPipeline();
auto& shadowPass = ShadowPipeline.AddPass("Shadow");
shadowPass.AddAttachment("Depth", ImageFormat::D32F, ImageUsage::Depth);
shadowPass.AddAttachment("Depth", ImageFormat::D32F, ImageUsage::Depth, true);
shadowPass.SetShaders(shaderMgr.GetShader("shadow_vert"), shaderMgr.GetShader("shadow_frag"));
shadowPass.SetPushConstant<GBufferConstant>(gbufferConstant);
shadowPass.SetPreRender([&](PassRenderContext& ctx) {

View File

@@ -119,6 +119,7 @@ VulkanImage::VulkanImage(ImageFormat inFormat, Vector2 inSize, ImageUsage usage)
drawImageUsages |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
drawImageUsages |= VK_IMAGE_USAGE_SAMPLED_BIT;
drawImageUsages |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
drawImageUsages |= VK_IMAGE_USAGE_TRANSFER_DST_BIT;
}
VkImageCreateInfo imgCreateInfo = VulkanInit::ImageCreateInfo(static_cast<VkFormat>(inFormat), drawImageUsages, vkExtent);