Skip to content

Commit ee1d357

Browse files
USD Viewer: set environment map through dome light
1 parent 8fc5a11 commit ee1d357

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

Samples/USDViewer/src/USDViewer.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#include "pxr/usd/usdGeom/imageable.h"
6363
#include "pxr/usd/usdLux/distantLight.h"
6464
#include "pxr/usd/usdLux/sphereLight.h"
65+
#include "pxr/usd/usdLux/domeLight.h"
6566
#include "pxr/usd/usdLux/shadowAPI.h"
6667
#include "pxr/base/gf/rotation.h"
6768

@@ -191,8 +192,6 @@ void USDViewer::Initialize(const SampleInitInfo& InitInfo)
191192

192193
ImGuizmo::SetGizmoSizeClipSpace(0.15f);
193194

194-
LoadEnvironmentMap("textures/papermill.ktx");
195-
196195
if (m_UsdFileName.empty())
197196
m_UsdFileName = "usd/AppleVisionPro.usdz";
198197
LoadStage();
@@ -348,6 +347,13 @@ void USDViewer::LoadStage()
348347
AddDirectionalLight("_HnDirectionalLight2_", 5000.f, pxr::GfRotation{pxr::GfVec3d{1, -0.5, 0.0}, -50}, 1024);
349348
AddDirectionalLight("_HnDirectionalLight3_", 5000.f, pxr::GfRotation{pxr::GfVec3d{1, 0.0, 0.5}, -40}, 1024);
350349

350+
// Environment map
351+
{
352+
m_Stage.DomeLightId = SceneDelegateId.AppendChild(pxr::TfToken{"_HnDomeLight_"});
353+
pxr::UsdLuxDomeLight DomeLight = pxr::UsdLuxDomeLight::Define(m_Stage.Stage, m_Stage.DomeLightId);
354+
DomeLight.CreateTextureFileAttr().Set(pxr::SdfAssetPath{"textures/papermill.ktx"});
355+
}
356+
351357
#if 0
352358
// Point light
353359
{
@@ -376,8 +382,6 @@ void USDViewer::LoadStage()
376382
m_Stage.FinalColorTarget = static_cast<USD::HnRenderBuffer*>(m_Stage.RenderIndex->GetBprim(pxr::HdPrimTypeTokens->renderBuffer, FinalColorTargetId));
377383
VERIFY_EXPR(m_Stage.FinalColorTarget != nullptr);
378384

379-
m_Stage.RenderDelegate->GetUSDRenderer()->PrecomputeCubemaps(m_pImmediateContext, m_EnvironmentMapSRV);
380-
381385
m_FrameParams = {};
382386
m_FrameParams.State.FrontFaceCCW = true;
383387
m_FrameParams.FinalColorTargetId = FinalColorTargetId;
@@ -456,22 +460,18 @@ void USDViewer::LoadStage()
456460

457461
void USDViewer::LoadEnvironmentMap(const char* Path)
458462
{
459-
RefCntAutoPtr<ITexture> pEnvironmentMap;
460-
CreateTextureFromFile(Path, TextureLoadInfo{"Environment map"}, m_pDevice, &pEnvironmentMap);
461-
VERIFY_EXPR(pEnvironmentMap);
463+
if (m_Stage.DomeLightId.IsEmpty())
464+
return;
462465

463-
if (m_Stage && m_Stage.RenderDelegate)
464-
{
465-
auto pIBLBacker = m_Stage.RenderDelegate->GetUSDRenderer();
466-
pIBLBacker->PrecomputeCubemaps(m_pImmediateContext, pEnvironmentMap->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE));
467-
}
466+
pxr::UsdPrim Prim = m_Stage.Stage->GetPrimAtPath(m_Stage.DomeLightId);
467+
if (!Prim)
468+
return;
468469

469-
StateTransitionDesc Barriers[] = {
470-
{pEnvironmentMap, RESOURCE_STATE_UNKNOWN, RESOURCE_STATE_SHADER_RESOURCE, STATE_TRANSITION_FLAG_UPDATE_STATE},
471-
};
472-
m_pImmediateContext->TransitionResourceStates(_countof(Barriers), Barriers);
470+
pxr::UsdLuxDomeLight DomeLight{Prim};
471+
if (!DomeLight)
472+
return;
473473

474-
m_EnvironmentMapSRV = pEnvironmentMap->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE);
474+
DomeLight.GetTextureFileAttr().Set(pxr::SdfAssetPath{Path});
475475
}
476476

477477
// Render a frame

Samples/USDViewer/src/USDViewer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class USDViewer final : public SampleBase
102102

103103
USD::HnRenderBuffer* FinalColorTarget = nullptr;
104104

105+
pxr::SdfPath DomeLightId;
105106
pxr::SdfPath SelectedPrimId;
106107

107108
float4x4 RootTransform = float4x4::Identity();

0 commit comments

Comments
 (0)