Skip to content

Commit

Permalink
Hydrogent: moved PS main source to USD renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Nov 1, 2023
1 parent 0b1cb72 commit 8161252
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 27 deletions.
25 changes: 0 additions & 25 deletions Hydrogent/src/HnRenderDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -118,8 +95,6 @@ HnRenderDelegate::HnRenderDelegate(const CreateInfo& CI) :
USDRendererCI.InputLayout.LayoutElements = Inputs;
USDRendererCI.InputLayout.NumElements = _countof(Inputs);

USDRendererCI.GetPSMainSource = GetPbrPSMainSource;

return USDRendererCI;
}()),
},
Expand Down
2 changes: 1 addition & 1 deletion Hydrogent/src/Tasks/HnSetupRenderingTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ void HnSetupRenderingTask::Execute(pxr::HdTaskContext* TaskCtx)
auto* pCtx = static_cast<HnRenderDelegate*>(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);
Expand Down
35 changes: 34 additions & 1 deletion PBR/src/USD_Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
{
}

Expand Down

0 comments on commit 8161252

Please sign in to comment.