From e9a4ef3865feb466dacf7eea4457ad62e3c53d01 Mon Sep 17 00:00:00 2001 From: assiduous Date: Wed, 16 Oct 2024 23:35:57 -0700 Subject: [PATCH] Hydrogent: use fixed depth bias for shadow pass --- Hydrogent/interface/Tasks/HnTaskManager.hpp | 4 +++- Hydrogent/src/Tasks/HnTaskManager.cpp | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Hydrogent/interface/Tasks/HnTaskManager.hpp b/Hydrogent/interface/Tasks/HnTaskManager.hpp index 41bd7576..8235f53d 100644 --- a/Hydrogent/interface/Tasks/HnTaskManager.hpp +++ b/Hydrogent/interface/Tasks/HnTaskManager.hpp @@ -46,6 +46,8 @@ struct HnRenderPassParams; struct HnReadRprimIdTaskParams; struct HnRenderBoundBoxTaskParams; +class HnShadowMapManager; + /// Task manager implementation in Hydrogent. class HnTaskManager { @@ -236,7 +238,7 @@ class HnTaskManager void CreateBeginFrameTask(); void CreateBeginMainPassTask(); - void CreateRenderShadowsTask(); + void CreateRenderShadowsTask(const HnShadowMapManager& ShadowMapMgr); void CreateRenderRprimsTask(const pxr::TfToken& MaterialTag, TaskUID UID, const HnRenderPassParams& RenderPassParams); void CreateRenderEnvMapTask(const pxr::TfToken& RenderPassName); void CreateRenderBoundBoxTask(const pxr::TfToken& RenderPassName); diff --git a/Hydrogent/src/Tasks/HnTaskManager.cpp b/Hydrogent/src/Tasks/HnTaskManager.cpp index 0a96ba3d..05404532 100644 --- a/Hydrogent/src/Tasks/HnTaskManager.cpp +++ b/Hydrogent/src/Tasks/HnTaskManager.cpp @@ -43,6 +43,7 @@ #include "HashUtils.hpp" #include "HnRenderDelegate.hpp" #include "HnRenderPass.hpp" +#include "HnShadowMapManager.hpp" namespace Diligent { @@ -145,9 +146,9 @@ HnTaskManager::HnTaskManager(pxr::HdRenderIndex& RenderIndex, { // Task creation order defines the default task order CreateBeginFrameTask(); - if (static_cast(RenderIndex.GetRenderDelegate())->GetShadowMapManager()) + if (const HnShadowMapManager* pShadowMapMgr = static_cast(RenderIndex.GetRenderDelegate())->GetShadowMapManager()) { - CreateRenderShadowsTask(); + CreateRenderShadowsTask(*pShadowMapMgr); } CreateBeginMainPassTask(); @@ -261,13 +262,15 @@ void HnTaskManager::CreateBeginFrameTask() CreateTask(HnTaskManagerTokens->beginFrameTask, TaskUID_BeginFrame, TaskParams); } -void HnTaskManager::CreateRenderShadowsTask() +void HnTaskManager::CreateRenderShadowsTask(const HnShadowMapManager& ShadowMapMgr) { const USD_Renderer& Renderer = *static_cast(GetRenderIndex().GetRenderDelegate())->GetUSDRenderer(); HnRenderShadowsTaskParams TaskParams; TaskParams.State.DepthBiasEnabled = true; TaskParams.State.SlopeScaledDepthBias = Renderer.GetSettings().PCFKernelSize * 0.5f + 0.5f; + const TEXTURE_FORMAT ShadowMapFmt = ShadowMapMgr.GetAtlasDesc().Format; + TaskParams.State.DepthBias = (ShadowMapFmt == TEX_FORMAT_D32_FLOAT || ShadowMapFmt == TEX_FORMAT_D32_FLOAT_S8X24_UINT) ? 10000 : 10; CreateTask(HnTaskManagerTokens->renderShadowsTask, TaskUID_RenderShadows, TaskParams); // Only render shadows from default material for now