3
0

DepthOfFieldComponentController.cpp 8.2 KB

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