MultiRenderPipelineExampleComponent.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 <Atom/RPI.Public/Base.h>
  11. #include <Atom/RPI.Public/WindowContext.h>
  12. #include <AzCore/Asset/AssetCommon.h>
  13. #include <AzCore/Component/TickBus.h>
  14. #include <AzFramework/Windowing/WindowBus.h>
  15. #include <AzFramework/Windowing/NativeWindow.h>
  16. #include <Atom/Feature/CoreLights/DirectionalLightFeatureProcessorInterface.h>
  17. #include <Atom/Feature/CoreLights/DiskLightFeatureProcessorInterface.h>
  18. #include <Atom/Feature/CoreLights/ShadowConstants.h>
  19. #include <Atom/Feature/SkyBox/SkyBoxFeatureProcessorInterface.h>
  20. #include <Atom/Feature/PostProcess/PostProcessFeatureProcessorInterface.h>
  21. #include <Utils/ImGuiSidebar.h>
  22. #include <Utils/Utils.h>
  23. struct ImGuiContext;
  24. namespace AtomSampleViewer
  25. {
  26. //! A sample component which render the same scene with different render pipelines in different windows
  27. //! It has a imgui menu to switch on/off the second render pipeline as well as turn on/off different graphics features
  28. //! There is also an option to have the second render pipeline to use the second camera.
  29. class MultiRenderPipelineExampleComponent final
  30. : public CommonSampleComponentBase
  31. , public AZ::TickBus::Handler
  32. , public AzFramework::WindowNotificationBus::Handler
  33. {
  34. public:
  35. AZ_COMPONENT(MultiRenderPipelineExampleComponent, "{A3654684-DB33-4B2C-B7AB-9B1D6BF3FCF1}", CommonSampleComponentBase);
  36. static void Reflect(AZ::ReflectContext* context);
  37. MultiRenderPipelineExampleComponent();
  38. ~MultiRenderPipelineExampleComponent() final = default;
  39. // AZ::Component
  40. void Activate() override;
  41. void Deactivate() override;
  42. // AzFramework::WindowNotificationBus::Handler
  43. void OnWindowClosed() override;
  44. private:
  45. // AZ::TickBus::Handler overrides ...
  46. void OnTick(float deltaTime, AZ::ScriptTimePoint timePoint) override;
  47. // CommonSampleComponentBase overrides...
  48. void OnAllAssetsReadyActivate() override;
  49. // Add render content to the scene
  50. void SetupScene();
  51. // Clean up render content in the scene
  52. void CleanUpScene();
  53. // enable/disable different features for the second render pipeline
  54. void EnableDepthOfField();
  55. void DisableDepthOfField();
  56. void AddDirectionalLight();
  57. void RemoveDirectionalLight();
  58. void AddDiskLight();
  59. void RemoveDiskLight();
  60. void EnableSkybox();
  61. void DisableSkybox();
  62. void AddIBL();
  63. void RemoveIBL();
  64. void AddSecondRenderPipeline();
  65. void RemoveSecondRenderPipeline();
  66. // For draw menus of selecting pipelines
  67. ImGuiSidebar m_imguiSidebar;
  68. // For scene content
  69. using DirectionalLightHandle = AZ::Render::DirectionalLightFeatureProcessorInterface::LightHandle;
  70. using DiskLightHandle = AZ::Render::DiskLightFeatureProcessorInterface::LightHandle;
  71. using MeshHandle = AZ::Render::MeshFeatureProcessorInterface::MeshHandle;
  72. // Directional light
  73. AZ::Render::DirectionalLightFeatureProcessorInterface* m_directionalLightFeatureProcessor = nullptr;
  74. DirectionalLightHandle m_directionalLightHandle;
  75. // Disk light
  76. AZ::Render::DiskLightFeatureProcessorInterface* m_diskLightFeatureProcessor = nullptr;
  77. DiskLightHandle m_diskLightHandle;
  78. // Meshes
  79. MeshHandle m_floorMeshHandle;
  80. static const uint32_t BunnyCount = 5;
  81. MeshHandle m_bunnyMeshHandles[BunnyCount];
  82. // Skybox
  83. AZ::Render::SkyBoxFeatureProcessorInterface* m_skyboxFeatureProcessor = nullptr;
  84. // IBL
  85. Utils::DefaultIBL m_ibl;
  86. // Post Process
  87. AZ::Render::PostProcessFeatureProcessorInterface* m_postProcessFeatureProcessor = nullptr;
  88. AZ::Entity* m_depthOfFieldEntity = nullptr;
  89. // flags of features enabled
  90. bool m_enabledDepthOfField = true;
  91. bool m_hasDirectionalLight = true;
  92. bool m_hasDiskLight = true;
  93. bool m_enabledSkybox = true;
  94. bool m_hasIBL = true;
  95. bool m_enableSecondRenderPipeline = true;
  96. bool m_useSecondCamera = false;
  97. // for directional light
  98. int m_shadowFilteringMethod = aznumeric_cast<int>(AZ::Render::ShadowFilterMethod::EsmPcf);
  99. // For second render pipeline
  100. AZStd::shared_ptr<AzFramework::NativeWindow> m_secondWindow;
  101. AZStd::shared_ptr<AZ::RPI::WindowContext> m_secondWindowContext;
  102. AZ::RPI::RenderPipelinePtr m_secondPipeline;
  103. // camera for the second render pipeline
  104. AZ::Entity* m_secondViewCameraEntity = nullptr;
  105. };
  106. } // namespace AtomSampleViewer