PostProcessFeatureProcessor.h 3.9 KB

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