MultiRenderPipelineExampleComponent.cpp 23 KB

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