MSAA_RPI_ExampleComponent.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0 OR MIT
  5. *
  6. */
  7. #pragma once
  8. #include <CommonSampleComponentBase.h>
  9. #include <AzCore/Component/EntityBus.h>
  10. #include <AzCore/Component/TickBus.h>
  11. #include <Atom/Feature/ImGui/ImGuiUtils.h>
  12. #include <AzFramework/Input/Events/InputChannelEventListener.h>
  13. #include <Atom/Bootstrap/DefaultWindowBus.h>
  14. #include <Utils/ImGuiSidebar.h>
  15. #include <Utils/Utils.h>
  16. #include <ExampleComponentBus.h>
  17. namespace AtomSampleViewer
  18. {
  19. //!
  20. //! This component creates a simple scene that tests the MSAA pipeline. It can test both MSAA enabled and disabled with the same scene
  21. //!
  22. class MSAA_RPI_ExampleComponent final
  23. : public CommonSampleComponentBase
  24. , public AZ::Render::Bootstrap::DefaultWindowNotificationBus::Handler
  25. , public AZ::TickBus::Handler
  26. , public ExampleComponentRequestBus::Handler
  27. {
  28. public:
  29. AZ_COMPONENT(MSAA_RPI_ExampleComponent, "{2BDCA64E-7E5F-49EE-ACF5-65C79C40840D}", CommonSampleComponentBase);
  30. static void Reflect(AZ::ReflectContext* context);
  31. void Activate() override;
  32. void Deactivate() override;
  33. private:
  34. // DefaultWindowNotificationBus::Handler
  35. void DefaultWindowCreated() override;
  36. // AZ::TickBus::Handler
  37. void OnTick(float deltaTime, AZ::ScriptTimePoint timePoint) override;
  38. // ExampleComponentRequestBus::Handler
  39. void ResetCamera() override;
  40. // helper functions
  41. void ChangeRenderPipeline();
  42. void ActivateIbl();
  43. void ActivateModel();
  44. void OnModelReady(AZ::Data::Instance<AZ::RPI::Model> model);
  45. AZ::Data::Asset<AZ::RPI::MaterialAsset> GetMaterialAsset();
  46. AZ::Data::Asset<AZ::RPI::ModelAsset> GetModelAsset();
  47. void DrawSidebar();
  48. bool DrawSidebarModeChooser(bool refresh);
  49. bool DrawSideBarModelChooser(bool refresh);
  50. // sample mesh
  51. int m_modelType = 0;
  52. AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_meshHandle;
  53. AZ::Render::MeshFeatureProcessorInterface::ModelChangedEvent::Handler m_meshChangedHandler
  54. {
  55. [&](AZ::Data::Instance<AZ::RPI::Model> model)
  56. {
  57. OnModelReady(model);
  58. }
  59. };
  60. // original render pipeline when the sample was started
  61. AZ::RPI::RenderPipelinePtr m_originalPipeline;
  62. // sample render pipeline, can be MSAA 2x/4x/8x or non-MSAA
  63. AZ::RPI::RenderPipelinePtr m_samplePipeline;
  64. // number of MSAA samples in the pipeline, controlled by the user
  65. int m_numSamples = 1;
  66. // flag indicating if the current pipeline is a non-MSAA pipeline
  67. bool m_isNonMsaaPipeline = false;
  68. // other state
  69. AZStd::shared_ptr<AZ::RPI::WindowContext> m_windowContext;
  70. Utils::DefaultIBL m_defaultIbl;
  71. ImGuiSidebar m_imguiSidebar;
  72. AZ::Render::ImGuiActiveContextScope m_imguiScope;
  73. };
  74. } // namespace AtomSampleViewer