Progress on render pipeline and render pass abstraction

This commit is contained in:
antopilo
2025-01-06 14:53:13 -05:00
parent ab09f8efb5
commit 0f5172eb04
4 changed files with 182 additions and 33 deletions

View File

@@ -42,29 +42,84 @@ void VkSceneRenderer::Init()
ModelMatrixMapping.clear();
MeshMaterialMapping.clear();
auto renderPipelineOpaque = RenderPipeline({1280, 720});
auto renderPipelineOpaque = RenderPipeline();
auto& gBufferPass = renderPipelineOpaque.AddPass("GBuffer");
gBufferPass.AddAttachment("Albedo", ImageFormat::RGBA8);
gBufferPass.AddAttachment("Normal", ImageFormat::RGBA8);
gBufferPass.AddAttachment("Material", ImageFormat::RGBA8);
gBufferPass.AddAttachment("Depth", ImageFormat::D32F);
gBufferPass.SetPreRender([](PassRenderContext& context) {
});
gBufferPass.SetRender([](PassRenderContext& context) {
auto& ssaoPass = renderPipelineOpaque.AddPass("SSAO");
ssaoPass.AddInput("Normal");
ssaoPass.AddInput("Depth");
ssaoPass.AddAttachment("SSAO", ImageFormat::RGBA8);
});
gBufferPass.SetPostRender([](PassRenderContext& context) {
auto& shadingPass = renderPipelineOpaque.AddPass("Shading");
shadingPass.AddInput("Albedo");
shadingPass.AddInput("Normal");
shadingPass.AddInput("Material");
shadingPass.AddInput("SSAO");
shadingPass.AddInput("Depth");
shadingPass.AddAttachment("Output", ImageFormat::RGBA16F);
});
renderPipelineOpaque.Execute({});
RenderPipeline bloomPipeline = RenderPipeline();
auto& thresholdPass = bloomPipeline.AddPass("Threshold");
auto& thresholdOuput = thresholdPass.AddAttachment("ThresholdOutput", ImageFormat::RGBA16F);
//thresholdPass.AddInput("Source");
// Downsample
const uint32_t iterationCount = 4;
std::vector<TextureAttachment> downsampleAttachments;
for (int i = 0; i < iterationCount; i++)
{
const std::string passName = "Downsample" + std::to_string(i);
auto& downsamplePass = bloomPipeline.AddPass(passName);
auto& downsampleOutput = downsamplePass.AddAttachment("DownsampleOutput", ImageFormat::RGBA16F);
downsampleAttachments.push_back(downsampleOutput);
if (i == 0)
{ // Initial downsample from source
downsamplePass.AddInput(thresholdOuput);
}
else
{ // Downsample previous pass
const uint32_t previousIndex = iterationCount - i - 1;
; downsamplePass.AddInput(downsampleAttachments[previousIndex]);
}
}
// Blur & Upsample
std::vector<TextureAttachment> upsampleAttachments;
for (int i = 0; i < iterationCount; i++)
{
auto& blurHPass = bloomPipeline.AddPass("BlurH" + std::to_string(i));
auto& blurHOutput = blurHPass.AddAttachment("BlurHOutput", ImageFormat::RGBA16F);
blurHPass.AddInput(downsampleAttachments[4 - i - 1]);
auto& blurVPass = bloomPipeline.AddPass("BlurV" + std::to_string(i));
auto& blurVOutput = blurVPass.AddAttachment("BlurVOutput", ImageFormat::RGBA16F);
blurVPass.AddInput(blurHOutput);
auto& upsamplePass = bloomPipeline.AddPass("Upsample" + std::to_string(i));
auto& upsampleOutput = upsamplePass.AddAttachment("UpsampleOutput", ImageFormat::RGBA16F);
if (i == 0)
{
upsamplePass.AddInput(upsampleAttachments[i - 1]);
}
else
{
upsamplePass.AddInput(upsampleAttachments[i - 1]);
}
upsamplePass.AddInput(blurVOutput);
upsampleAttachments.push_back(upsampleOutput);
}
// Final composition
auto& finalPass = bloomPipeline.AddPass("Final");
finalPass.AddAttachment("FinalOutput", ImageFormat::RGBA16F);
std::vector<std::string> inputs = { "Source", "Lens"};
bloomPipeline.Execute(inputs);
}
void VkSceneRenderer::BeginScene(RenderContext inContext)
@@ -453,6 +508,18 @@ void VkSceneRenderer::CreateDescriptors()
vkUpdateDescriptorSets(device, 1, &samplerWrite, 0, nullptr);
}
void VkSceneRenderer::CreatePipelines()
{
GBufferPipeline = RenderPipeline();
auto& gBufferPass = GBufferPipeline.AddPass("GBuffer");
gBufferPass.SetShaders(Shaders["basic_vert"], Shaders["basic_frag"]);
gBufferPass.AddAttachment("Albedo", ImageFormat::RGBA8);
gBufferPass.AddAttachment("Normal", ImageFormat::RGBA16F);
gBufferPass.AddAttachment("Material", ImageFormat::RGBA8);
gBufferPass.AddAttachment("Depth", ImageFormat::D32F, ImageUsage::Depth);
GBufferPipeline.Build();
}
void VkSceneRenderer::SetGBufferSize(const Vector2& size)
{
GBufferAlbedo = CreateRef<VulkanImage>(ImageFormat::RGBA16F, size);