MultiRenderPipelineExampleComponent.h 5.2 KB

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