| 369 | } |
| 370 | |
| 371 | void HnLight::ComputeDirectLightProjMatrix(pxr::HdSceneDelegate& SceneDelegate) |
| 372 | { |
| 373 | pxr::HdRenderIndex& RenderIndex = SceneDelegate.GetRenderIndex(); |
| 374 | |
| 375 | BoundBox LightSpaceBounds{BoundBox::Invalid()}; |
| 376 | if (!m_SceneBounds.IsValid()) |
| 377 | { |
| 378 | // First time compute accurate scene bounds in light space by projecting |
| 379 | // each primitive's bounding box into light space. |
| 380 | // Also, compute the scnene bounds in world space. |
| 381 | |
| 382 | const pxr::SdfPathVector& RPrimIds = RenderIndex.GetRprimIds(); |
| 383 | for (const pxr::SdfPath& RPrimId : RPrimIds) |
| 384 | { |
| 385 | if (RPrimId.IsEmpty()) |
| 386 | continue; |
| 387 | |
| 388 | const pxr::GfRange3d PrimExtent = SceneDelegate.GetExtent(RPrimId); |
| 389 | if (PrimExtent.IsEmpty()) |
| 390 | continue; |
| 391 | |
| 392 | const BoundBox PrimBB = ToBoundBox(PrimExtent); |
| 393 | const float4x4 PrimTransform = ToMatrix4x4<float>(SceneDelegate.GetTransform(RPrimId)); |
| 394 | for (Uint32 i = 0; i < 8; ++i) |
| 395 | { |
| 396 | float4 Corner = {PrimBB.GetCorner(i), 1.0}; |
| 397 | |
| 398 | Corner = Corner * PrimTransform; |
| 399 | m_SceneBounds = m_SceneBounds.Enclose(Corner); |
| 400 | |
| 401 | Corner = Corner * m_ViewMatrix; |
| 402 | LightSpaceBounds = LightSpaceBounds.Enclose(Corner); |
| 403 | } |
| 404 | } |
| 405 | } |
| 406 | else |
| 407 | { |
| 408 | // Use precomputed scene bounds in world space. This is less accurate, but |
| 409 | // much faster. |
| 410 | for (Uint32 i = 0; i < 8; ++i) |
| 411 | { |
| 412 | float4 Corner = {m_SceneBounds.GetCorner(i), 1.0}; |
| 413 | Corner = Corner * m_ViewMatrix; |
| 414 | LightSpaceBounds = LightSpaceBounds.Enclose(Corner); |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | IRenderDevice* pDevice = static_cast<const HnRenderDelegate*>(RenderIndex.GetRenderDelegate())->GetDevice(); |
| 419 | const RenderDeviceInfo& DeviceInfo = pDevice->GetDeviceInfo(); |
| 420 | |
| 421 | m_ProjMatrix = float4x4::OrthoOffCenter(LightSpaceBounds.Min.x, LightSpaceBounds.Max.x, |
| 422 | LightSpaceBounds.Min.y, LightSpaceBounds.Max.y, |
| 423 | LightSpaceBounds.Min.z, LightSpaceBounds.Max.z, |
| 424 | DeviceInfo.NDC.MinZ == -1); |
| 425 | } |
| 426 | |
| 427 | void HnLight::Sync(pxr::HdSceneDelegate* SceneDelegate, |
| 428 | pxr::HdRenderParam* RenderParam, |
nothing calls this directly
no test coverage detected