MultiSceneExampleComponent.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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/PointLightFeatureProcessorInterface.h>
  21. #include <Atom/Feature/CoreLights/SpotLightFeatureProcessorInterface.h>
  22. #include <Atom/Feature/CoreLights/DirectionalLightFeatureProcessorInterface.h>
  23. #include <Atom/Feature/ReflectionProbe/ReflectionProbeFeatureProcessorInterface.h>
  24. #include <Atom/Feature/ReflectionProbe/ReflectionProbeFeatureProcessor.h>
  25. #include <Utils/Utils.h>
  26. struct ImGuiContext;
  27. namespace AtomSampleViewer
  28. {
  29. class SecondWindowedScene
  30. : public AZ::TickBus::Handler
  31. , public AzFramework::WindowNotificationBus::Handler
  32. {
  33. using ModelChangedHandler = AZ::Render::MeshFeatureProcessorInterface::ModelChangedEvent::Handler;
  34. using PointLightHandle = AZ::Render::PointLightFeatureProcessorInterface::LightHandle;
  35. using SpotLightHandle = AZ::Render::SpotLightFeatureProcessorInterface::LightHandle;
  36. using DirectionalLightHandle = AZ::Render::DirectionalLightFeatureProcessorInterface::LightHandle;
  37. using ReflectinoProbeHandle = AZ::Render::ReflectionProbeHandle;
  38. static constexpr uint32_t ShaderBallCount = 12u;
  39. public:
  40. SecondWindowedScene(AZStd::string_view sceneName, class MultiSceneExampleComponent* parent);
  41. ~SecondWindowedScene();
  42. AzFramework::NativeWindowHandle GetNativeWindowHandle();
  43. void MoveCamera(bool enabled);
  44. // AZ::TickBus::Handler overrides ...
  45. void OnTick(float deltaTime, AZ::ScriptTimePoint timePoint) override;
  46. // AzFramework::WindowNotificationBus::Handler overrides ...
  47. void OnWindowClosed() override;
  48. private:
  49. AZStd::unique_ptr<AzFramework::NativeWindow> m_nativeWindow;
  50. AZStd::shared_ptr<AZ::RPI::WindowContext> m_windowContext;
  51. AZStd::unique_ptr<AzFramework::EntityContext> m_entityContext;
  52. AZStd::string m_sceneName;
  53. AzFramework::Scene* m_frameworkScene = nullptr;
  54. AZ::RPI::ScenePtr m_scene;
  55. AZ::RPI::RenderPipelinePtr m_pipeline;
  56. // Entities
  57. AZ::Entity* m_cameraEntity = nullptr;
  58. AZ::Entity* m_depthOfFieldEntity = nullptr;
  59. // Feature Settings
  60. AZ::Render::DepthOfFieldSettingsInterface* m_depthOfFieldSettings = nullptr;
  61. // FeatureProcessors
  62. AZ::Render::MeshFeatureProcessorInterface* m_meshFeatureProcessor = nullptr;
  63. AZ::Render::SkyBoxFeatureProcessorInterface* m_skyBoxFeatureProcessor = nullptr;
  64. AZ::Render::PointLightFeatureProcessorInterface* m_pointLightFeatureProcessor = nullptr;
  65. AZ::Render::SpotLightFeatureProcessorInterface* m_spotLightFeatureProcessor = nullptr;
  66. AZ::Render::DirectionalLightFeatureProcessorInterface* m_directionalLightFeatureProcessor = nullptr;
  67. AZ::Render::PostProcessFeatureProcessorInterface* m_postProcessFeatureProcessor = nullptr;
  68. AZ::Render::ReflectionProbeFeatureProcessorInterface* m_reflectionProbeFeatureProcessor = nullptr;
  69. // Meshes
  70. AZStd::vector<AZ::Render::MeshFeatureProcessorInterface::MeshHandle> m_shaderBallMeshHandles;
  71. AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_floorMeshHandle;
  72. // Model change handlers
  73. AZStd::vector<ModelChangedHandler> m_shaderBallChangedHandles;
  74. // Various FeatureProcessor handles
  75. PointLightHandle m_pointLightHandle;
  76. SpotLightHandle m_spotLightHandle;
  77. DirectionalLightHandle m_directionalLightHandle;
  78. ReflectinoProbeHandle m_reflectionProbeHandle;
  79. double m_simulateTime = 0.0f;
  80. float m_deltaTime = 0.0f;
  81. MultiSceneExampleComponent* m_parent = nullptr;
  82. const AZ::Vector3 m_cameraOffset{ 0.0f, -4.0f, 2.0f };
  83. AZ::Vector3 m_dynamicCameraOffset{ 3.73f, 0.0f, 0.0f };
  84. bool m_moveCamera = false;
  85. Utils::DefaultIBL m_defaultIbl;
  86. };
  87. //! A sample component to demonstrate multiple scenes.
  88. class MultiSceneExampleComponent final
  89. : public CommonSampleComponentBase
  90. , public AZ::TickBus::Handler
  91. {
  92. public:
  93. AZ_COMPONENT(MultiSceneExampleComponent, "{FB0F55AE-6708-47BE-87EB-DD1EB3EF5CD1}", CommonSampleComponentBase);
  94. static void Reflect(AZ::ReflectContext* context);
  95. MultiSceneExampleComponent();
  96. ~MultiSceneExampleComponent() override = default;
  97. // AZ::Component
  98. void Activate() override;
  99. void Deactivate() override;
  100. void OnChildWindowClosed();
  101. private:
  102. // AZ::TickBus::Handler overrides ...
  103. void OnTick(float deltaTime, AZ::ScriptTimePoint timePoint) override;
  104. void OpenSecondSceneWindow();
  105. AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_meshHandle;
  106. AZ::Component* m_mainCameraControlComponent = nullptr;
  107. AZStd::unique_ptr<SecondWindowedScene> m_windowedScene;
  108. // Lights
  109. Utils::DefaultIBL m_defaultIbl;
  110. };
  111. } // namespace AtomSampleViewer