DepthOfFieldExampleComponent.h 3.8 KB

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