3
0

SsaoComponentController.cpp 7.6 KB

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