diff --git a/Hydrogent/interface/HnRenderPass.hpp b/Hydrogent/interface/HnRenderPass.hpp index 460434db..c4898fda 100644 --- a/Hydrogent/interface/HnRenderPass.hpp +++ b/Hydrogent/interface/HnRenderPass.hpp @@ -29,6 +29,8 @@ #include "pxr/imaging/hd/types.h" #include "pxr/imaging/hd/renderPass.h" +#include "HnTypes.hpp" + namespace Diligent { @@ -38,6 +40,20 @@ namespace USD class HnMesh; class HnMaterial; +struct HnMeshRenderParams +{ + HN_RENDER_MODE RenderMode = HN_RENDER_MODE_SOLID; + + int DebugView = 0; + float OcclusionStrength = 1; + float EmissionScale = 1; + float IBLScale = 1; + + float4 WireframeColor = float4(1, 1, 1, 1); + + float4x4 Transform = float4x4::Identity(); +}; + /// Hydra render pass implementation in Hydrogent. class HnRenderPass final : public pxr::HdRenderPass { @@ -48,6 +64,11 @@ class HnRenderPass final : public pxr::HdRenderPass HnRenderPass(pxr::HdRenderIndex* pIndex, const pxr::HdRprimCollection& Collection); + void SetMeshRenderParams(const HnMeshRenderParams& Params) + { + m_Params = Params; + } + protected: // Virtual API: Execute the buckets corresponding to renderTags; // renderTags.empty() implies execute everything. @@ -65,6 +86,8 @@ class HnRenderPass final : public pxr::HdRenderPass const HnMaterial& Material); private: + HnMeshRenderParams m_Params; + pxr::HdRenderIndex::HdDrawItemPtrVector m_DrawItems; unsigned int m_CollectionVersion = ~0u; diff --git a/Hydrogent/interface/HnRenderPassState.hpp b/Hydrogent/interface/HnRenderPassState.hpp index 270a77b9..e9436eb8 100644 --- a/Hydrogent/interface/HnRenderPassState.hpp +++ b/Hydrogent/interface/HnRenderPassState.hpp @@ -68,15 +68,6 @@ class HnRenderPassState final : public pxr::HdRenderPassState m_NumRenderTargets = NumRTs; } - void SetRenderMode(HN_RENDER_MODE RenderMode) - { - m_RenderMode = RenderMode; - } - HN_RENDER_MODE GetRenderMode() const - { - return m_RenderMode; - } - void SetFrontFaceCCW(bool FrontFaceCCW) { m_FrontFaceCCW = FrontFaceCCW; @@ -86,51 +77,6 @@ class HnRenderPassState final : public pxr::HdRenderPassState return m_FrontFaceCCW; } - void SetDebugView(int DebugView) - { - m_DebugView = DebugView; - } - int GetDebugView() const - { - return m_DebugView; - } - - void SetOcclusionStrength(float OcclusionStrength) - { - m_OcclusionStrength = OcclusionStrength; - } - float GetOcclusionStrength() const - { - return m_OcclusionStrength; - } - - void SetEmissionScale(float EmissionScale) - { - m_EmissionScale = EmissionScale; - } - float GetEmissionScale() const - { - return m_EmissionScale; - } - - void SetIBLScale(float IBLScale) - { - m_IBLScale = IBLScale; - } - float GetIBLScale() const - { - return m_IBLScale; - } - - void SetTransform(const float4x4& Transform) - { - m_Transform = Transform; - } - const float4x4& GetTransform() const - { - return m_Transform; - } - Uint32 GetNumRenderTargets() const { return m_NumRenderTargets; @@ -154,16 +100,7 @@ class HnRenderPassState final : public pxr::HdRenderPassState std::array m_RTVFormats = {}; TEXTURE_FORMAT m_DepthFormat = TEX_FORMAT_UNKNOWN; - HN_RENDER_MODE m_RenderMode = HN_RENDER_MODE_SOLID; - bool m_FrontFaceCCW = false; - - int m_DebugView = 0; - float m_OcclusionStrength = 1; - float m_EmissionScale = 1; - float m_IBLScale = 1; - - float4x4 m_Transform = float4x4::Identity(); }; } // namespace USD diff --git a/Hydrogent/interface/Tasks/HnRenderRprimsTask.hpp b/Hydrogent/interface/Tasks/HnRenderRprimsTask.hpp index d61e5a61..8f076f23 100644 --- a/Hydrogent/interface/Tasks/HnRenderRprimsTask.hpp +++ b/Hydrogent/interface/Tasks/HnRenderRprimsTask.hpp @@ -27,6 +27,9 @@ #pragma once #include "HnTask.hpp" +#include "HnTypes.hpp" + +#include "../../../Common/interface/BasicMath.hpp" #include "pxr/imaging/hd/renderPass.h" @@ -38,10 +41,30 @@ namespace USD struct HnRenderRprimsTaskParams { + HN_RENDER_MODE RenderMode = HN_RENDER_MODE_SOLID; + + int DebugView = 0; + float OcclusionStrength = 1; + float EmissionScale = 1; + float IBLScale = 1; + + float4 WireframeColor = float4(1, 1, 1, 1); + + float4x4 Transform = float4x4::Identity(); + constexpr bool operator==(const HnRenderRprimsTaskParams& rhs) const { - return true; + // clang-format off + return RenderMode == rhs.RenderMode && + DebugView == rhs.DebugView && + OcclusionStrength == rhs.OcclusionStrength && + EmissionScale == rhs.EmissionScale && + IBLScale == rhs.IBLScale && + WireframeColor == rhs.WireframeColor && + Transform == rhs.Transform; + // clang-format on } + constexpr bool operator!=(const HnRenderRprimsTaskParams& rhs) const { return !(*this == rhs); @@ -70,6 +93,9 @@ class HnRenderRprimsTask final : public HnTask return m_RenderTags; } +private: + void UpdateRenderPassParams(const HnRenderRprimsTaskParams& Params); + private: pxr::TfTokenVector m_RenderTags; pxr::HdRenderPassSharedPtr m_RenderPass; diff --git a/Hydrogent/src/HnRenderPass.cpp b/Hydrogent/src/HnRenderPass.cpp index 7809b2a4..803af6b6 100644 --- a/Hydrogent/src/HnRenderPass.cpp +++ b/Hydrogent/src/HnRenderPass.cpp @@ -59,7 +59,6 @@ struct HnRenderPass::RenderState IDeviceContext* const pCtx; IBuffer* const pPBRAttribsCB; - const HnRenderPassState& RPState; const PBR_Renderer::ALPHA_MODE AlphaMode; USD_Renderer::PbrPsoCacheAccessor PbrPSOCache; @@ -96,19 +95,17 @@ void HnRenderPass::_Execute(const pxr::HdRenderPassStateSharedPtr& RPState, RenderState State{ pRenderDelegate->GetDeviceContext(), USDRenderer->GetPBRAttribsCB(), - static_cast(*RPState), MaterialTagToPbrAlphaMode(m_MaterialTag), }; - GraphicsPipelineDesc GraphicsDesc = State.RPState.GetGraphicsPipelineDesc(); - const HN_RENDER_MODE RenderMode = State.RPState.GetRenderMode(); - if (RenderMode == HN_RENDER_MODE_SOLID) + GraphicsPipelineDesc GraphicsDesc = static_cast(RPState.get())->GetGraphicsPipelineDesc(); + if (m_Params.RenderMode == HN_RENDER_MODE_SOLID) { GraphicsDesc.PrimitiveTopology = PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; State.PbrPSOCache = USDRenderer->GetPbrPsoCacheAccessor(GraphicsDesc); VERIFY_EXPR(State.PbrPSOCache); } - else if (RenderMode == HN_RENDER_MODE_MESH_EDGES) + else if (m_Params.RenderMode == HN_RENDER_MODE_MESH_EDGES) { GraphicsDesc.PrimitiveTopology = PRIMITIVE_TOPOLOGY_LINE_LIST; State.WireframePSOCache = USDRenderer->GetWireframePsoCacheAccessor(GraphicsDesc); @@ -224,9 +221,7 @@ void HnRenderPass::RenderMesh(RenderState& State, } } - const auto RenderMode = State.RPState.GetRenderMode(); - - auto* pIB = (RenderMode == HN_RENDER_MODE_MESH_EDGES) ? + auto* pIB = (m_Params.RenderMode == HN_RENDER_MODE_MESH_EDGES) ? Mesh.GetEdgeIndexBuffer() : Mesh.GetTriangleIndexBuffer(); @@ -236,7 +231,7 @@ void HnRenderPass::RenderMesh(RenderState& State, auto PSOFlags = PBR_Renderer::PSO_FLAG_ENABLE_CUSTOM_DATA_OUTPUT; IPipelineState* pPSO = nullptr; - if (RenderMode == HN_RENDER_MODE_SOLID) + if (m_Params.RenderMode == HN_RENDER_MODE_SOLID) { if (pNormalsVB != nullptr) PSOFlags |= PBR_Renderer::PSO_FLAG_USE_VERTEX_NORMALS; @@ -260,7 +255,7 @@ void HnRenderPass::RenderMesh(RenderState& State, "This may indicate an issue in how alpha mode is determined in the material, or (less likely) an issue in Rprim sorting by Hydra."); pPSO = State.PbrPSOCache.Get({PSOFlags, static_cast(State.AlphaMode), /*DoubleSided = */ false}, true); } - else if (RenderMode == HN_RENDER_MODE_MESH_EDGES) + else if (m_Params.RenderMode == HN_RENDER_MODE_MESH_EDGES) { pPSO = State.WireframePSOCache.Get({PSOFlags, /*DoubleSided = */ false}, true); } @@ -284,7 +279,7 @@ void HnRenderPass::RenderMesh(RenderState& State, { MapHelper pDstShaderAttribs{State.pCtx, State.pPBRAttribsCB, MAP_WRITE, MAP_FLAG_DISCARD}; - pDstShaderAttribs->Transforms.NodeMatrix = Mesh.GetTransform() * State.RPState.GetTransform(); + pDstShaderAttribs->Transforms.NodeMatrix = Mesh.GetTransform() * m_Params.Transform; pDstShaderAttribs->Transforms.JointCount = 0; static_assert(sizeof(pDstShaderAttribs->Material) == sizeof(ShaderAttribs), "The sizeof(PBRMaterialShaderInfo) is inconsistent with sizeof(ShaderAttribs)"); @@ -292,13 +287,13 @@ void HnRenderPass::RenderMesh(RenderState& State, auto& RendererParams = pDstShaderAttribs->Renderer; - RendererParams.DebugViewType = State.RPState.GetDebugView(); - RendererParams.OcclusionStrength = State.RPState.GetOcclusionStrength(); - RendererParams.EmissionScale = State.RPState.GetEmissionScale(); - RendererParams.IBLScale = State.RPState.GetIBLScale(); + RendererParams.DebugViewType = m_Params.DebugView; + RendererParams.OcclusionStrength = m_Params.OcclusionStrength; + RendererParams.EmissionScale = m_Params.EmissionScale; + RendererParams.IBLScale = m_Params.IBLScale; - RendererParams.PrefilteredCubeMipLevels = 5; //m_Settings.UseIBL ? static_cast(m_pPrefilteredEnvMapSRV->GetTexture()->GetDesc().MipLevels) : 0.f; - RendererParams.WireframeColor = float4{1, 1, 1, 1}; //Attribs.WireframeColor; + RendererParams.PrefilteredCubeMipLevels = 5; //m_Settings.UseIBL ? static_cast(m_pPrefilteredEnvMapSRV->GetTexture()->GetDesc().MipLevels) : 0.f; + RendererParams.WireframeColor = m_Params.WireframeColor; RendererParams.HighlightColor = float4{0, 0, 0, 0}; // Tone mapping is performed in the post-processing pass @@ -313,7 +308,7 @@ void HnRenderPass::RenderMesh(RenderState& State, } State.pCtx->CommitShaderResources(pSRB, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); - DrawIndexedAttribs DrawAttrs = (RenderMode == HN_RENDER_MODE_MESH_EDGES) ? + DrawIndexedAttribs DrawAttrs = (m_Params.RenderMode == HN_RENDER_MODE_MESH_EDGES) ? DrawIndexedAttribs{Mesh.GetNumEdges() * 2, VT_UINT32, DRAW_FLAG_VERIFY_ALL} : DrawIndexedAttribs{Mesh.GetNumTriangles() * 3, VT_UINT32, DRAW_FLAG_VERIFY_ALL}; diff --git a/Hydrogent/src/Tasks/HnRenderRprimsTask.cpp b/Hydrogent/src/Tasks/HnRenderRprimsTask.cpp index 9bd54033..f6ac959e 100644 --- a/Hydrogent/src/Tasks/HnRenderRprimsTask.cpp +++ b/Hydrogent/src/Tasks/HnRenderRprimsTask.cpp @@ -27,6 +27,7 @@ #include "Tasks/HnRenderRprimsTask.hpp" #include "HnRenderPassState.hpp" +#include "HnRenderPass.hpp" #include "HnTokens.hpp" #include "pxr/imaging/hd/renderDelegate.h" @@ -48,6 +49,22 @@ HnRenderRprimsTask::~HnRenderRprimsTask() { } +void HnRenderRprimsTask::UpdateRenderPassParams(const HnRenderRprimsTaskParams& Params) +{ + if (!m_RenderPass) + return; + + HnMeshRenderParams RenderPassParams; + RenderPassParams.RenderMode = Params.RenderMode; + RenderPassParams.DebugView = Params.DebugView; + RenderPassParams.OcclusionStrength = Params.OcclusionStrength; + RenderPassParams.EmissionScale = Params.EmissionScale; + RenderPassParams.IBLScale = Params.IBLScale; + RenderPassParams.WireframeColor = Params.WireframeColor; + RenderPassParams.Transform = Params.Transform; + static_cast(m_RenderPass.get())->SetMeshRenderParams(RenderPassParams); +} + void HnRenderRprimsTask::Sync(pxr::HdSceneDelegate* Delegate, pxr::HdTaskContext* TaskCtx, pxr::HdDirtyBits* DirtyBits) @@ -71,6 +88,8 @@ void HnRenderRprimsTask::Sync(pxr::HdSceneDelegate* Delegate, pxr::HdRenderIndex& Index = Delegate->GetRenderIndex(); pxr::HdRenderDelegate* RenderDelegate = Index.GetRenderDelegate(); m_RenderPass = RenderDelegate->CreateRenderPass(&Index, Collection); + // Need to set params for the new render pass. + *DirtyBits |= pxr::HdChangeTracker::DirtyParams; } else { @@ -85,7 +104,7 @@ void HnRenderRprimsTask::Sync(pxr::HdSceneDelegate* Delegate, if (ParamsValue.IsHolding()) { HnRenderRprimsTaskParams Params = ParamsValue.UncheckedGet(); - (void)Params; + UpdateRenderPassParams(Params); } else { diff --git a/Hydrogent/src/Tasks/HnSetupRenderingTask.cpp b/Hydrogent/src/Tasks/HnSetupRenderingTask.cpp index bbaa579e..8b398890 100644 --- a/Hydrogent/src/Tasks/HnSetupRenderingTask.cpp +++ b/Hydrogent/src/Tasks/HnSetupRenderingTask.cpp @@ -64,13 +64,6 @@ HnSetupRenderingTask::~HnSetupRenderingTask() void HnSetupRenderingTask::UpdateRenderPassState(const HnSetupRenderingTaskParams& Params) { - m_RenderPassState->SetRenderMode(Params.RenderMode); - m_RenderPassState->SetDebugView(Params.DebugView); - m_RenderPassState->SetOcclusionStrength(Params.OcclusionStrength); - m_RenderPassState->SetEmissionScale(Params.EmissionScale); - m_RenderPassState->SetIBLScale(Params.IBLScale); - m_RenderPassState->SetTransform(Params.Transform); - VERIFY_EXPR(Params.ColorFormat != TEX_FORMAT_UNKNOWN); m_RenderPassState->SetNumRenderTargets(Params.MeshIdFormat != TEX_FORMAT_UNKNOWN ? 2 : 1); m_RenderPassState->SetRenderTargetFormat(0, Params.ColorFormat); diff --git a/Hydrogent/src/Tasks/HnTaskManager.cpp b/Hydrogent/src/Tasks/HnTaskManager.cpp index ae1bece7..33c3dd80 100644 --- a/Hydrogent/src/Tasks/HnTaskManager.cpp +++ b/Hydrogent/src/Tasks/HnTaskManager.cpp @@ -210,6 +210,8 @@ void HnTaskManager::CreateRenderRprimsTask(const pxr::TfToken& MaterialTag, Task m_ParamsDelegate.SetParameter(RenderRprimsTaskId, pxr::HdTokens->params, TaskParams); m_ParamsDelegate.SetParameter(RenderRprimsTaskId, pxr::HdTokens->collection, Collection); m_ParamsDelegate.SetParameter(RenderRprimsTaskId, pxr::HdTokens->renderTags, RenderTags); + + m_RenderTaskIds.emplace_back(RenderRprimsTaskId); } void HnTaskManager::SetRenderRprimParams(const HnRenderRprimsTaskParams& Params)