SsaoExampleComponent.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #pragma once
  9. #include <CommonSampleComponentBase.h>
  10. #include <AzCore/Component/EntityBus.h>
  11. #include <AzCore/Component/TickBus.h>
  12. #include <Atom/Feature/ImGui/ImGuiUtils.h>
  13. #include <AzFramework/Input/Events/InputChannelEventListener.h>
  14. #include <Atom/Bootstrap/DefaultWindowBus.h>
  15. #include <Atom/RPI.Public/Pass/Specific/SelectorPass.h>
  16. #include <Passes/RayTracingAmbientOcclusionPass.h>
  17. #include <Utils/ImGuiSidebar.h>
  18. #include <Utils/Utils.h>
  19. #include <ExampleComponentBus.h>
  20. namespace AtomSampleViewer
  21. {
  22. //!
  23. //! This component creates a simple scene that tests raw SSAO output from depth
  24. //!
  25. class SsaoExampleComponent final
  26. : public CommonSampleComponentBase
  27. , public AZ::Render::Bootstrap::DefaultWindowNotificationBus::Handler
  28. , public AZ::TickBus::Handler
  29. {
  30. public:
  31. AZ_COMPONENT(SsaoExampleComponent, "{5D1A0FF0-02CB-4462-8A87-27498F67BEC1}", CommonSampleComponentBase);
  32. static void Reflect(AZ::ReflectContext* context);
  33. void Activate() override;
  34. void Deactivate() override;
  35. private:
  36. // AZ::TickBus::Handler
  37. void OnTick(float deltaTime, AZ::ScriptTimePoint timePoint) override;
  38. // AZ::EntityBus::MultiHandler...
  39. void OnEntityDestruction(const AZ::EntityId& entityId) override;
  40. void ActivatePostProcessSettings();
  41. void DectivatePostProcessSettings();
  42. void ActivateSsaoPipeline();
  43. void DeactivateSsaoPipeline();
  44. void CreateSsaoPipeline();
  45. void DestroySsaoPipeline();
  46. void ActivateModel();
  47. void DeactivateModel();
  48. void ActivateCamera();
  49. void DeactivateCamera();
  50. void MoveCameraToStartPosition();
  51. void DefaultWindowCreated() override;
  52. void OnModelReady(AZ::Data::Instance<AZ::RPI::Model> model);
  53. void DrawImGUI();
  54. void DrawSidebar();
  55. void SwitchAOType();
  56. AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_meshHandle;
  57. AZ::RPI::RenderPipelinePtr m_ssaoPipeline;
  58. AZ::RPI::RenderPipelinePtr m_originalPipeline;
  59. AZStd::shared_ptr<AZ::RPI::WindowContext> m_windowContext;
  60. ImGuiSidebar m_imguiSidebar;
  61. float m_originalFarClipDistance = 0.f;
  62. bool m_worldModelAssetLoaded = false;
  63. AZ::Render::PostProcessFeatureProcessorInterface* m_postProcessFeatureProcessor = nullptr;
  64. AZ::Render::SsaoSettingsInterface* m_ssaoSettings = nullptr;
  65. AZ::Entity* m_ssaoEntity = nullptr;
  66. AZ::Render::ImGuiActiveContextScope m_imguiScope;
  67. enum AmbientOcclusionType
  68. {
  69. SSAO = 0,
  70. RTAO
  71. };
  72. // Ambient Occlusion type. 0: SSAO; 1: RTAO
  73. int m_aoType = AmbientOcclusionType::SSAO;
  74. // Ray tracing ambient occlusion
  75. bool m_rayTracingEnabled = false;
  76. AZ::RPI::Ptr<AZ::Render::RayTracingAmbientOcclusionPass> m_RTAOPass;
  77. // To swtich between outputs
  78. AZ::RPI::Ptr<AZ::RPI::SelectorPass> m_selector;
  79. };
  80. } // namespace AtomSampleViewer