| 398 | } |
| 399 | |
| 400 | void HnBeginFrameTask::UpdateFrameConstants(IDeviceContext* pCtx, |
| 401 | IBuffer* pFrameAttrbisCB, |
| 402 | bool UseTAA, |
| 403 | const float2& Jitter, |
| 404 | bool& CameraTransformDirty) |
| 405 | { |
| 406 | HnRenderDelegate* RenderDelegate = static_cast<HnRenderDelegate*>(m_RenderIndex->GetRenderDelegate()); |
| 407 | const HnRenderParam* RenderParam = static_cast<const HnRenderParam*>(RenderDelegate->GetRenderParam()); |
| 408 | IRenderDevice* pDevice = RenderDelegate->GetDevice(); |
| 409 | const USD_Renderer& Renderer = *RenderDelegate->GetUSDRenderer(); |
| 410 | const int MaxLightCount = Renderer.GetSettings().MaxLightCount; |
| 411 | |
| 412 | const Uint32 NumShadowCastingLights = Renderer.GetSettings().EnableShadows ? Renderer.GetSettings().MaxShadowCastingLightCount : 0; |
| 413 | const Uint32 FrameAttribsDataSize = pFrameAttrbisCB->GetDesc().Size; |
| 414 | VERIFY(FrameAttribsDataSize == RenderDelegate->GetShadowPassFrameAttribsOffset(NumShadowCastingLights), "Frame attributes buffer size mismatch"); |
| 415 | m_FrameAttribsData.resize(FrameAttribsDataSize); |
| 416 | // |
| 417 | // || Main Pass || Shadow Pass 1 || ... || Shadow Pass N || |
| 418 | // || Camera|PrevCamera|Renderer|Lights|ShadowMaps || Camera|PrevCamera|Renderer || ... || Camera|PrevCamera|Renderer || |
| 419 | // |
| 420 | |
| 421 | // Write shadow casting light attributes first to initialize shadow cating light indices |
| 422 | if (const HnShadowMapManager* ShadowMapMgr = RenderDelegate->GetShadowMapManager()) |
| 423 | { |
| 424 | const TextureDesc& ShadowAtlasDesc = ShadowMapMgr->GetAtlasDesc(); |
| 425 | |
| 426 | const auto& Lights = RenderDelegate->GetLights(); |
| 427 | for (const HnLight* Light : Lights) |
| 428 | { |
| 429 | const Int32 ShadowCastingLightIdx = Light->GetFrameAttribsIndex(); |
| 430 | VERIFY_EXPR((ShadowCastingLightIdx < 0) == (!Light->ShadowsEnabled() || !Light->IsVisible() || ShadowCastingLightIdx >= static_cast<Int32>(NumShadowCastingLights))); |
| 431 | if (ShadowCastingLightIdx < 0) |
| 432 | continue; |
| 433 | |
| 434 | HLSL::PBRFrameAttribs* ShadowAttribs = reinterpret_cast<HLSL::PBRFrameAttribs*>(&m_FrameAttribsData[RenderDelegate->GetShadowPassFrameAttribsOffset(ShadowCastingLightIdx)]); |
| 435 | HLSL::CameraAttribs& CamAttribs = ShadowAttribs->Camera; |
| 436 | |
| 437 | const float4x4& ProjMatrix = Light->GetViewProjMatrix(); |
| 438 | const float4x4& ViewMatrix = Light->GetViewMatrix(); |
| 439 | const float4x4 ViewProj = Light->GetViewProjMatrix(); |
| 440 | |
| 441 | VERIFY_EXPR(ShadowAtlasDesc.Width > 0 && ShadowAtlasDesc.Height > 0); |
| 442 | CamAttribs.f4ViewportSize = float4{ |
| 443 | static_cast<float>(ShadowAtlasDesc.Width), |
| 444 | static_cast<float>(ShadowAtlasDesc.Height), |
| 445 | 1.f / static_cast<float>(ShadowAtlasDesc.Width), |
| 446 | 1.f / static_cast<float>(ShadowAtlasDesc.Height), |
| 447 | }; |
| 448 | CamAttribs.fHandness = 1.f; |
| 449 | |
| 450 | CamAttribs.mView = ViewMatrix; |
| 451 | CamAttribs.mProj = ProjMatrix; |
| 452 | CamAttribs.mViewProj = ViewProj; |
| 453 | CamAttribs.mViewInv = ViewMatrix.Inverse(); |
| 454 | CamAttribs.mProjInv = ProjMatrix.Inverse(); |
| 455 | CamAttribs.mViewProjInv = ViewProj.Inverse(); |
| 456 | CamAttribs.f4Position = float4{0, 0, 0, 1}; |
| 457 | CamAttribs.f2Jitter = float2{0, 0}; |
nothing calls this directly
no test coverage detected