From 81612521c8e9bfdf7f3c9753fc870e5d4fa777c6 Mon Sep 17 00:00:00 2001 From: assiduous Date: Tue, 31 Oct 2023 20:49:47 -0700 Subject: [PATCH] Hydrogent: moved PS main source to USD renderer --- Hydrogent/src/HnRenderDelegate.cpp | 25 -------------- Hydrogent/src/Tasks/HnSetupRenderingTask.cpp | 2 +- PBR/src/USD_Renderer.cpp | 35 +++++++++++++++++++- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/Hydrogent/src/HnRenderDelegate.cpp b/Hydrogent/src/HnRenderDelegate.cpp index 1d6a83f3..f05d605f 100644 --- a/Hydrogent/src/HnRenderDelegate.cpp +++ b/Hydrogent/src/HnRenderDelegate.cpp @@ -62,29 +62,6 @@ const pxr::TfTokenVector HnRenderDelegate::SupportedBPrimTypes = }; // clang-format on -static std::string GetPbrPSMainSource(USD_Renderer::PSO_FLAGS PSOFlags) -{ - VERIFY(PSOFlags & USD_Renderer::PSO_FLAG_ENABLE_CUSTOM_DATA_OUTPUT, "Custom output flag is expected to be set"); - return R"( -struct PSOutput -{ - float4 Color : SV_Target0; - float4 MeshID : SV_Target1; - float4 IsSelected : SV_Target2; -}; - -void main(in VSOutput VSOut, - in bool IsFrontFace : SV_IsFrontFace, - out PSOutput PSOut) -{ - PSOut.Color = ComputePbrSurfaceColor(VSOut, IsFrontFace); - - // It is important to set alpha to 1.0 as all targets are rendered with the same blend mode - PSOut.MeshID = float4(g_PBRAttribs.Renderer.CustomData.x, 0.0, 0.0, 1.0); - PSOut.IsSelected = float4(g_PBRAttribs.Renderer.CustomData.y, 0.0, 0.0, 1.0); -} -)"; -} HnRenderDelegate::HnRenderDelegate(const CreateInfo& CI) : m_pDevice{CI.pDevice}, @@ -118,8 +95,6 @@ HnRenderDelegate::HnRenderDelegate(const CreateInfo& CI) : USDRendererCI.InputLayout.LayoutElements = Inputs; USDRendererCI.InputLayout.NumElements = _countof(Inputs); - USDRendererCI.GetPSMainSource = GetPbrPSMainSource; - return USDRendererCI; }()), }, diff --git a/Hydrogent/src/Tasks/HnSetupRenderingTask.cpp b/Hydrogent/src/Tasks/HnSetupRenderingTask.cpp index c174c965..5f026599 100644 --- a/Hydrogent/src/Tasks/HnSetupRenderingTask.cpp +++ b/Hydrogent/src/Tasks/HnSetupRenderingTask.cpp @@ -216,7 +216,7 @@ void HnSetupRenderingTask::Execute(pxr::HdTaskContext* TaskCtx) auto* pCtx = static_cast(m_RenderIndex->GetRenderDelegate())->GetDeviceContext(); pCtx->SetRenderTargets(_countof(pRTVs), pRTVs, Targets.DepthDSV, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); - pCtx->ClearRenderTarget(Targets.FinalColorRTV, m_ClearColor.Data(), RESOURCE_STATE_TRANSITION_MODE_TRANSITION); + pCtx->ClearRenderTarget(Targets.OffscreenColorRTV, m_ClearColor.Data(), RESOURCE_STATE_TRANSITION_MODE_TRANSITION); constexpr float Zero[] = {0, 0, 0, 0}; pCtx->ClearRenderTarget(Targets.MeshIdRTV, Zero, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); pCtx->ClearRenderTarget(Targets.SelectionRTV, Zero, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); diff --git a/PBR/src/USD_Renderer.cpp b/PBR/src/USD_Renderer.cpp index 8a4ce25b..ac5db349 100644 --- a/PBR/src/USD_Renderer.cpp +++ b/PBR/src/USD_Renderer.cpp @@ -33,11 +33,44 @@ namespace Diligent { +static std::string GetUsdPbrPSMainSource(USD_Renderer::PSO_FLAGS PSOFlags) +{ + VERIFY(PSOFlags & USD_Renderer::PSO_FLAG_ENABLE_CUSTOM_DATA_OUTPUT, "Custom output flag is expected to be set"); + return R"( +struct PSOutput +{ + float4 Color : SV_Target0; + float4 MeshID : SV_Target1; + float4 IsSelected : SV_Target2; +}; + +void main(in VSOutput VSOut, + in bool IsFrontFace : SV_IsFrontFace, + out PSOutput PSOut) +{ + PSOut.Color = ComputePbrSurfaceColor(VSOut, IsFrontFace); + + // It is important to set alpha to 1.0 as all targets are rendered with the same blend mode + PSOut.MeshID = float4(g_PBRAttribs.Renderer.CustomData.x, 0.0, 0.0, 1.0); + PSOut.IsSelected = float4(g_PBRAttribs.Renderer.CustomData.y, 0.0, 0.0, 1.0); +} +)"; +} + USD_Renderer::USD_Renderer(IRenderDevice* pDevice, IRenderStateCache* pStateCache, IDeviceContext* pCtx, const CreateInfo& CI) : - PBR_Renderer{pDevice, pStateCache, pCtx, CI} + PBR_Renderer{ + pDevice, + pStateCache, + pCtx, + [](CreateInfo CI) { + if (CI.GetPSMainSource == nullptr) + CI.GetPSMainSource = GetUsdPbrPSMainSource; + return CI; + }(CI), + } { }