/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Code/Engine/RendererCore/Pipeline/Implementation/Passes/BlurPass.cpp
113 строк
4 KB
Sanakan8472
Render Graph (#1948)
03 июн 2026, 10:19
Не верифицирован
03 июн 2026, 10:19
60bb12c
Код
Авторство
О чём код?
#include <RendererCore/RendererCorePCH.h> #include <Foundation/IO/TypeVersionContext.h> #include <RendererCore/Pipeline/Passes/BlurPass.h> #include <RendererCore/Pipeline/View.h> #include <RendererCore/RenderContext/RenderContext.h> #include <Core/Graphics/Geometry.h> #include <RendererCore/../../../Data/Base/Shaders/Pipeline/BlurConstants.h> // clang-format off EZ_BEGIN_DYNAMIC_REFLECTED_TYPE(ezBlurPass, 1, ezRTTIDefaultAllocator<ezBlurPass>) { EZ_BEGIN_PROPERTIES { EZ_MEMBER_PROPERTY("Input", m_PinInput), EZ_MEMBER_PROPERTY("Output", m_PinOutput), EZ_ACCESSOR_PROPERTY("Radius", GetRadius, SetRadius)->AddAttributes(new ezDefaultValueAttribute(15)), } EZ_END_PROPERTIES; EZ_BEGIN_ATTRIBUTES { new ezCategoryAttribute("Utilities") } EZ_END_ATTRIBUTES; } EZ_END_DYNAMIC_REFLECTED_TYPE; // clang-format on ezBlurPass::ezBlurPass() : ezRenderPipelinePass("BlurPass") { { // Load shader. m_hShader = ezResourceManager::LoadResource<ezShaderResource>("Shaders/Pipeline/Blur.ezShader"); EZ_ASSERT_DEV(m_hShader.IsValid(), "Could not load blur shader!"); } { m_hBlurCB = ezRenderContext::CreateConstantBufferStorage<ezBlurConstants>(); } } ezBlurPass::~ezBlurPass() { ezRenderContext::DeleteConstantBufferStorage(m_hBlurCB); } ezStatus ezBlurPass::AddRenderPasses(const ezViewData& viewData, const ezCamera& camera, ezRenderGraph& ref_graph, const ezArrayPtr<const ezRenderPipelinePinConnection> inputs, ezArrayPtr<ezRenderPipelinePinConnection> outputs) { ezRenderGraphTextureHandle hInput = inputs[m_PinInput.m_uiInputIndex].m_TextureHandle; if (hInput.IsInvalidated()) return ezStatus(ezFmt("Input: Not connected")); const ezGALTextureCreationDescription inputDesc = ref_graph.GetTextureDesc(hInput); ezRenderGraphTextureHandle hOutput = ref_graph.CreateTexture(inputDesc); outputs[m_PinOutput.m_uiOutputIndex].m_TextureHandle = hOutput; auto pass = ref_graph.AddGraphicsPass("Blur"); pass.AddColorTarget(hOutput, {}, ezGALRenderTargetLoadOp::Clear); pass.SetClearColor(0, ezColor(1.0f, 0.0f, 0.0f)); pass.ReadTexture(hInput, {}, ezGALResourceState::ShaderResource, ezGALShaderStageFlags::PixelShader); pass.SetStereoscopic(camera.IsStereoscopic()); pass.SetExecuteCallback([=](const ezRenderGraphContext& ctx) { const ezRenderViewContext& renderViewContext = *ctx.GetUserData<ezRenderViewContext>(); renderViewContext.UpdateViewport(); renderViewContext.m_pRenderContext->BindShader(m_hShader); renderViewContext.m_pRenderContext->BindNullMeshBuffer(ezGALPrimitiveTopology::Triangles, 1); ezBindGroupBuilder& bindGroup = renderViewContext.m_pRenderContext->GetBindGroup(); bindGroup.BindTexture("Input", ctx.ResolveTexture(hInput)); bindGroup.BindBuffer("ezBlurConstants", m_hBlurCB); renderViewContext.m_pRenderContext->DrawMeshBuffer().IgnoreResult(); }); return EZ_SUCCESS; } ezResult ezBlurPass::Serialize(ezStreamWriter& inout_stream) const { EZ_SUCCEED_OR_RETURN(SUPER::Serialize(inout_stream)); inout_stream << m_iRadius; return EZ_SUCCESS; } ezResult ezBlurPass::Deserialize(ezStreamReader& inout_stream) { EZ_SUCCEED_OR_RETURN(SUPER::Deserialize(inout_stream)); const ezUInt32 uiVersion = ezTypeVersionReadContext::GetContext()->GetTypeVersion(GetStaticRTTI()); EZ_IGNORE_UNUSED(uiVersion); inout_stream >> m_iRadius; return EZ_SUCCESS; } void ezBlurPass::SetRadius(ezInt32 iRadius) { m_iRadius = iRadius; ezBlurConstants* cb = ezRenderContext::GetConstantBufferData<ezBlurConstants>(m_hBlurCB); cb->BlurRadius = m_iRadius; } ezInt32 ezBlurPass::GetRadius() const { return m_iRadius; } EZ_STATICLINK_FILE(RendererCore, RendererCore_Pipeline_Implementation_Passes_BlurPass);