From c80067d8f462aa0a7b3b5a7e219f31a20f29ecf7 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sat, 21 Oct 2023 20:47:17 -0700 Subject: [PATCH] Hydrogent: added more render pass state parameters, updated mesh rendering in the render pass --- Hydrogent/include/HnRenderDelegate.hpp | 5 - Hydrogent/include/HnRenderPass.hpp | 18 +-- Hydrogent/include/HnRenderPassState.hpp | 15 ++- Hydrogent/include/HnRendererImpl.hpp | 4 + .../include/Tasks/HnSetupRenderingTask.hpp | 53 +++++++- Hydrogent/include/Tasks/HnTaskController.hpp | 28 +++-- Hydrogent/interface/HnRenderer.hpp | 2 + Hydrogent/src/HnRenderPass.cpp | 114 +++++++++++------- Hydrogent/src/HnRenderPassState.cpp | 6 +- Hydrogent/src/HnRendererImpl.cpp | 16 ++- Hydrogent/src/Tasks/HnSetupRenderingTask.cpp | 19 +++ Hydrogent/src/Tasks/HnTaskController.cpp | 8 ++ 12 files changed, 205 insertions(+), 83 deletions(-) diff --git a/Hydrogent/include/HnRenderDelegate.hpp b/Hydrogent/include/HnRenderDelegate.hpp index 4625c556..7c2981d6 100644 --- a/Hydrogent/include/HnRenderDelegate.hpp +++ b/Hydrogent/include/HnRenderDelegate.hpp @@ -202,11 +202,6 @@ class HnRenderDelegate final : public pxr::HdRenderDelegate IRenderDevice* GetDevice() { return m_pDevice; } IDeviceContext* GetDeviceContext() { return m_pContext; } - // TODO: needs to be dynamic - static constexpr TEXTURE_FORMAT ColorBufferFormat = TEX_FORMAT_R11G11B10_FLOAT; - static constexpr TEXTURE_FORMAT MeshIdFormat = TEX_FORMAT_R32_FLOAT; - static constexpr TEXTURE_FORMAT DepthFormat = TEX_FORMAT_D32_FLOAT; - private: static const pxr::TfTokenVector SupportedRPrimTypes; static const pxr::TfTokenVector SupportedSPrimTypes; diff --git a/Hydrogent/include/HnRenderPass.hpp b/Hydrogent/include/HnRenderPass.hpp index 3f2049cb..895805e8 100644 --- a/Hydrogent/include/HnRenderPass.hpp +++ b/Hydrogent/include/HnRenderPass.hpp @@ -29,9 +29,6 @@ #include "pxr/imaging/hd/types.h" #include "pxr/imaging/hd/renderPass.h" -#include "../../../DiligentCore/Graphics/GraphicsEngine/interface/DeviceContext.h" -#include "../../../DiligentFX/PBR/interface/USD_Renderer.hpp" - namespace Diligent { @@ -40,7 +37,6 @@ namespace USD class HnMesh; class HnMaterial; -class HnRenderPassState; /// Hydra render pass implementation in Hydrogent. class HnRenderPass final : public pxr::HdRenderPass @@ -55,7 +51,7 @@ class HnRenderPass final : public pxr::HdRenderPass protected: // Virtual API: Execute the buckets corresponding to renderTags; // renderTags.empty() implies execute everything. - virtual void _Execute(const pxr::HdRenderPassStateSharedPtr& State, + virtual void _Execute(const pxr::HdRenderPassStateSharedPtr& RPState, const pxr::TfTokenVector& Tags) override final; virtual void _MarkCollectionDirty() override final; @@ -63,16 +59,12 @@ class HnRenderPass final : public pxr::HdRenderPass private: void UpdateDrawItems(const pxr::TfTokenVector& RenderTags); - void RenderMesh(IDeviceContext* pCtx, - const HnRenderPassState& State, - const HnMesh& Mesh, - const HnMaterial& Material); + struct RenderState; + void RenderMesh(RenderState& State, + const HnMesh& Mesh, + const HnMaterial& Material); private: - std::shared_ptr m_USDRenderer; - USD_Renderer::PbrPsoCacheAccessor m_PbrPSOCache; - USD_Renderer::WireframePsoCacheAccessor m_WireframePSOCache; - pxr::HdRenderIndex::HdDrawItemPtrVector m_DrawItems; unsigned int m_CollectionVersion = ~0u; diff --git a/Hydrogent/include/HnRenderPassState.hpp b/Hydrogent/include/HnRenderPassState.hpp index 929d7fb0..0989c7dd 100644 --- a/Hydrogent/include/HnRenderPassState.hpp +++ b/Hydrogent/include/HnRenderPassState.hpp @@ -55,11 +55,11 @@ class HnRenderPassState final : public pxr::HdRenderPassState void Begin(IDeviceContext* pContext); - void SetRTVFormat(Uint32 RT, TEXTURE_FORMAT Fmt) + void SetRenderTargetFormat(Uint32 RT, TEXTURE_FORMAT Fmt) { m_RTVFormats[RT] = Fmt; } - void SetDepthFormat(TEXTURE_FORMAT DepthFormat) + void SetDepthStencilFormat(TEXTURE_FORMAT DepthFormat) { m_DepthFormat = DepthFormat; } @@ -77,6 +77,15 @@ class HnRenderPassState final : public pxr::HdRenderPassState return m_RenderMode; } + void SetFrontFaceCCW(bool FrontFaceCCW) + { + m_FrontFaceCCW = FrontFaceCCW; + } + bool GetFrontFaceCCW() const + { + return m_FrontFaceCCW; + } + void SetDebugView(int DebugView) { m_DebugView = DebugView; @@ -134,6 +143,8 @@ class HnRenderPassState final : public pxr::HdRenderPassState 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; diff --git a/Hydrogent/include/HnRendererImpl.hpp b/Hydrogent/include/HnRendererImpl.hpp index f9e46741..585ff74f 100644 --- a/Hydrogent/include/HnRendererImpl.hpp +++ b/Hydrogent/include/HnRendererImpl.hpp @@ -113,6 +113,10 @@ class HnRendererImpl final : public ObjectBase pxr::HdEngine m_Engine; + static constexpr TEXTURE_FORMAT ColorBufferFormat = TEX_FORMAT_R11G11B10_FLOAT; + static constexpr TEXTURE_FORMAT MeshIdFormat = TEX_FORMAT_R32_FLOAT; + static constexpr TEXTURE_FORMAT DepthFormat = TEX_FORMAT_D32_FLOAT; + RefCntAutoPtr m_ColorBuffer; RefCntAutoPtr m_MeshIdTexture; RefCntAutoPtr m_DepthBufferDSV; diff --git a/Hydrogent/include/Tasks/HnSetupRenderingTask.hpp b/Hydrogent/include/Tasks/HnSetupRenderingTask.hpp index 06f3f8b1..e7705744 100644 --- a/Hydrogent/include/Tasks/HnSetupRenderingTask.hpp +++ b/Hydrogent/include/Tasks/HnSetupRenderingTask.hpp @@ -44,12 +44,30 @@ struct HnSetupRenderingTaskParams constexpr bool operator==(const HnSetupRenderingTaskParams& rhs) const { // clang-format off - return RenderMode == rhs.RenderMode && - DebugView == rhs.DebugView && - OcclusionStrength == rhs.OcclusionStrength && - EmissionScale == rhs.EmissionScale && - IBLScale == rhs.IBLScale && - Transform == rhs.Transform; + return ColorFormat == rhs.ColorFormat && + MeshIdFormat == rhs.MeshIdFormat && + DepthFormat == rhs.DepthFormat && + RenderMode == rhs.RenderMode && + FrontFaceCCW == rhs.FrontFaceCCW && + DebugView == rhs.DebugView && + OcclusionStrength == rhs.OcclusionStrength && + EmissionScale == rhs.EmissionScale && + IBLScale == rhs.IBLScale && + Transform == rhs.Transform && + DepthBias == rhs.DepthBias && + SlopeScaledDepthBias == rhs.SlopeScaledDepthBias && + DepthFunc == rhs.DepthFunc && + DepthBiasEnabled == rhs.DepthBiasEnabled && + DepthTestEnabled == rhs.DepthTestEnabled && + DepthClampEnabled == rhs.DepthClampEnabled && + CullStyle == rhs.CullStyle && + StencilFunc == rhs.StencilFunc && + StencilRef == rhs.StencilRef && + StencilMask == rhs.StencilMask && + StencilFailOp == rhs.StencilFailOp && + StencilZFailOp == rhs.StencilZFailOp && + StencilZPassOp == rhs.StencilZPassOp && + StencilEnabled == rhs.StencilEnabled; // clang-format on } constexpr bool operator!=(const HnSetupRenderingTaskParams& rhs) const @@ -57,14 +75,37 @@ struct HnSetupRenderingTaskParams return !(*this == rhs); } + TEXTURE_FORMAT ColorFormat = TEX_FORMAT_UNKNOWN; + TEXTURE_FORMAT MeshIdFormat = TEX_FORMAT_UNKNOWN; + TEXTURE_FORMAT DepthFormat = TEX_FORMAT_UNKNOWN; + HN_RENDER_MODE RenderMode = HN_RENDER_MODE_SOLID; + bool FrontFaceCCW = false; + int DebugView = 0; float OcclusionStrength = 1; float EmissionScale = 1; float IBLScale = 1; float4x4 Transform = float4x4::Identity(); + + float DepthBias = 0; + float SlopeScaledDepthBias = 0; + pxr::HdCompareFunction DepthFunc = pxr::HdCmpFuncLess; + bool DepthBiasEnabled = false; + bool DepthTestEnabled = true; + bool DepthClampEnabled = false; + + pxr::HdCullStyle CullStyle = pxr::HdCullStyleBack; + + pxr::HdCompareFunction StencilFunc = pxr::HdCmpFuncAlways; + int StencilRef = 0; + int StencilMask = 0xFF; + pxr::HdStencilOp StencilFailOp = pxr::HdStencilOpKeep; + pxr::HdStencilOp StencilZFailOp = pxr::HdStencilOpKeep; + pxr::HdStencilOp StencilZPassOp = pxr::HdStencilOpKeep; + bool StencilEnabled = false; }; /// Post processing task implementation in Hydrogent. diff --git a/Hydrogent/include/Tasks/HnTaskController.hpp b/Hydrogent/include/Tasks/HnTaskController.hpp index 3fdd50ba..0d14f78f 100644 --- a/Hydrogent/include/Tasks/HnTaskController.hpp +++ b/Hydrogent/include/Tasks/HnTaskController.hpp @@ -41,6 +41,7 @@ namespace USD struct HnSetupRenderingTaskParams; struct HnPostProcessTaskParams; +struct HnRenderRprimsTaskParams; /// Task controller implementation in Hydrogent. class HnTaskController @@ -115,6 +116,12 @@ class HnTaskController bool SetTaskParams(TaskUID UID, TaskParamsType&& Params); + template + bool SetTaskParams(const pxr::SdfPath& Id, + TaskParamsType&& Params); + + void SetRenderRprimParams(const HnRenderRprimsTaskParams& Params); + pxr::HdTaskSharedPtr GetTask(TaskUID UID) const; void RemoveTask(TaskUID UID); @@ -235,15 +242,9 @@ void HnTaskController::CreateTask(const pxr::TfToken& TaskId, } template -bool HnTaskController::SetTaskParams(TaskUID UID, - TaskParamsType&& Params) +bool HnTaskController::SetTaskParams(const pxr::SdfPath& TaskId, + TaskParamsType&& Params) { - const auto it = m_TaskUIDs.find(UID); - if (it == m_TaskUIDs.end()) - return false; - - const auto& TaskId = it->second; - TaskParamsType OldParams = m_ParamsDelegate.GetParameter::type>(TaskId, pxr::HdTokens->params); if (OldParams == Params) return false; @@ -254,6 +255,17 @@ bool HnTaskController::SetTaskParams(TaskUID UID, return true; } +template +bool HnTaskController::SetTaskParams(TaskUID UID, + TaskParamsType&& Params) +{ + const auto it = m_TaskUIDs.find(UID); + if (it == m_TaskUIDs.end()) + return false; + + return SetTaskParams(it->second, std::forward(Params)); +} + } // namespace USD } // namespace Diligent diff --git a/Hydrogent/interface/HnRenderer.hpp b/Hydrogent/interface/HnRenderer.hpp index 9ccb0bb6..c8595398 100644 --- a/Hydrogent/interface/HnRenderer.hpp +++ b/Hydrogent/interface/HnRenderer.hpp @@ -89,6 +89,8 @@ struct HnRenderParams float IBLScale = 1; HN_RENDER_MODE RenderMode = HN_RENDER_MODE_SOLID; + + bool FrontFaceCCW = false; }; class IHnRenderer : public IObject diff --git a/Hydrogent/src/HnRenderPass.cpp b/Hydrogent/src/HnRenderPass.cpp index 1f81232c..f1baf7c7 100644 --- a/Hydrogent/src/HnRenderPass.cpp +++ b/Hydrogent/src/HnRenderPass.cpp @@ -32,6 +32,7 @@ #include "pxr/imaging/hd/renderIndex.h" +#include "USD_Renderer.hpp" #include "MapHelper.hpp" namespace Diligent @@ -50,29 +51,23 @@ HnRenderPass::HnRenderPass(pxr::HdRenderIndex* pIndex, const pxr::HdRprimCollection& Collection) : pxr::HdRenderPass{pIndex, Collection} { - HnRenderDelegate* pRenderDelegate = static_cast(pIndex->GetRenderDelegate()); - - m_USDRenderer = pRenderDelegate->GetUSDRenderer(); +} - GraphicsPipelineDesc GraphicsDesc; - // TODO: these parameters should be taken from the render pass state - GraphicsDesc.NumRenderTargets = 2; - GraphicsDesc.RTVFormats[0] = HnRenderDelegate::ColorBufferFormat; - GraphicsDesc.RTVFormats[1] = HnRenderDelegate::MeshIdFormat; - GraphicsDesc.DSVFormat = HnRenderDelegate::DepthFormat; - GraphicsDesc.PrimitiveTopology = PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; - GraphicsDesc.RasterizerDesc.FrontCounterClockwise = true; +struct HnRenderPass::RenderState +{ + IDeviceContext* const pCtx; + IBuffer* const pPBRAttribsCB; - m_PbrPSOCache = m_USDRenderer->GetPbrPsoCacheAccessor(GraphicsDesc); - VERIFY_EXPR(m_PbrPSOCache); + const HnRenderPassState& RPState; + const PBR_Renderer::ALPHA_MODE AlphaMode; - GraphicsDesc.PrimitiveTopology = PRIMITIVE_TOPOLOGY_LINE_LIST; + USD_Renderer::PbrPsoCacheAccessor PbrPSOCache; + USD_Renderer::WireframePsoCacheAccessor WireframePSOCache; - m_WireframePSOCache = m_USDRenderer->GetWireframePsoCacheAccessor(GraphicsDesc); - VERIFY_EXPR(m_WireframePSOCache); -} + IPipelineState* pPSO = nullptr; +}; -void HnRenderPass::_Execute(const pxr::HdRenderPassStateSharedPtr& State, +void HnRenderPass::_Execute(const pxr::HdRenderPassStateSharedPtr& RPState, const pxr::TfTokenVector& Tags) { UpdateDrawItems(Tags); @@ -81,7 +76,7 @@ void HnRenderPass::_Execute(const pxr::HdRenderPassStateSharedPtr& State, // Render pass state is initialized by the setup rendering task, and // passed from the render Rprims task. - if (!State) + if (!RPState) { UNEXPECTED("Render pass state should not be null"); return; @@ -89,7 +84,40 @@ void HnRenderPass::_Execute(const pxr::HdRenderPassStateSharedPtr& State, pxr::HdRenderIndex* pRenderIndex = GetRenderIndex(); HnRenderDelegate* pRenderDelegate = static_cast(pRenderIndex->GetRenderDelegate()); - IDeviceContext* pCtx = pRenderDelegate->GetDeviceContext(); + + auto& USDRenderer = pRenderDelegate->GetUSDRenderer(); + if (!USDRenderer) + { + UNEXPECTED("USD renderer is not initialized"); + return; + } + + RenderState State{ + pRenderDelegate->GetDeviceContext(), + USDRenderer->GetPBRAttribsCB(), + static_cast(*RPState), + PBR_Renderer::ALPHA_MODE_OPAQUE, + }; + + GraphicsPipelineDesc GraphicsDesc = State.RPState.GetGraphicsPipelineDesc(); + const HN_RENDER_MODE RenderMode = State.RPState.GetRenderMode(); + if (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) + { + GraphicsDesc.PrimitiveTopology = PRIMITIVE_TOPOLOGY_LINE_LIST; + State.WireframePSOCache = USDRenderer->GetWireframePsoCacheAccessor(GraphicsDesc); + VERIFY_EXPR(State.WireframePSOCache); + } + else + { + UNEXPECTED("Unexpected render mode"); + return; + } for (const pxr::HdDrawItem* pDrawItem : m_DrawItems) { @@ -104,7 +132,7 @@ void HnRenderPass::_Execute(const pxr::HdRenderPassStateSharedPtr& State, if (pMaterial == nullptr) continue; - RenderMesh(pCtx, *static_cast(State.get()), *pMesh, *pMaterial); + RenderMesh(State, *pMesh, *pMaterial); } } } @@ -117,8 +145,8 @@ void HnRenderPass::_MarkCollectionDirty() void HnRenderPass::UpdateDrawItems(const pxr::TfTokenVector& RenderTags) { - pxr::HdRenderIndex* pRenderIndex = GetRenderIndex(); - HnRenderDelegate* pRenderDelegate = static_cast(pRenderIndex->GetRenderDelegate()); + pxr::HdRenderIndex* pRenderIndex = GetRenderIndex(); + //HnRenderDelegate* pRenderDelegate = static_cast(pRenderIndex->GetRenderDelegate()); const pxr::HdRprimCollection& Collection = GetRprimCollection(); const pxr::HdChangeTracker& Tracker = pRenderIndex->GetChangeTracker(); @@ -168,10 +196,9 @@ void HnRenderPass::UpdateDrawItems(const pxr::TfTokenVector& RenderTags) } -void HnRenderPass::RenderMesh(IDeviceContext* pCtx, - const HnRenderPassState& State, - const HnMesh& Mesh, - const HnMaterial& Material) +void HnRenderPass::RenderMesh(RenderState& State, + const HnMesh& Mesh, + const HnMaterial& Material) { auto* const pSRB = Material.GetSRB(); auto* const pPosVB = Mesh.GetVertexBuffer(pxr::HdTokens->points); @@ -195,7 +222,7 @@ void HnRenderPass::RenderMesh(IDeviceContext* pCtx, } } - const auto RenderMode = State.GetRenderMode(); + const auto RenderMode = State.RPState.GetRenderMode(); auto* pIB = (RenderMode == HN_RENDER_MODE_MESH_EDGES) ? Mesh.GetEdgeIndexBuffer() : @@ -226,28 +253,33 @@ void HnRenderPass::RenderMesh(IDeviceContext* pCtx, PBR_Renderer::PSO_FLAG_USE_IBL | PBR_Renderer::PSO_FLAG_ENABLE_DEBUG_VIEW; - pPSO = m_PbrPSOCache.Get({PSOFlags, static_cast(ShaderAttribs.AlphaMode), /*DoubleSided = */ false}, true); + pPSO = State.PbrPSOCache.Get({PSOFlags, static_cast(ShaderAttribs.AlphaMode), /*DoubleSided = */ false}, true); } else if (RenderMode == HN_RENDER_MODE_MESH_EDGES) { - pPSO = m_WireframePSOCache.Get({PSOFlags, /*DoubleSided = */ false}, true); + pPSO = State.WireframePSOCache.Get({PSOFlags, /*DoubleSided = */ false}, true); } else { UNEXPECTED("Unexpected render mode"); return; } - pCtx->SetPipelineState(pPSO); + + if (State.pPSO != pPSO) + { + State.pCtx->SetPipelineState(pPSO); + State.pPSO = pPSO; + } // Bind vertex and index buffers IBuffer* pBuffs[] = {pPosVB, pNormalsVB, pTexCoordVBs[0], pTexCoordVBs[1]}; - pCtx->SetVertexBuffers(0, _countof(pBuffs), pBuffs, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); - pCtx->SetIndexBuffer(pIB, 0, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); + State.pCtx->SetVertexBuffers(0, _countof(pBuffs), pBuffs, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); + State.pCtx->SetIndexBuffer(pIB, 0, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); { - MapHelper pDstShaderAttribs{pCtx, m_USDRenderer->GetPBRAttribsCB(), MAP_WRITE, MAP_FLAG_DISCARD}; + MapHelper pDstShaderAttribs{State.pCtx, State.pPBRAttribsCB, MAP_WRITE, MAP_FLAG_DISCARD}; - pDstShaderAttribs->Transforms.NodeMatrix = Mesh.GetTransform() * State.GetTransform(); + pDstShaderAttribs->Transforms.NodeMatrix = Mesh.GetTransform() * State.RPState.GetTransform(); pDstShaderAttribs->Transforms.JointCount = 0; static_assert(sizeof(pDstShaderAttribs->Material) == sizeof(ShaderAttribs), "The sizeof(PBRMaterialShaderInfo) is inconsistent with sizeof(ShaderAttribs)"); @@ -255,10 +287,10 @@ void HnRenderPass::RenderMesh(IDeviceContext* pCtx, auto& RendererParams = pDstShaderAttribs->Renderer; - RendererParams.DebugViewType = State.GetDebugView(); - RendererParams.OcclusionStrength = State.GetOcclusionStrength(); - RendererParams.EmissionScale = State.GetEmissionScale(); - RendererParams.IBLScale = State.GetIBLScale(); + RendererParams.DebugViewType = State.RPState.GetDebugView(); + RendererParams.OcclusionStrength = State.RPState.GetOcclusionStrength(); + RendererParams.EmissionScale = State.RPState.GetEmissionScale(); + RendererParams.IBLScale = State.RPState.GetIBLScale(); RendererParams.PrefilteredCubeMipLevels = 5; //m_Settings.UseIBL ? static_cast(m_pPrefilteredEnvMapSRV->GetTexture()->GetDesc().MipLevels) : 0.f; RendererParams.WireframeColor = float4{1, 1, 1, 1}; //Attribs.WireframeColor; @@ -274,12 +306,12 @@ void HnRenderPass::RenderMesh(IDeviceContext* pCtx, RendererParams.CustomData = CustomData; } - pCtx->CommitShaderResources(pSRB, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); + State.pCtx->CommitShaderResources(pSRB, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); DrawIndexedAttribs DrawAttrs = (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}; - pCtx->DrawIndexed(DrawAttrs); + State.pCtx->DrawIndexed(DrawAttrs); } } // namespace USD diff --git a/Hydrogent/src/HnRenderPassState.cpp b/Hydrogent/src/HnRenderPassState.cpp index 1470caec..d349f47d 100644 --- a/Hydrogent/src/HnRenderPassState.cpp +++ b/Hydrogent/src/HnRenderPassState.cpp @@ -46,7 +46,6 @@ HnRenderPassState::HnRenderPassState() void HnRenderPassState::Begin(IDeviceContext* pContext) { - VERIFY(_stencilMask == 0, "Stencil mask is not supported"); VERIFY(!_depthMaskEnabled, "Depth mask is not supported"); VERIFY(_camera == nullptr, "Camera is not used"); VERIFY(!_framing.IsValid(), "Framing is not used"); @@ -80,7 +79,8 @@ RasterizerStateDesc HnRenderPassState::GetRasterizerState() const RasterizerStateDesc RSState; - RSState.DepthClipEnable = !_depthClampEnabled; + RSState.DepthClipEnable = !_depthClampEnabled; + RSState.FrontCounterClockwise = m_FrontFaceCCW; if (_depthBiasEnabled) { RSState.DepthBias = _depthBiasConstantFactor; @@ -96,6 +96,8 @@ DepthStencilStateDesc HnRenderPassState::GetDepthStencilState() const DSSState.DepthEnable = _depthTestEnabled; DSSState.DepthFunc = HdCompareFunctionToComparisonFunction(_depthFunc); DSSState.StencilEnable = _stencilEnabled; + DSSState.StencilReadMask = static_cast(_stencilMask); + DSSState.StencilWriteMask = static_cast(_stencilMask); DSSState.FrontFace.StencilFunc = HdCompareFunctionToComparisonFunction(_stencilFunc); DSSState.FrontFace.StencilFailOp = HdStencilOpToStencilOp(_stencilFailOp); DSSState.FrontFace.StencilPassOp = HdStencilOpToStencilOp(_stencilZPassOp); diff --git a/Hydrogent/src/HnRendererImpl.cpp b/Hydrogent/src/HnRendererImpl.cpp index 70e652ea..8285b7e6 100644 --- a/Hydrogent/src/HnRendererImpl.cpp +++ b/Hydrogent/src/HnRendererImpl.cpp @@ -83,9 +83,9 @@ HnRendererImpl::HnRendererImpl(IReferenceCounters* pRefCounters, EnvMapRndrCI.pDevice = pDevice; EnvMapRndrCI.pCameraAttribsCB = CI.pCameraAttribsCB; EnvMapRndrCI.NumRenderTargets = 2; - EnvMapRndrCI.RTVFormats[0] = HnRenderDelegate::ColorBufferFormat; - EnvMapRndrCI.RTVFormats[1] = HnRenderDelegate::MeshIdFormat; - EnvMapRndrCI.DSVFormat = HnRenderDelegate::DepthFormat; + EnvMapRndrCI.RTVFormats[0] = ColorBufferFormat; + EnvMapRndrCI.RTVFormats[1] = MeshIdFormat; + EnvMapRndrCI.DSVFormat = DepthFormat; return EnvMapRndrCI; }(CI, pDevice))}, @@ -139,7 +139,11 @@ void HnRendererImpl::Update() if (m_RenderParamsChanged) { HnSetupRenderingTaskParams Params; + Params.ColorFormat = ColorBufferFormat; + Params.MeshIdFormat = MeshIdFormat; + Params.DepthFormat = DepthFormat; Params.RenderMode = m_RenderParams.RenderMode; + Params.FrontFaceCCW = m_RenderParams.FrontFaceCCW; Params.DebugView = m_RenderParams.DebugView; Params.OcclusionStrength = m_RenderParams.OcclusionStrength; Params.EmissionScale = m_RenderParams.EmissionScale; @@ -176,18 +180,18 @@ void HnRendererImpl::PrepareRenderTargets(ITextureView* pDstRtv) TexDesc.Type = RESOURCE_DIM_TEX_2D; TexDesc.Width = DstTexDesc.Width; TexDesc.Height = DstTexDesc.Height; - TexDesc.Format = HnRenderDelegate::ColorBufferFormat; + TexDesc.Format = ColorBufferFormat; TexDesc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE; TexDesc.MipLevels = 1; m_ColorBuffer = m_Device.CreateTexture(TexDesc); TexDesc.Name = "Mesh ID buffer"; - TexDesc.Format = HnRenderDelegate::MeshIdFormat; + TexDesc.Format = MeshIdFormat; TexDesc.BindFlags = BIND_RENDER_TARGET | BIND_SHADER_RESOURCE; m_MeshIdTexture = m_Device.CreateTexture(TexDesc); TexDesc.Name = "Depth buffer"; - TexDesc.Format = HnRenderDelegate::DepthFormat; + TexDesc.Format = DepthFormat; TexDesc.BindFlags = BIND_DEPTH_STENCIL; m_DepthBufferDSV = m_Device.CreateTexture(TexDesc)->GetDefaultView(TEXTURE_VIEW_DEPTH_STENCIL); } diff --git a/Hydrogent/src/Tasks/HnSetupRenderingTask.cpp b/Hydrogent/src/Tasks/HnSetupRenderingTask.cpp index 878dd72a..9eb2e934 100644 --- a/Hydrogent/src/Tasks/HnSetupRenderingTask.cpp +++ b/Hydrogent/src/Tasks/HnSetupRenderingTask.cpp @@ -54,6 +54,25 @@ void HnSetupRenderingTask::UpdateRenderPassState(const HnSetupRenderingTaskParam 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); + m_RenderPassState->SetRenderTargetFormat(1, Params.MeshIdFormat); + m_RenderPassState->SetDepthStencilFormat(Params.DepthFormat); + + m_RenderPassState->SetDepthBias(Params.DepthBias, Params.SlopeScaledDepthBias); + m_RenderPassState->SetDepthFunc(Params.DepthFunc); + m_RenderPassState->SetDepthBiasEnabled(Params.DepthBiasEnabled); + m_RenderPassState->SetEnableDepthTest(Params.DepthTestEnabled); + m_RenderPassState->SetEnableDepthClamp(Params.DepthClampEnabled); + + m_RenderPassState->SetCullStyle(Params.CullStyle); + + m_RenderPassState->SetStencil(Params.StencilFunc, Params.StencilRef, Params.StencilMask, + Params.StencilFailOp, Params.StencilZFailOp, Params.StencilZPassOp); + + m_RenderPassState->SetFrontFaceCCW(Params.FrontFaceCCW); } void HnSetupRenderingTask::Sync(pxr::HdSceneDelegate* Delegate, diff --git a/Hydrogent/src/Tasks/HnTaskController.cpp b/Hydrogent/src/Tasks/HnTaskController.cpp index 32d87bea..b86a3ee2 100644 --- a/Hydrogent/src/Tasks/HnTaskController.cpp +++ b/Hydrogent/src/Tasks/HnTaskController.cpp @@ -208,6 +208,14 @@ void HnTaskController::CreateRenderRprimsTask(const pxr::TfToken& MaterialTag, T m_ParamsDelegate.SetParameter(RenderRprimsTaskId, pxr::HdTokens->renderTags, RenderTags); } +void HnTaskController::SetRenderRprimParams(const HnRenderRprimsTaskParams& Params) +{ + for (const auto& TaskId : m_RenderTaskIds) + { + SetTaskParams(TaskId, Params); + } +} + void HnTaskController::CreatePostProcessTask() { HnPostProcessTaskParams TaskParams;