PostFxLayerComponentConfig.cpp 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #include <AtomLyIntegration/CommonFeatures/PostProcess/PostFxLayerComponentConfig.h>
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. #include <AzCore/Serialization/EditContext.h>
  11. #include <AtomLyIntegration/CommonFeatures/PostProcess/PostFxLayerCategoriesProviderRequestBus.h>
  12. #include <AzCore/std/sort.h>
  13. namespace AZ
  14. {
  15. namespace Render
  16. {
  17. void PostFxLayerComponentConfig::Reflect(ReflectContext* context)
  18. {
  19. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  20. {
  21. serializeContext->Class<PostFxLayerComponentConfig, ComponentConfig>()
  22. ->Version(2)
  23. ->Field("layerCategory", &PostFxLayerComponentConfig::m_layerCategoryValue)
  24. #define SERIALIZE_CLASS PostFxLayerComponentConfig
  25. #include <Atom/Feature/ParamMacros/StartParamSerializeContext.inl>
  26. #include <Atom/Feature/PostProcess/PostProcessParams.inl>
  27. #include <Atom/Feature/ParamMacros/EndParams.inl>
  28. #undef SERIALIZE_CLASS
  29. ->Field("cameraTags", &PostFxLayerComponentConfig::m_cameraTags)
  30. ->Field("exclusionTags", &PostFxLayerComponentConfig::m_exclusionTags)
  31. ;
  32. }
  33. }
  34. void PostFxLayerComponentConfig::CopySettingsTo(PostProcessSettingsInterface* settings) const
  35. {
  36. if (!settings)
  37. {
  38. return;
  39. }
  40. #define COPY_TARGET settings
  41. #include <Atom/Feature/ParamMacros/StartParamCopySettingsTo.inl>
  42. #include <Atom/Feature/PostProcess/PostProcessParams.inl>
  43. #include <Atom/Feature/ParamMacros/EndParams.inl>
  44. #undef COPY_TARGET
  45. settings->SetLayerCategoryValue(m_layerCategoryValue);
  46. }
  47. AZStd::string PostFxLayerComponentConfig::GetPriorityLabel()
  48. {
  49. auto priorityLayersList = BuildLayerCategories();
  50. // use the first match as the priority label since all labels with the same priority will belong to the same layer
  51. auto it = AZStd::find_if(
  52. priorityLayersList.begin(),
  53. priorityLayersList.end(),
  54. [this](const auto& entry) { return m_layerCategoryValue == entry.first; });
  55. return it == priorityLayersList.end() ? "Priority" : "Priority in " + it->second;
  56. }
  57. AZStd::vector<AZStd::pair<int, AZStd::string>> PostFxLayerComponentConfig::BuildLayerCategories() const
  58. {
  59. // Call the bus to retrieve a list of categories
  60. PostFx::LayerCategoriesMap layerCategories;
  61. PostFxLayerCategoriesProviderRequestBus::Broadcast(&PostFxLayerCategoriesProviderRequests::GetLayerCategories, layerCategories);
  62. AZStd::vector<AZStd::pair<int, AZStd::string>> results;
  63. results.reserve(layerCategories.size());
  64. for (const auto& layer : layerCategories)
  65. {
  66. results.push_back(AZStd::pair<int, AZStd::string>(layer.second, layer.first));
  67. }
  68. AZStd::sort(
  69. results.begin(),
  70. results.end(),
  71. [](auto& left, auto& right) { return left.first < right.first;});
  72. return results;
  73. }
  74. } // namespace Render
  75. } // namespace AZ