|
62 | 62 | #include "pxr/usd/usdGeom/imageable.h"
|
63 | 63 | #include "pxr/usd/usdLux/distantLight.h"
|
64 | 64 | #include "pxr/usd/usdLux/sphereLight.h"
|
| 65 | +#include "pxr/usd/usdLux/domeLight.h" |
65 | 66 | #include "pxr/usd/usdLux/shadowAPI.h"
|
66 | 67 | #include "pxr/base/gf/rotation.h"
|
67 | 68 |
|
@@ -191,8 +192,6 @@ void USDViewer::Initialize(const SampleInitInfo& InitInfo)
|
191 | 192 |
|
192 | 193 | ImGuizmo::SetGizmoSizeClipSpace(0.15f);
|
193 | 194 |
|
194 |
| - LoadEnvironmentMap("textures/papermill.ktx"); |
195 |
| - |
196 | 195 | if (m_UsdFileName.empty())
|
197 | 196 | m_UsdFileName = "usd/AppleVisionPro.usdz";
|
198 | 197 | LoadStage();
|
@@ -348,6 +347,13 @@ void USDViewer::LoadStage()
|
348 | 347 | AddDirectionalLight("_HnDirectionalLight2_", 5000.f, pxr::GfRotation{pxr::GfVec3d{1, -0.5, 0.0}, -50}, 1024);
|
349 | 348 | AddDirectionalLight("_HnDirectionalLight3_", 5000.f, pxr::GfRotation{pxr::GfVec3d{1, 0.0, 0.5}, -40}, 1024);
|
350 | 349 |
|
| 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 | + |
351 | 357 | #if 0
|
352 | 358 | // Point light
|
353 | 359 | {
|
@@ -376,8 +382,6 @@ void USDViewer::LoadStage()
|
376 | 382 | m_Stage.FinalColorTarget = static_cast<USD::HnRenderBuffer*>(m_Stage.RenderIndex->GetBprim(pxr::HdPrimTypeTokens->renderBuffer, FinalColorTargetId));
|
377 | 383 | VERIFY_EXPR(m_Stage.FinalColorTarget != nullptr);
|
378 | 384 |
|
379 |
| - m_Stage.RenderDelegate->GetUSDRenderer()->PrecomputeCubemaps(m_pImmediateContext, m_EnvironmentMapSRV); |
380 |
| - |
381 | 385 | m_FrameParams = {};
|
382 | 386 | m_FrameParams.State.FrontFaceCCW = true;
|
383 | 387 | m_FrameParams.FinalColorTargetId = FinalColorTargetId;
|
@@ -456,22 +460,18 @@ void USDViewer::LoadStage()
|
456 | 460 |
|
457 | 461 | void USDViewer::LoadEnvironmentMap(const char* Path)
|
458 | 462 | {
|
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; |
462 | 465 |
|
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; |
468 | 469 |
|
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; |
473 | 473 |
|
474 |
| - m_EnvironmentMapSRV = pEnvironmentMap->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE); |
| 474 | + DomeLight.GetTextureFileAttr().Set(pxr::SdfAssetPath{Path}); |
475 | 475 | }
|
476 | 476 |
|
477 | 477 | // Render a frame
|
|
0 commit comments