11/*
2- * Copyright 2023-2024 Diligent Graphics LLC
2+ * Copyright 2023-2025 Diligent Graphics LLC
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -433,15 +433,22 @@ void HnLight::Sync(pxr::HdSceneDelegate* SceneDelegate,
433433
434434 const pxr::SdfPath& Id = GetId ();
435435
436- bool LightDirty = false ;
437-
436+ bool LightDirty = false ;
437+ bool IBLCubemapDirty = false ;
438438 {
439439 bool IsVisible = SceneDelegate->GetVisible (Id);
440440 if (IsVisible != m_IsVisible)
441441 {
442442 m_IsVisible = IsVisible;
443443 LightDirty = true ;
444444 m_IsShadowMapDirty = true ;
445+ if (m_TypeId == pxr::HdPrimTypeTokens->domeLight )
446+ {
447+ // NB: we need to update IBL cube maps even if the light became invisible since
448+ // if multiple dome lights were visible, the IBL was precomputed for
449+ // the first one, which might be any of them.
450+ IBLCubemapDirty = true ;
451+ }
445452 }
446453 }
447454
@@ -527,9 +534,10 @@ void HnLight::Sync(pxr::HdSceneDelegate* SceneDelegate,
527534 std::string TexturePath = GetTextureFile (*SceneDelegate, Id).GetAssetPath ();
528535 if (TexturePath != m_TexturePath)
529536 {
530- m_TexturePath = std::move (TexturePath);
531- LightDirty = true ;
532- m_IsTextureDirty = true ;
537+ m_TexturePath = std::move (TexturePath);
538+ LightDirty = true ;
539+ // If the dome light is invisible, we will precompute its IBL cubemaps when it becomes visible
540+ IBLCubemapDirty = m_IsVisible;
533541 }
534542 }
535543
@@ -627,7 +635,7 @@ void HnLight::Sync(pxr::HdSceneDelegate* SceneDelegate,
627635 if (LightDirty)
628636 static_cast <HnRenderParam*>(RenderParam)->MakeAttribDirty (HnRenderParam::GlobalAttrib::Light);
629637
630- if (m_IsTextureDirty )
638+ if (IBLCubemapDirty )
631639 static_cast <HnRenderParam*>(RenderParam)->MakeAttribDirty (HnRenderParam::GlobalAttrib::LightResources);
632640 }
633641
@@ -637,7 +645,9 @@ void HnLight::Sync(pxr::HdSceneDelegate* SceneDelegate,
637645void HnLight::PrecomputeIBLCubemaps (HnRenderDelegate& RenderDelegate)
638646{
639647 VERIFY_EXPR (m_TypeId == pxr::HdPrimTypeTokens->domeLight );
640- if (!m_IsTextureDirty)
648+ const HnRenderParam* pRenderParam = static_cast <const HnRenderParam*>(RenderDelegate.GetRenderParam ());
649+ const uint32_t LightResourcesVersion = pRenderParam->GetAttribVersion (HnRenderParam::GlobalAttrib::LightResources);
650+ if (LightResourcesVersion == m_LightResourcesVersion)
641651 return ;
642652
643653 IRenderDevice* pDevice = RenderDelegate.GetDevice ();
@@ -681,7 +691,7 @@ void HnLight::PrecomputeIBLCubemaps(HnRenderDelegate& RenderDelegate)
681691
682692 RenderDelegate.GetUSDRenderer ()->PrecomputeCubemaps (pCtx, pEnvMap->GetDefaultView (TEXTURE_VIEW_SHADER_RESOURCE));
683693
684- m_IsTextureDirty = false ;
694+ m_LightResourcesVersion = LightResourcesVersion ;
685695}
686696
687697} // namespace USD
0 commit comments