3
0

PostProcessFeatureProcessor.h 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 <PostProcess/PostProcessSettings.h>
  10. #include <Atom/Feature/PostProcess/PostProcessFeatureProcessorInterface.h>
  11. #include <Atom/RPI.Public/Shader/ShaderResourceGroup.h>
  12. #include <Atom/RPI.Public/Base.h>
  13. #include <AtomCore/std/containers/vector_set.h>
  14. #include <AzCore/std/chrono/chrono.h>
  15. namespace AZ
  16. {
  17. namespace Render
  18. {
  19. //! Feature processor for owning and managing post process settings
  20. class PostProcessFeatureProcessor final
  21. : public PostProcessFeatureProcessorInterface
  22. {
  23. public:
  24. AZ_CLASS_ALLOCATOR(PostProcessFeatureProcessor, AZ::SystemAllocator)
  25. AZ_RTTI(AZ::Render::PostProcessFeatureProcessor, "{A6A8357C-5A34-4297-B4DD-A1FB6556CE3E}", AZ::Render::PostProcessFeatureProcessorInterface);
  26. static void Reflect(AZ::ReflectContext* context);
  27. PostProcessFeatureProcessor() = default;
  28. virtual ~PostProcessFeatureProcessor() = default;
  29. //! FeatureProcessor overrides...
  30. void Activate() override;
  31. void Deactivate() override;
  32. void Simulate(const FeatureProcessor::SimulatePacket& packet) override;
  33. //! PostProcessFeatureProcessorInterface...
  34. PostProcessSettingsInterface* GetSettingsInterface(EntityId entityId) override;
  35. PostProcessSettingsInterface* GetOrCreateSettingsInterface(EntityId entityId) override;
  36. void RemoveSettingsInterface(EntityId entityId) override;
  37. void OnPostProcessSettingsChanged() override;
  38. PostProcessSettings* GetLevelSettingsFromView(AZ::RPI::ViewPtr view);
  39. void SetViewAlias(const AZ::RPI::ViewPtr sourceView, const AZ::RPI::ViewPtr targetView);
  40. void RemoveViewAlias(const AZ::RPI::ViewPtr sourceView);
  41. private:
  42. PostProcessFeatureProcessor(const PostProcessFeatureProcessor&) = delete;
  43. void UpdateTime();
  44. // Sorts all post processing settings into buckets based on category (level,
  45. void SortPostProcessSettings();
  46. // Aggregates all level settings into a single level setting based their priorities and override settings
  47. void AggregateLevelSettings();
  48. void RemoveOutdatedViewSettings(const AZStd::vector_set<const RPI::View*>& activeViews);
  49. // Members...
  50. static constexpr const char* FeatureProcessorName = "PostProcessFeatureProcessor";
  51. struct EntitySettingsEntry
  52. {
  53. EntityId m_entityId;
  54. AZStd::unique_ptr<PostProcessSettings> m_postProcessSettings = nullptr;
  55. };
  56. // List of all owned post process settings with corresponding entity ID
  57. AZStd::vector<EntitySettingsEntry> m_settings;
  58. // Settings sorted by category and then by priority
  59. AZStd::vector<PostProcessSettings*> m_sortedFrameSettings;
  60. // A blended aggregate of all the level settings based on each level setting's priority and override values
  61. AZStd::unique_ptr<PostProcessSettings> m_globalAggregateLevelSettings = nullptr;
  62. // Whether owned post process settings have been changed.
  63. bool m_settingsChanged = true;
  64. // Time...
  65. AZStd::chrono::steady_clock::time_point m_currentTime;
  66. float m_deltaTime;
  67. // Each camera/view will have its own PostProcessSettings
  68. AZStd::unordered_map<AZ::RPI::View*, PostProcessSettings> m_blendedPerViewSettings;
  69. // This is used for mimicking a postfx setting of a different view
  70. AZStd::unordered_map<AZ::RPI::View*, AZ::RPI::View*> m_viewAliasMap;
  71. };
  72. } // namespace Render
  73. } // namespace AZ