2
0

Subpass_RPI_ExampleComponent.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 <AzCore/Component/EntityBus.h>
  10. #include <AzFramework/Input/Events/InputChannelEventListener.h>
  11. #include <Atom/Bootstrap/DefaultWindowBus.h>
  12. #include <Atom/Feature/ImGui/ImGuiUtils.h>
  13. #include <Atom/Feature/SkyBox/SkyBoxFeatureProcessorInterface.h>
  14. #include <Utils/Utils.h>
  15. #include <Utils/ImGuiSidebar.h>
  16. #include <CommonSampleComponentBase.h>
  17. namespace AtomSampleViewer
  18. {
  19. //! This example demonstrates how to use Subpasses at the RPI level.
  20. //! The are two Render Pipelines that are identical in terms of expected output,
  21. //! but they work diffrently to achive the same outcome.
  22. //! The first (default) pipeline is made of Two Subpasses, Forward followed by SkyBox.
  23. //! The second pipeline is made of Two Passes, Forward followed by SkyBox.
  24. //! The user can switch between those two pipelines by using the Keys '1' or '2'.
  25. class Subpass_RPI_ExampleComponent final
  26. : public CommonSampleComponentBase
  27. , public AZ::Render::Bootstrap::DefaultWindowNotificationBus::Handler
  28. , public AzFramework::InputChannelEventListener
  29. {
  30. public:
  31. AZ_COMPONENT(Subpass_RPI_ExampleComponent, "{6AD413AE-161D-4A8B-99B3-58E02277F2F0}", CommonSampleComponentBase);
  32. static void Reflect(AZ::ReflectContext* context);
  33. static constexpr char LogName[] = "Subpass_RPI_Example";
  34. Subpass_RPI_ExampleComponent();
  35. ~Subpass_RPI_ExampleComponent() override = default;
  36. //! AZ::Component
  37. void Activate() override;
  38. void Deactivate() override;
  39. private:
  40. //! AZ::EntityBus::MultiHandler
  41. void OnEntityDestruction(const AZ::EntityId& entityId) override;
  42. //! AzFramework::InputChannelEventListener
  43. //! In this example we use keyboard events for the digit keys to allow
  44. //! the user to change the active pipeline.
  45. bool OnInputChannelEventFiltered(const AzFramework::InputChannel& inputChannel) override;
  46. //! Must be called before ActivateModel();
  47. void ActivateGroundPlane();
  48. void ActivateModel();
  49. void UpdateGroundPlane();
  50. void UseArcBallCameraController();
  51. void UseNoClipCameraController();
  52. void RemoveController();
  53. void SetArcBallControllerParams();
  54. void ResetCameraController();
  55. void DefaultWindowCreated() override;
  56. enum class AvailablePipelines : size_t
  57. {
  58. TwoSubpassesPipeline,
  59. TwoPassesPipeline,
  60. Count
  61. };
  62. void ChangeActivePipeline(AvailablePipelines pipelineOption);
  63. void RestoreOriginalPipeline();
  64. static constexpr char DefaultMaterialPath[] = "objects/hermanubis/hermanubis_stone.azmaterial";
  65. static constexpr char DefaultModelPath[] = "materialeditor/viewportmodels/hermanubis.fbx.azmodel";
  66. static constexpr char DefaultGroundPlaneModelPath[] = "objects/plane.fbx.azmodel";
  67. AvailablePipelines m_activePipelineOption = AvailablePipelines::TwoSubpassesPipeline;
  68. //! Original render pipeline when the sample was started.
  69. //! This sample only goes back to this pipeline when it is closed/deactivated.
  70. AZ::RPI::RenderPipelinePtr m_originalPipeline = nullptr;
  71. //! The active pipeline from this sample. It can be one of:
  72. //! 1- TwoSubpassesPipeline (default): One Vulkan Render Pass that contains two Subpasses.
  73. //! Manually activated by the user when pressing the '1' keyboard key.
  74. //! 2- TwoPassesPipeline: Two Vulkan Render Passes.
  75. //! Manually activated by the user when pressing the '2' keyboard key.
  76. AZ::RPI::RenderPipelinePtr m_activePipeline = nullptr;
  77. AZStd::shared_ptr<AZ::RPI::WindowContext> m_windowContext;
  78. AZ::Render::ImGuiActiveContextScope m_imguiScope;
  79. enum class CameraControllerType : int32_t
  80. {
  81. ArcBall = 0,
  82. NoClip,
  83. Count
  84. };
  85. static const uint32_t CameraControllerCount = static_cast<uint32_t>(CameraControllerType::Count);
  86. static const char* CameraControllerNameTable[CameraControllerCount];
  87. CameraControllerType m_currentCameraControllerType = CameraControllerType::ArcBall;
  88. static constexpr float ArcballRadiusMinModifier = 0.01f;
  89. static constexpr float ArcballRadiusMaxModifier = 4.0f;
  90. static constexpr float ArcballRadiusDefaultModifier = 2.0f;
  91. bool m_cameraControllerDisabled = false;
  92. AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_meshHandle;
  93. AZ::Data::Asset<AZ::RPI::ModelAsset> m_modelAsset;
  94. AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_groundPlandMeshHandle;
  95. AZ::Data::Asset<AZ::RPI::ModelAsset> m_groundPlaneModelAsset;
  96. };
  97. } // namespace AtomSampleViewer