DepthOfFieldExampleComponent.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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/Feature/PostProcess/PostProcessFeatureProcessorInterface.h>
  11. #include <Atom/Feature/CoreLights/DirectionalLightFeatureProcessorInterface.h>
  12. #include <AzCore/Component/EntityBus.h>
  13. #include <AzCore/Component/TickBus.h>
  14. #include <Utils/ImGuiSidebar.h>
  15. namespace AtomSampleViewer
  16. {
  17. /*
  18. * This component creates a simple scene to Depth of Field.
  19. */
  20. class DepthOfFieldExampleComponent final
  21. : public CommonSampleComponentBase
  22. , public AZ::TickBus::Handler
  23. {
  24. public:
  25. AZ_COMPONENT(DepthOfFieldExampleComponent, "{F2CE0FCC-F3CE-4900-929D-74DCF554DF97}", CommonSampleComponentBase);
  26. static void Reflect(AZ::ReflectContext* context);
  27. DepthOfFieldExampleComponent() = default;
  28. ~DepthOfFieldExampleComponent() override = default;
  29. void Activate() override;
  30. void Deactivate() override;
  31. private:
  32. // AZ::TickBus::Handler overrides...
  33. void OnTick(float deltaTime, AZ::ScriptTimePoint time);
  34. // AZ::EntityBus::MultiHandler...
  35. void OnEntityDestruction(const AZ::EntityId& entityId) override;
  36. void UseArcBallCameraController();
  37. void RemoveController();
  38. void CreateMeshes();
  39. void CreateLight();
  40. void CreateDepthOfFieldEntity();
  41. void DrawSidebar();
  42. static constexpr uint32_t BunnyNumber = 32;
  43. static constexpr float DistanceBetweenUnits = 1.0f;
  44. static constexpr float ModelScaleRatio = DistanceBetweenUnits * 1.3f;
  45. static constexpr float ViewNear = 0.2f;
  46. static constexpr float ViewFar = ViewNear + DistanceBetweenUnits * BunnyNumber;
  47. static constexpr float FocusDefault = ViewNear + (ViewFar - ViewNear) * 0.35f;
  48. static constexpr float ViewFovDegrees = 20.0f;
  49. // owning entity
  50. AZ::Entity* m_depthOfFieldEntity = nullptr;
  51. // asset
  52. AZ::Data::Asset<AZ::RPI::ModelAsset> m_bunnyModelAsset;
  53. AZ::Data::Asset<AZ::RPI::MaterialAsset> m_materialAsset;
  54. // Mesh handles
  55. using MeshHandle = AZ::Render::MeshFeatureProcessorInterface::MeshHandle;
  56. AZStd::array<MeshHandle, BunnyNumber> m_meshHandles;
  57. // Light handle
  58. using DirectionalLightHandle = AZ::Render::DirectionalLightFeatureProcessorInterface::LightHandle;
  59. DirectionalLightHandle m_directionalLightHandle;
  60. // GUI
  61. ImGuiSidebar m_imguiSidebar;
  62. // initialize flag
  63. bool m_isInitCamera = false;
  64. bool m_isInitParameters = false;
  65. // save default camera parameter on base viewer.
  66. // When deactivate this component, return the parameters to camera.
  67. float m_saveDefaultNearOnAtomSampleViewer = 0.1f;
  68. float m_saveDefaultFarOnAtomSampleViewer = 10.0f;
  69. float m_saveDefaultFovDegreesOnAtomSampleViewer = 20.0f;
  70. // feature processors
  71. AZ::Render::PostProcessFeatureProcessorInterface* m_postProcessFeatureProcessor = nullptr;
  72. AZ::Render::DirectionalLightFeatureProcessorInterface* m_directionalLightFeatureProcessor = nullptr;
  73. AZ::Render::DepthOfFieldSettingsInterface* m_depthOfFieldSettings = nullptr;
  74. AZ::Render::PostProcessSettingsInterface* m_postProcessSettings = nullptr;
  75. };
  76. } // namespace AtomSampleViewer