Skip to content

Commit

Permalink
clearing depth buffer outside of forward pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Kbz-8 committed Sep 1, 2024
1 parent 820cb54 commit dfa04bc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions ScopEngine/Runtime/Sources/Renderer/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,22 @@ namespace Scop
subresource_range.levelCount = 1;
subresource_range.baseArrayLayer = 0;

VkImageLayout old_layout = m_layout;
TransitionLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, cmd);
if(m_type == ImageType::Color || m_type == ImageType::Cube)
{
VkImageLayout old_layout = m_layout;
TransitionLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, cmd);
subresource_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
VkClearColorValue clear_color = VkClearColorValue({ { color.x, color.y, color.z, color.w } });
vkCmdClearColorImage(cmd, m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clear_color, 1, &subresource_range);
TransitionLayout(old_layout, cmd);
}
else if(m_type == ImageType::Depth)
{
VkClearDepthStencilValue clear_depth_stencil = { 1.0f, 1 };
subresource_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
TransitionLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, cmd);
vkCmdClearDepthStencilImage(cmd, m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clear_depth_stencil, 1, &subresource_range);
}
TransitionLayout(old_layout, cmd);
}

void Image::DestroySampler() noexcept
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ namespace Scop
pipeline_descriptor.depth = &scene.GetDepth();
if(scene.GetForwardData().wireframe)
pipeline_descriptor.mode = VK_POLYGON_MODE_LINE;
pipeline_descriptor.clear_color_attachments = false;
pipeline.Init(pipeline_descriptor);
}

VkCommandBuffer cmd = renderer.GetActiveCommandBuffer();
pipeline.BindPipeline(cmd, 0, { 0.0f, 0.0f, 0.0f, 1.0f });
pipeline.BindPipeline(cmd, 0, {});
for(auto actor : scene.GetActors())
{
ModelData model_data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace Scop
}

m_main_render_texture.Clear(renderer.GetActiveCommandBuffer(), Vec4f{ 0.0f, 0.0f, 0.0f, 1.0f });
scene.GetDepth().Clear(renderer.GetActiveCommandBuffer(), {});

if(scene.GetDescription().render_3D_enabled)
m_forward.Pass(scene, renderer, m_main_render_texture);
Expand Down

0 comments on commit dfa04bc

Please sign in to comment.