Files
HelloVulkan/Engine/src/Renderer/Passes/BloomPass.cpp
T
atdunbg 718a658f5d refactor: 解耦重构——还清四处架构债(对齐 UE/Unity 分层)
- SceneRenderer:场景→渲染数据翻译层(UE FSceneRenderer / Unity CullingResults
  模式),收口相机/灯光/光空间矩阵/双视图剔除,Renderer 只编排
- pass 对象化(Unity ScriptableRenderPass 模式):8 个 pass lambda 拆为
  Passes::{Shadow,Forward,Bloom,Tonemap,ImGui,Present},BuildGraph 超级函数消失;
  SceneGpu/FullscreenGpu 承接共享装配
- 中性 AssetRef(Core 层):ECS 组件不再依赖 Assets 模块(Unity InstanceID 思路)
- IAssetUploader 接口:AssetManager 不感知 Vulkan 具体类,上传服务由渲染层
  VulkanAssetUploader 提供
- Renderer 公共 API 不变(App 层零改动),编译零错误 validation 零警告
2026-09-23 12:02:49 +08:00

76 lines
3.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// Created by atdunbg on 2026/9/23.
//
#include <Engine/Renderer/Passes/BloomPass.h>
#include <Engine/Core/FrameContext.h>
namespace Engine::Passes
{
BloomPass::BloomPass(FullscreenGpu& gpu, PostProcessParams& params,
RG::TextureHandle hdrColor,
RG::TextureHandle bloomA, RG::TextureHandle bloomB)
: m_Gpu(gpu), m_Params(params),
m_HDR(hdrColor), m_A(bloomA), m_B(bloomB)
{
m_ExtractSets.resize(kMaxFramesInFlight);
m_BlurHSets.resize(kMaxFramesInFlight);
m_BlurVSets.resize(kMaxFramesInFlight);
for (u32 slot = 0; slot < kMaxFramesInFlight; ++slot) {
m_ExtractSets[slot] = m_Gpu.AllocateSet();
m_BlurHSets[slot] = m_Gpu.AllocateSet();
m_BlurVSets[slot] = m_Gpu.AllocateSet();
}
}
void BloomPass::Register(RG::RenderGraph& rg)
{
// Extract:HDR → 半分辨率 A(软阈值由 frag 的 param0 传入)
rg.AddPass("BloomExtract",
[this](RG::RenderGraphContext& ctx) {
m_Gpu.RecordFullscreen(ctx, ctx.View(m_A), m_Gpu.extractFrag,
m_ExtractSets[ctx.frame.frameSlot],
FullscreenPush{0.0f, m_Params.bloomThreshold, 0.0f, 0.0f});
})
.Read(m_HDR, RG::ResourceUse::ShaderRead,
vk::ShaderStageFlagBits::eFragment)
.Write(m_A, RG::ResourceUse::ColorAttachment);
// BlurH:A → B(水平步长经 push 传入)
rg.AddPass("BloomBlurH",
[this](RG::RenderGraphContext& ctx) {
m_Gpu.RecordFullscreen(ctx, ctx.View(m_B), m_Gpu.blurFrag,
m_BlurHSets[ctx.frame.frameSlot],
FullscreenPush{0.0f,
1.0f / ctx.extent.width, 0.0f,
0.0f});
})
.Read(m_A, RG::ResourceUse::ShaderRead,
vk::ShaderStageFlagBits::eFragment)
.Write(m_B, RG::ResourceUse::ColorAttachment);
// BlurV:B → A(垂直步长)
rg.AddPass("BloomBlurV",
[this](RG::RenderGraphContext& ctx) {
m_Gpu.RecordFullscreen(ctx, ctx.View(m_A), m_Gpu.blurFrag,
m_BlurVSets[ctx.frame.frameSlot],
FullscreenPush{0.0f, 0.0f,
1.0f / ctx.extent.height,
0.0f});
})
.Read(m_B, RG::ResourceUse::ShaderRead,
vk::ShaderStageFlagBits::eFragment)
.Write(m_A, RG::ResourceUse::ColorAttachment);
}
void BloomPass::OnTargetsRebuilt(RG::RenderGraph& rg)
{
for (u32 slot = 0; slot < kMaxFramesInFlight; ++slot) {
m_Gpu.UpdateSetInput(m_ExtractSets[slot], 0, rg, m_HDR, slot);
m_Gpu.UpdateSetInput(m_BlurHSets[slot], 0, rg, m_A, slot);
m_Gpu.UpdateSetInput(m_BlurVSets[slot], 0, rg, m_B, slot);
}
}
} // namespace Engine::Passes