ChromaticAberrationComponentController.cpp 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 <PostProcess/ChromaticAberration/ChromaticAberrationComponentController.h>
  9. #include <AzCore/RTTI/BehaviorContext.h>
  10. #include <Atom/RPI.Public/Scene.h>
  11. namespace AZ
  12. {
  13. namespace Render
  14. {
  15. void ChromaticAberrationComponentController::Reflect(ReflectContext* context)
  16. {
  17. ChromaticAberrationComponentConfig::Reflect(context);
  18. if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
  19. {
  20. serializeContext->Class<ChromaticAberrationComponentController>()
  21. ->Version(0)
  22. ->Field("Configuration", &ChromaticAberrationComponentController::m_configuration);
  23. }
  24. if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  25. {
  26. behaviorContext->EBus<ChromaticAberrationRequestBus>("ChromaticAberrationRequestBus")
  27. ->Attribute(AZ::Script::Attributes::Module, "render")
  28. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
  29. // Auto-gen behavior context...
  30. #define PARAM_EVENT_BUS ChromaticAberrationRequestBus::Events
  31. #include <Atom/Feature/ParamMacros/StartParamBehaviorContext.inl>
  32. #include <Atom/Feature/PostProcess/ChromaticAberration/ChromaticAberrationParams.inl>
  33. #include <Atom/Feature/ParamMacros/EndParams.inl>
  34. #undef PARAM_EVENT_BUS
  35. ;
  36. }
  37. }
  38. void ChromaticAberrationComponentController::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  39. {
  40. provided.push_back(AZ_CRC_CE("ChromaticAberrationService"));
  41. }
  42. void ChromaticAberrationComponentController::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  43. {
  44. incompatible.push_back(AZ_CRC_CE("ChromaticAberrationService"));
  45. }
  46. void ChromaticAberrationComponentController::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  47. {
  48. required.push_back(AZ_CRC_CE("PostFXLayerService"));
  49. }
  50. ChromaticAberrationComponentController::ChromaticAberrationComponentController(const ChromaticAberrationComponentConfig& config)
  51. : m_configuration(config)
  52. {
  53. }
  54. void ChromaticAberrationComponentController::Activate(EntityId entityId)
  55. {
  56. m_entityId = entityId;
  57. PostProcessFeatureProcessorInterface* fp =
  58. RPI::Scene::GetFeatureProcessorForEntity<PostProcessFeatureProcessorInterface>(m_entityId);
  59. if (fp)
  60. {
  61. m_postProcessInterface = fp->GetOrCreateSettingsInterface(m_entityId);
  62. if (m_postProcessInterface)
  63. {
  64. m_settingsInterface = m_postProcessInterface->GetOrCreateChromaticAberrationSettingsInterface();
  65. OnConfigChanged();
  66. }
  67. }
  68. ChromaticAberrationRequestBus::Handler::BusConnect(m_entityId);
  69. }
  70. void ChromaticAberrationComponentController::Deactivate()
  71. {
  72. ChromaticAberrationRequestBus::Handler::BusDisconnect(m_entityId);
  73. if (m_postProcessInterface)
  74. {
  75. m_postProcessInterface->RemoveChromaticAberrationSettingsInterface();
  76. }
  77. m_postProcessInterface = nullptr;
  78. m_settingsInterface = nullptr;
  79. m_entityId.SetInvalid();
  80. }
  81. // Getters & Setters...
  82. void ChromaticAberrationComponentController::SetConfiguration(const ChromaticAberrationComponentConfig& config)
  83. {
  84. m_configuration = config;
  85. OnConfigChanged();
  86. }
  87. const ChromaticAberrationComponentConfig& ChromaticAberrationComponentController::GetConfiguration() const
  88. {
  89. return m_configuration;
  90. }
  91. void ChromaticAberrationComponentController::OnConfigChanged()
  92. {
  93. if (m_settingsInterface)
  94. {
  95. m_configuration.CopySettingsTo(m_settingsInterface);
  96. m_settingsInterface->OnConfigChanged();
  97. }
  98. }
  99. // Auto-gen getter/setter function definitions...
  100. // The setter functions will set the values on the Atom settings class, then get the value back
  101. // from the settings class to set the local configuration. This is in case the settings class
  102. // applies some custom logic that results in the set value being different from the input
  103. #define AZ_GFX_COMMON_PARAM(ValueType, Name, MemberName, DefaultValue) \
  104. ValueType ChromaticAberrationComponentController::Get##Name() const \
  105. { \
  106. return m_configuration.MemberName; \
  107. } \
  108. void ChromaticAberrationComponentController::Set##Name(ValueType val) \
  109. { \
  110. if (m_settingsInterface) \
  111. { \
  112. m_settingsInterface->Set##Name(val); \
  113. m_settingsInterface->OnConfigChanged(); \
  114. m_configuration.MemberName = m_settingsInterface->Get##Name(); \
  115. } \
  116. else \
  117. { \
  118. m_configuration.MemberName = val; \
  119. } \
  120. }
  121. #define AZ_GFX_COMMON_OVERRIDE(ValueType, Name, MemberName, OverrideValueType) \
  122. OverrideValueType ChromaticAberrationComponentController::Get##Name##Override() const \
  123. { \
  124. return m_configuration.MemberName##Override; \
  125. } \
  126. void ChromaticAberrationComponentController::Set##Name##Override(OverrideValueType val) \
  127. { \
  128. m_configuration.MemberName##Override = val; \
  129. if (m_settingsInterface) \
  130. { \
  131. m_settingsInterface->Set##Name##Override(val); \
  132. m_settingsInterface->OnConfigChanged(); \
  133. } \
  134. }
  135. #include <Atom/Feature/ParamMacros/MapAllCommon.inl>
  136. #include <Atom/Feature/PostProcess/ChromaticAberration/ChromaticAberrationParams.inl>
  137. #include <Atom/Feature/ParamMacros/EndParams.inl>
  138. } // namespace Render
  139. } // namespace AZ