LookModificationComponentController.cpp 8.1 KB

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