MultiRenderPipelineExampleComponent.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project
  3. *
  4. * SPDX-License-Identifier: Apache-2.0 OR MIT
  5. *
  6. */
  7. #include <AtomSampleViewerOptions.h>
  8. #include <MultiRenderPipelineExampleComponent.h>
  9. #include <Atom/Component/DebugCamera/CameraComponent.h>
  10. #include <Atom/Component/DebugCamera/NoClipControllerComponent.h>
  11. #include <Atom/RHI/RHISystemInterface.h>
  12. #include <Atom/RPI.Public/ViewProviderBus.h>
  13. #include <Atom/RPI.Public/RenderPipeline.h>
  14. #include <Atom/RPI.Public/Scene.h>
  15. #include <Atom/RPI.Public/RPISystemInterface.h>
  16. #include <Atom/RPI.Reflect/Asset/AssetUtils.h>
  17. #include <Atom/RPI.Reflect/Model/ModelAsset.h>
  18. #include <Atom/Feature/ImGui/ImGuiUtils.h>
  19. #include <AzCore/Math/MatrixUtils.h>
  20. #include <Automation/ScriptableImGui.h>
  21. #include <Automation/ScriptRunnerBus.h>
  22. #include <AzCore/Component/Entity.h>
  23. #include <AzFramework/Components/TransformComponent.h>
  24. #include <AzFramework/Scene/SceneSystemInterface.h>
  25. #include <AzFramework/Entity/GameEntityContextComponent.h>
  26. #include <EntityUtilityFunctions.h>
  27. #include <SampleComponentConfig.h>
  28. #include <SampleComponentManager.h>
  29. #include <Utils/Utils.h>
  30. #include <RHI/BasicRHIComponent.h>
  31. namespace AtomSampleViewer
  32. {
  33. using namespace AZ;
  34. void MultiRenderPipelineExampleComponent::Reflect(AZ::ReflectContext* context)
  35. {
  36. if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  37. {
  38. serializeContext->Class<MultiRenderPipelineExampleComponent, AZ::Component>()
  39. ->Version(0)
  40. ;
  41. }
  42. }
  43. MultiRenderPipelineExampleComponent::MultiRenderPipelineExampleComponent()
  44. : m_imguiSidebar("@user@/MultiRenderPipelineExampleComponent/sidebar.xml")
  45. {
  46. m_sampleName = "MultiRenderPipelineExampleComponent";
  47. }
  48. void MultiRenderPipelineExampleComponent::Activate()
  49. {
  50. m_scene = RPI::RPISystemInterface::Get()->GetDefaultScene();
  51. // Save references of different feature processors
  52. m_diskLightFeatureProcessor = m_scene->GetFeatureProcessor<Render::DiskLightFeatureProcessorInterface>();
  53. m_directionalLightFeatureProcessor = m_scene->GetFeatureProcessor<Render::DirectionalLightFeatureProcessorInterface>();
  54. m_skyboxFeatureProcessor = m_scene->GetFeatureProcessor<AZ::Render::SkyBoxFeatureProcessorInterface>();
  55. m_postProcessFeatureProcessor = m_scene->GetFeatureProcessor<AZ::Render::PostProcessFeatureProcessorInterface>();
  56. m_ibl.PreloadAssets();
  57. // Don't continue the script until assets are ready and scene is setup
  58. ScriptRunnerRequestBus::Broadcast(&ScriptRunnerRequests::PauseScriptWithTimeout, 120.0f);
  59. // preload assets
  60. AZStd::vector<AssetCollectionAsyncLoader::AssetToLoadInfo> assetList = {
  61. {DefaultPbrMaterialPath, azrtti_typeid<RPI::MaterialAsset>()},
  62. {BunnyModelFilePath, azrtti_typeid<RPI::ModelAsset>()},
  63. {CubeModelFilePath, azrtti_typeid<RPI::ModelAsset>()}
  64. };
  65. PreloadAssets(assetList);
  66. }
  67. void MultiRenderPipelineExampleComponent::OnAllAssetsReadyActivate()
  68. {
  69. SetupScene();
  70. if (SupportsMultipleWindows() && m_enableSecondRenderPipeline)
  71. {
  72. AddSecondRenderPipeline();
  73. }
  74. AZ::TickBus::Handler::BusConnect();
  75. m_imguiSidebar.Activate();
  76. ScriptRunnerRequestBus::Broadcast(&ScriptRunnerRequests::ResumeScript);
  77. }
  78. void MultiRenderPipelineExampleComponent::SetupScene()
  79. {
  80. auto meshFeatureProcessor = GetMeshFeatureProcessor();
  81. auto materialAsset = RPI::AssetUtils::LoadAssetByProductPath<RPI::MaterialAsset>(DefaultPbrMaterialPath,
  82. RPI::AssetUtils::TraceLevel::Assert);
  83. auto material = AZ::RPI::Material::FindOrCreate(materialAsset);
  84. auto bunnyAsset = RPI::AssetUtils::LoadAssetByProductPath<RPI::ModelAsset>(BunnyModelFilePath,
  85. RPI::AssetUtils::TraceLevel::Assert);
  86. auto floorAsset = RPI::AssetUtils::LoadAssetByProductPath<RPI::ModelAsset>(CubeModelFilePath,
  87. RPI::AssetUtils::TraceLevel::Assert);
  88. m_floorMeshHandle = meshFeatureProcessor->AcquireMesh(Render::MeshHandleDescriptor{ floorAsset }, material);
  89. for (uint32_t bunnyIndex = 0; bunnyIndex < BunnyCount; bunnyIndex++)
  90. {
  91. m_bunnyMeshHandles[bunnyIndex] = meshFeatureProcessor->AcquireMesh(Render::MeshHandleDescriptor{ bunnyAsset }, material);
  92. }
  93. const Vector3 floorNonUniformScale{ 12.f, 12.f, 0.1f };
  94. const Vector3 translation{ 0.f, 0.f, -0.05f };
  95. Transform floorTransform = Transform::CreateTranslation(translation);
  96. meshFeatureProcessor->SetTransform(m_floorMeshHandle, floorTransform, floorNonUniformScale);
  97. meshFeatureProcessor->SetTransform(m_bunnyMeshHandles[0], Transform::CreateTranslation(Vector3(0.f, 0.f, 0.21f)));
  98. meshFeatureProcessor->SetTransform(m_bunnyMeshHandles[1], Transform::CreateTranslation(Vector3(-3.f, 3.f, 0.21f)));
  99. meshFeatureProcessor->SetTransform(m_bunnyMeshHandles[2], Transform::CreateTranslation(Vector3(3.f, 3.f, 0.21f)));
  100. meshFeatureProcessor->SetTransform(m_bunnyMeshHandles[3], Transform::CreateTranslation(Vector3(3.f, -3.f, 0.21f)));
  101. meshFeatureProcessor->SetTransform(m_bunnyMeshHandles[4], Transform::CreateTranslation(Vector3(-3.f, -3.f, 0.21f)));
  102. // Set camera to use no clip controller
  103. AZ::Debug::CameraControllerRequestBus::Event(GetCameraEntityId(), &AZ::Debug::CameraControllerRequestBus::Events::Enable,
  104. azrtti_typeid<AZ::Debug::NoClipControllerComponent>());
  105. AZ::Debug::NoClipControllerRequestBus::Event(GetCameraEntityId(), &AZ::Debug::NoClipControllerRequestBus::Events::SetFov, AZ::DegToRad(90));
  106. // Set camera's initial transform
  107. Transform cameraLookat = Transform::CreateLookAt(Vector3(-2.15f, -5.25f, 1.6f), Vector3(-0.5f, -2.0f, 0));
  108. AZ::TransformBus::Event(GetCameraEntityId(), &AZ::TransformInterface::SetWorldTM, cameraLookat);
  109. if (m_enabledDepthOfField)
  110. {
  111. EnableDepthOfField();
  112. }
  113. if (m_hasDirectionalLight)
  114. {
  115. AddDirectionalLight();
  116. }
  117. if (m_hasDiskLight)
  118. {
  119. AddDiskLight();
  120. }
  121. if (m_enabledSkybox)
  122. {
  123. EnableSkybox();
  124. }
  125. if (m_hasIBL)
  126. {
  127. AddIBL();
  128. }
  129. }
  130. void MultiRenderPipelineExampleComponent::EnableDepthOfField()
  131. {
  132. if (m_postProcessFeatureProcessor)
  133. {
  134. auto* postProcessSettings = m_postProcessFeatureProcessor->GetOrCreateSettingsInterface(GetCameraEntityId());
  135. auto* dofSettings = postProcessSettings->GetOrCreateDepthOfFieldSettingsInterface();
  136. dofSettings->SetQualityLevel(1);
  137. dofSettings->SetApertureF(0.5f);
  138. dofSettings->SetEnableDebugColoring(false);
  139. dofSettings->SetEnableAutoFocus(true);
  140. dofSettings->SetAutoFocusScreenPosition(AZ::Vector2{ 0.5f, 0.5f });
  141. dofSettings->SetAutoFocusSensitivity(1.0f);
  142. dofSettings->SetAutoFocusSpeed(Render::DepthOfField::AutoFocusSpeedMax);
  143. dofSettings->SetAutoFocusDelay(0.2f);
  144. dofSettings->SetCameraEntityId(GetCameraEntityId());
  145. dofSettings->SetEnabled(true);
  146. dofSettings->OnConfigChanged();
  147. // associate a setting to the primary view
  148. AZ::RPI::ViewPtr cameraView;
  149. AZ::RPI::ViewProviderBus::EventResult(cameraView, GetCameraEntityId(), &AZ::RPI::ViewProvider::GetView);
  150. AZ::Render::PostProcessSettingsInterface::ViewBlendWeightMap perViewBlendWeights;
  151. perViewBlendWeights[cameraView.get()] = 1.0;
  152. postProcessSettings->CopyViewToBlendWeightSettings(perViewBlendWeights);
  153. }
  154. }
  155. void MultiRenderPipelineExampleComponent::DisableDepthOfField()
  156. {
  157. if (m_postProcessFeatureProcessor)
  158. {
  159. auto* postProcessSettings = m_postProcessFeatureProcessor->GetOrCreateSettingsInterface(GetCameraEntityId());
  160. auto* dofSettings = postProcessSettings->GetOrCreateDepthOfFieldSettingsInterface();
  161. dofSettings->SetEnabled(false);
  162. dofSettings->OnConfigChanged();
  163. }
  164. }
  165. void MultiRenderPipelineExampleComponent::AddDirectionalLight()
  166. {
  167. if (m_directionalLightHandle.IsValid())
  168. {
  169. return;
  170. }
  171. auto& featureProcessor = m_directionalLightFeatureProcessor;
  172. DirectionalLightHandle handle = featureProcessor->AcquireLight();
  173. const auto lightTransform = Transform::CreateLookAt(
  174. Vector3(100, 100, 100),
  175. Vector3::CreateZero());
  176. featureProcessor->SetDirection(handle, lightTransform.GetBasis(1));
  177. AZ::Render::PhotometricColor<AZ::Render::PhotometricUnit::Lux> lightColor(Color::CreateOne() * 5.0f);
  178. featureProcessor->SetRgbIntensity(handle, lightColor);
  179. featureProcessor->SetCascadeCount(handle, 4);
  180. featureProcessor->SetShadowmapSize(handle, Render::ShadowmapSize::Size2048);
  181. featureProcessor->SetViewFrustumCorrectionEnabled(handle, true);
  182. featureProcessor->SetShadowFilterMethod(handle, aznumeric_cast<Render::ShadowFilterMethod>(m_shadowFilteringMethod));
  183. featureProcessor->SetShadowBoundaryWidth(handle, 0.03f);
  184. featureProcessor->SetPredictionSampleCount(handle, 4);
  185. featureProcessor->SetFilteringSampleCount(handle, 32);
  186. featureProcessor->SetGroundHeight(handle, 0.f);
  187. featureProcessor->SetShadowFarClipDistance(handle, 100.f);
  188. m_directionalLightHandle = handle;
  189. }
  190. void MultiRenderPipelineExampleComponent::RemoveDirectionalLight()
  191. {
  192. if (m_directionalLightHandle.IsValid())
  193. {
  194. m_directionalLightFeatureProcessor->ReleaseLight(m_directionalLightHandle);
  195. }
  196. }
  197. void MultiRenderPipelineExampleComponent::AddDiskLight()
  198. {
  199. Render::DiskLightFeatureProcessorInterface* const featureProcessor = m_diskLightFeatureProcessor;
  200. const DiskLightHandle handle = featureProcessor->AcquireLight();
  201. AZ::Render::PhotometricColor<AZ::Render::PhotometricUnit::Candela> lightColor(Colors::Green * 500.0f);
  202. featureProcessor->SetRgbIntensity(handle, lightColor);
  203. featureProcessor->SetAttenuationRadius(handle, 30.0f);
  204. featureProcessor->SetConeAngles(handle, DegToRad(17.5f * 0.9f), DegToRad(17.5f));
  205. featureProcessor->SetShadowsEnabled(handle, true);
  206. featureProcessor->SetShadowmapMaxResolution(handle, Render::ShadowmapSize::Size1024);
  207. Vector3 position(0, 5, 7);
  208. Vector3 direction = -position;
  209. direction.Normalize();
  210. featureProcessor->SetPosition(handle, position);
  211. featureProcessor->SetDirection(handle, direction);
  212. m_diskLightHandle = handle;
  213. }
  214. void MultiRenderPipelineExampleComponent::RemoveDiskLight()
  215. {
  216. if (m_diskLightHandle.IsValid())
  217. {
  218. m_diskLightFeatureProcessor->ReleaseLight(m_diskLightHandle);
  219. }
  220. }
  221. void MultiRenderPipelineExampleComponent::EnableSkybox()
  222. {
  223. m_skyboxFeatureProcessor->SetSkyboxMode(AZ::Render::SkyBoxMode::PhysicalSky);
  224. m_skyboxFeatureProcessor->Enable(true);
  225. }
  226. void MultiRenderPipelineExampleComponent::DisableSkybox()
  227. {
  228. if (m_skyboxFeatureProcessor)
  229. {
  230. m_skyboxFeatureProcessor->Enable(false);
  231. }
  232. }
  233. void MultiRenderPipelineExampleComponent::AddIBL()
  234. {
  235. m_ibl.Init(m_scene.get());
  236. }
  237. void MultiRenderPipelineExampleComponent::RemoveIBL()
  238. {
  239. m_ibl.Reset();
  240. }
  241. void MultiRenderPipelineExampleComponent::AddSecondRenderPipeline()
  242. {
  243. // Create second render pipeline
  244. // Create a second window for this render pipeline
  245. m_secondWindow = AZStd::make_unique<AzFramework::NativeWindow>("Multi render pipeline: Second Window",
  246. AzFramework::WindowGeometry(0, 0, 800, 600));
  247. m_secondWindow->Activate();
  248. RHI::Ptr<RHI::Device> device = RHI::RHISystemInterface::Get()->GetDevice();
  249. m_secondWindowContext = AZStd::make_shared<RPI::WindowContext>();
  250. m_secondWindowContext->Initialize(*device, m_secondWindow->GetWindowHandle());
  251. AzFramework::WindowNotificationBus::Handler::BusConnect(m_secondWindow->GetWindowHandle());
  252. // Create a custom pipeline descriptor
  253. AZ::RPI::RenderPipelineDescriptor pipelineDesc;
  254. pipelineDesc.m_mainViewTagName = "MainCamera";
  255. pipelineDesc.m_name = "SecondPipeline";
  256. pipelineDesc.m_rootPassTemplate = "MainPipeline";
  257. pipelineDesc.m_renderSettings.m_multisampleState.m_samples = 4;
  258. m_secondPipeline = AZ::RPI::RenderPipeline::CreateRenderPipelineForWindow(pipelineDesc, *m_secondWindowContext);
  259. m_scene->AddRenderPipeline(m_secondPipeline);
  260. // Create a new camera entity and use it for the second render pipeline
  261. m_secondViewCameraEntity = AtomSampleViewer::CreateEntity("SecondViewCamera", GetEntityContextId());
  262. AZ::Debug::CameraComponentConfig cameraConfig(m_secondWindowContext);
  263. cameraConfig.m_fovY = AZ::Constants::QuarterPi * 1.5f;
  264. cameraConfig.m_target = m_secondWindowContext;
  265. AZ::Debug::CameraComponent* camComponent = static_cast<AZ::Debug::CameraComponent*>(m_secondViewCameraEntity->CreateComponent(
  266. azrtti_typeid<AZ::Debug::CameraComponent>()));
  267. camComponent->SetConfiguration(cameraConfig);
  268. m_secondViewCameraEntity->CreateComponent(azrtti_typeid<AzFramework::TransformComponent>());
  269. m_secondViewCameraEntity->CreateComponent(azrtti_typeid<AZ::Debug::NoClipControllerComponent>());
  270. m_secondViewCameraEntity->Activate();
  271. AZ::Debug::CameraControllerRequestBus::Event(m_secondViewCameraEntity->GetId(), &AZ::Debug::CameraControllerRequestBus::Events::Enable,
  272. azrtti_typeid<AZ::Debug::NoClipControllerComponent>());
  273. // Set camera's initial transform and fov
  274. auto cameraId = m_secondViewCameraEntity->GetId();
  275. AZ::Debug::NoClipControllerRequestBus::Event(cameraId, &AZ::Debug::NoClipControllerRequestBus::Events::SetFov, AZ::DegToRad(90));
  276. AZ::Debug::NoClipControllerRequestBus::Event(cameraId, &AZ::Debug::NoClipControllerRequestBus::Events::SetPosition, Vector3(2.75f, 5.25f, 1.49f));
  277. AZ::Debug::NoClipControllerRequestBus::Event(cameraId, &AZ::Debug::NoClipControllerRequestBus::Events::SetHeading, AZ::DegToRad(-171.9));
  278. AZ::Debug::NoClipControllerRequestBus::Event(cameraId, &AZ::Debug::NoClipControllerRequestBus::Events::SetPitch, AZ::DegToRad(-11.6f));
  279. if (m_useSecondCamera)
  280. {
  281. AZ::EntityId secondCameraEntityId = m_secondViewCameraEntity->GetId();
  282. m_secondPipeline->SetDefaultViewFromEntity(secondCameraEntityId);
  283. // associate a setting to the secondary view
  284. AZ::RPI::ViewPtr cameraView;
  285. AZ::RPI::ViewProviderBus::EventResult(cameraView, secondCameraEntityId, &AZ::RPI::ViewProvider::GetView);
  286. AZ::Render::PostProcessSettingsInterface::ViewBlendWeightMap perViewBlendWeights;
  287. perViewBlendWeights[cameraView.get()] = 1.0;
  288. auto* postProcessSettings = m_postProcessFeatureProcessor->GetOrCreateSettingsInterface(secondCameraEntityId);
  289. postProcessSettings->CopyViewToBlendWeightSettings(perViewBlendWeights);
  290. }
  291. else
  292. {
  293. m_secondPipeline->SetDefaultViewFromEntity(GetCameraEntityId());
  294. }
  295. }
  296. void MultiRenderPipelineExampleComponent::RemoveSecondRenderPipeline()
  297. {
  298. AzFramework::WindowNotificationBus::Handler::BusDisconnect();
  299. if (m_secondViewCameraEntity)
  300. {
  301. DestroyEntity(m_secondViewCameraEntity);
  302. m_secondViewCameraEntity = nullptr;
  303. }
  304. if (m_secondPipeline)
  305. {
  306. m_secondPipeline->RemoveFromScene();
  307. m_secondPipeline = nullptr;
  308. }
  309. m_secondWindowContext = nullptr;
  310. m_secondWindow = nullptr;
  311. }
  312. void MultiRenderPipelineExampleComponent::CleanUpScene()
  313. {
  314. RemoveIBL();
  315. DisableSkybox();
  316. RemoveDiskLight();
  317. RemoveDirectionalLight();
  318. DisableDepthOfField();
  319. RemoveSecondRenderPipeline();
  320. GetMeshFeatureProcessor()->ReleaseMesh(m_floorMeshHandle);
  321. for (auto index = 0; index < BunnyCount; index++)
  322. {
  323. GetMeshFeatureProcessor()->ReleaseMesh(m_bunnyMeshHandles[index]);
  324. }
  325. }
  326. void MultiRenderPipelineExampleComponent::Deactivate()
  327. {
  328. m_imguiSidebar.Deactivate();
  329. AZ::TickBus::Handler::BusDisconnect();
  330. CleanUpScene();
  331. m_directionalLightFeatureProcessor = nullptr;
  332. m_diskLightFeatureProcessor = nullptr;
  333. m_skyboxFeatureProcessor = nullptr;
  334. m_scene = nullptr;
  335. }
  336. void MultiRenderPipelineExampleComponent::OnWindowClosed()
  337. {
  338. RemoveSecondRenderPipeline();
  339. m_enableSecondRenderPipeline = false;
  340. }
  341. void MultiRenderPipelineExampleComponent::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint timePoint)
  342. {
  343. bool queueSecondWindowDeactivate = false;
  344. if (m_hasDirectionalLight)
  345. {
  346. auto& featureProcessor = m_directionalLightFeatureProcessor;
  347. Transform cameraTransform = Transform::CreateIdentity();
  348. TransformBus::EventResult(
  349. cameraTransform,
  350. GetCameraEntityId(),
  351. &TransformBus::Events::GetWorldTM);
  352. featureProcessor->SetCameraTransform(
  353. m_directionalLightHandle,
  354. cameraTransform);
  355. if (m_useSecondCamera && m_secondViewCameraEntity)
  356. {
  357. TransformBus::EventResult(
  358. cameraTransform,
  359. m_secondViewCameraEntity->GetId(),
  360. &TransformBus::Events::GetWorldTM);
  361. featureProcessor->SetCameraTransform(
  362. m_directionalLightHandle,
  363. cameraTransform,
  364. m_secondPipeline->GetId());
  365. }
  366. }
  367. if (m_imguiSidebar.Begin())
  368. {
  369. ImGui::Spacing();
  370. ImGui::Text("Second RenderPipeline");
  371. ImGui::Indent();
  372. if (SupportsMultipleWindows())
  373. {
  374. if (ScriptableImGui::Checkbox("Enable second pipeline", &m_enableSecondRenderPipeline))
  375. {
  376. if (m_enableSecondRenderPipeline)
  377. {
  378. AddSecondRenderPipeline();
  379. }
  380. else
  381. {
  382. queueSecondWindowDeactivate = true;
  383. }
  384. }
  385. ImGui::Indent();
  386. if (m_secondPipeline)
  387. {
  388. if (ScriptableImGui::Checkbox("Use second camera", &m_useSecondCamera))
  389. {
  390. if (m_useSecondCamera)
  391. {
  392. m_secondPipeline->SetDefaultViewFromEntity(m_secondViewCameraEntity->GetId());
  393. }
  394. else
  395. {
  396. m_secondPipeline->SetDefaultViewFromEntity(GetCameraEntityId());
  397. }
  398. }
  399. }
  400. ImGui::Unindent();
  401. ImGui::Separator();
  402. }
  403. ImGui::Unindent();
  404. ImGui::Spacing();
  405. ImGui::Text("Features");
  406. ImGui::Indent();
  407. if (ScriptableImGui::Checkbox("Enable Depth of Field", &m_enabledDepthOfField))
  408. {
  409. if (m_enabledDepthOfField)
  410. {
  411. EnableDepthOfField();
  412. }
  413. else
  414. {
  415. DisableDepthOfField();
  416. }
  417. }
  418. if (ScriptableImGui::Checkbox("Add/Remove Directional Light", &m_hasDirectionalLight))
  419. {
  420. if (m_hasDirectionalLight)
  421. {
  422. AddDirectionalLight();
  423. }
  424. else
  425. {
  426. RemoveDirectionalLight();
  427. }
  428. }
  429. if (m_hasDirectionalLight)
  430. {
  431. ImGui::Indent();
  432. ImGui::Text("Filtering Method");
  433. bool methodChanged = false;
  434. methodChanged = methodChanged ||
  435. ScriptableImGui::RadioButton("None", &m_shadowFilteringMethod, 0);
  436. ImGui::SameLine();
  437. methodChanged = methodChanged ||
  438. ScriptableImGui::RadioButton("PCF", &m_shadowFilteringMethod, 1);
  439. ImGui::SameLine();
  440. methodChanged = methodChanged ||
  441. ScriptableImGui::RadioButton("ESM", &m_shadowFilteringMethod, 2);
  442. ImGui::SameLine();
  443. methodChanged = methodChanged ||
  444. ScriptableImGui::RadioButton("ESM+PCF", &m_shadowFilteringMethod, 3);
  445. if (methodChanged)
  446. {
  447. m_directionalLightFeatureProcessor->SetShadowFilterMethod(m_directionalLightHandle, aznumeric_cast<Render::ShadowFilterMethod>(m_shadowFilteringMethod));
  448. }
  449. ImGui::Unindent();
  450. }
  451. if (ScriptableImGui::Checkbox("Add/Remove Spot Light", &m_hasDiskLight))
  452. {
  453. if (m_hasDiskLight)
  454. {
  455. AddDiskLight();
  456. }
  457. else
  458. {
  459. RemoveDiskLight();
  460. }
  461. }
  462. if (ScriptableImGui::Checkbox("Enable Skybox", &m_enabledSkybox))
  463. {
  464. if (m_enabledSkybox)
  465. {
  466. EnableSkybox();
  467. }
  468. else
  469. {
  470. DisableSkybox();
  471. }
  472. }
  473. if (ScriptableImGui::Checkbox("Add/Remove IBL", &m_hasIBL))
  474. {
  475. if (m_hasIBL)
  476. {
  477. AddIBL();
  478. }
  479. else
  480. {
  481. RemoveIBL();
  482. }
  483. }
  484. ImGui::Unindent();
  485. ImGui::Separator();
  486. m_imguiSidebar.End();
  487. }
  488. if (m_secondPipeline)
  489. {
  490. Render::ImGuiActiveContextScope contextGuard = Render::ImGuiActiveContextScope::FromPass(RPI::PassHierarchyFilter({ "SecondPipeline", "ImGuiPass"}));
  491. AZ_Error("MultiRenderPipelineExampleComponent", contextGuard.IsEnabled(), "Unable to activate imgui context for second pipeline.");
  492. if (contextGuard.IsEnabled())
  493. {
  494. if (ImGui::Begin("Second Window"))
  495. {
  496. if (ScriptableImGui::Button("Close Window"))
  497. {
  498. queueSecondWindowDeactivate = true;
  499. }
  500. }
  501. ImGui::End();
  502. }
  503. }
  504. if (queueSecondWindowDeactivate)
  505. {
  506. m_secondWindow->Deactivate();
  507. }
  508. }
  509. } // namespace AtomSampleViewer