SsaoExampleComponent.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. * its licensors.
  4. *
  5. * For complete copyright and license terms please see the LICENSE at the root of this
  6. * distribution (the "License"). All use of this software is governed by the License,
  7. * or, if provided, by the license below or the license accompanying this file. Do not
  8. * remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. *
  11. */
  12. #pragma once
  13. #include <CommonSampleComponentBase.h>
  14. #include <AzCore/Component/EntityBus.h>
  15. #include <AzCore/Component/TickBus.h>
  16. #include <Atom/Feature/ImGui/ImGuiUtils.h>
  17. #include <AzFramework/Input/Events/InputChannelEventListener.h>
  18. #include <Atom/Bootstrap/DefaultWindowBus.h>
  19. #include <Atom/RPI.Public/Pass/Specific/SelectorPass.h>
  20. #include <Passes/RayTracingAmbientOcclusionPass.h>
  21. #include <Utils/ImGuiSidebar.h>
  22. #include <Utils/Utils.h>
  23. #include <ExampleComponentBus.h>
  24. namespace AtomSampleViewer
  25. {
  26. //!
  27. //! This component creates a simple scene that tests raw SSAO output from depth
  28. //!
  29. class SsaoExampleComponent final
  30. : public CommonSampleComponentBase
  31. , public AZ::Render::Bootstrap::DefaultWindowNotificationBus::Handler
  32. , public AZ::TickBus::Handler
  33. {
  34. public:
  35. AZ_COMPONENT(SsaoExampleComponent, "{5D1A0FF0-02CB-4462-8A87-27498F67BEC1}", CommonSampleComponentBase);
  36. static void Reflect(AZ::ReflectContext* context);
  37. void Activate() override;
  38. void Deactivate() override;
  39. private:
  40. // AZ::TickBus::Handler
  41. void OnTick(float deltaTime, AZ::ScriptTimePoint timePoint) override;
  42. // AZ::EntityBus::MultiHandler...
  43. void OnEntityDestruction(const AZ::EntityId& entityId) override;
  44. void ActivatePostProcessSettings();
  45. void DectivatePostProcessSettings();
  46. void ActivateSsaoPipeline();
  47. void DeactivateSsaoPipeline();
  48. void CreateSsaoPipeline();
  49. void DestroySsaoPipeline();
  50. void ActivateModel();
  51. void DeactivateModel();
  52. void ActivateCamera();
  53. void DeactivateCamera();
  54. void MoveCameraToStartPosition();
  55. void DefaultWindowCreated() override;
  56. void OnModelReady(AZ::Data::Instance<AZ::RPI::Model> model);
  57. void DrawImGUI();
  58. void DrawSidebar();
  59. void SwitchAOType();
  60. AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_meshHandle;
  61. AZ::Render::MeshFeatureProcessorInterface::ModelChangedEvent::Handler m_meshChangedHandler
  62. {
  63. [&](AZ::Data::Instance<AZ::RPI::Model> model)
  64. {
  65. OnModelReady(model);
  66. }
  67. };
  68. AZ::RPI::RenderPipelinePtr m_ssaoPipeline;
  69. AZ::RPI::RenderPipelinePtr m_originalPipeline;
  70. AZStd::shared_ptr<AZ::RPI::WindowContext> m_windowContext;
  71. ImGuiSidebar m_imguiSidebar;
  72. float m_originalFarClipDistance = 0.f;
  73. bool m_worldModelAssetLoaded = false;
  74. AZ::Render::PostProcessFeatureProcessorInterface* m_postProcessFeatureProcessor = nullptr;
  75. AZ::Render::SsaoSettingsInterface* m_ssaoSettings = nullptr;
  76. AZ::Entity* m_ssaoEntity = nullptr;
  77. AZ::Render::ImGuiActiveContextScope m_imguiScope;
  78. enum AmbientOcclusionType
  79. {
  80. SSAO = 0,
  81. RTAO
  82. };
  83. // Ambient Occlusion type. 0: SSAO; 1: RTAO
  84. int m_aoType = AmbientOcclusionType::SSAO;
  85. // Ray tracing ambient occlusion
  86. bool m_rayTracingEnabled = false;
  87. AZ::RPI::Ptr<AZ::Render::RayTracingAmbientOcclusionPass> m_RTAOPass;
  88. // To swtich between outputs
  89. AZ::RPI::Ptr<AZ::RPI::SelectorPass> m_selector;
  90. };
  91. } // namespace AtomSampleViewer