3
0

DeferredFogComponentController.cpp 7.7 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 <ScreenSpace/DeferredFogComponentController.h>
  11. namespace AZ
  12. {
  13. namespace Render
  14. {
  15. void DeferredFogComponentController::Reflect(ReflectContext* context)
  16. {
  17. DeferredFogComponentConfig::Reflect(context);
  18. if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
  19. {
  20. serializeContext->Class<DeferredFogComponentController>()
  21. ->Version(0)
  22. ->Field("Configuration", &DeferredFogComponentController::m_configuration);
  23. }
  24. if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  25. {
  26. behaviorContext->EBus<DeferredFogRequestsBus>("DeferredFogRequestsBus")
  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 DeferredFogRequestsBus::Events
  31. #define AZ_GFX_COMMON_PARAM(ValueType, Name, MemberName, DefaultValue) \
  32. ->Event("Set" #Name, &PARAM_EVENT_BUS::Set##Name) \
  33. ->Event("Get" #Name, &PARAM_EVENT_BUS::Get##Name) \
  34. ->VirtualProperty(#Name, "Get" #Name, "Set" #Name) \
  35. #include <Atom/Feature/ParamMacros/MapParamCommon.inl>
  36. #include <Atom/Feature/ScreenSpace/DeferredFogParams.inl>
  37. #include <Atom/Feature/ParamMacros/EndParams.inl>
  38. #undef PARAM_EVENT_BUS
  39. ;
  40. }
  41. }
  42. void DeferredFogComponentController::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  43. {
  44. provided.push_back(AZ_CRC_CE("DeferredFogService"));
  45. }
  46. void DeferredFogComponentController::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  47. {
  48. incompatible.push_back(AZ_CRC_CE("DeferredFogService"));
  49. }
  50. void DeferredFogComponentController::GetRequiredServices( [[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& required)
  51. { // In the future deferred fog might be required to be anchored to activation locations
  52. required.push_back(AZ_CRC_CE("PostFXLayerService")); // For aggregated settings, otherwise settings are not updated
  53. }
  54. DeferredFogComponentController::DeferredFogComponentController(const DeferredFogComponentConfig& config)
  55. : m_configuration(config)
  56. {
  57. }
  58. void DeferredFogComponentController::Activate(EntityId entityId)
  59. {
  60. m_entityId = entityId;
  61. PostProcessFeatureProcessorInterface* featureProcessor = RPI::Scene::GetFeatureProcessorForEntity<PostProcessFeatureProcessorInterface>(m_entityId);
  62. if (featureProcessor)
  63. {
  64. m_postProcessInterface = featureProcessor->GetOrCreateSettingsInterface(m_entityId);
  65. if (m_postProcessInterface)
  66. {
  67. m_settingsInterface = m_postProcessInterface->GetOrCreateDeferredFogSettingsInterface();
  68. OnConfigChanged();
  69. }
  70. }
  71. DeferredFogRequestsBus::Handler::BusConnect(m_entityId);
  72. }
  73. void DeferredFogComponentController::Deactivate()
  74. {
  75. DeferredFogRequestsBus::Handler::BusDisconnect(m_entityId);
  76. if (m_postProcessInterface)
  77. {
  78. // turn off the lights before leaving
  79. m_settingsInterface->SetEnabled(false);
  80. m_settingsInterface->OnSettingsChanged();
  81. // Now you can leave
  82. m_postProcessInterface->RemoveDeferredFogSettingsInterface();
  83. }
  84. m_settingsInterface = nullptr;
  85. m_entityId.SetInvalid();
  86. }
  87. void DeferredFogComponentController::SetConfiguration(const DeferredFogComponentConfig& config)
  88. {
  89. m_configuration = config;
  90. OnConfigChanged();
  91. }
  92. const DeferredFogComponentConfig& DeferredFogComponentController::GetConfiguration() const
  93. {
  94. return m_configuration;
  95. }
  96. void DeferredFogComponentController::OnConfigChanged()
  97. {
  98. if (m_settingsInterface)
  99. {
  100. // Set SRG constants
  101. m_configuration.CopySettingsTo(m_settingsInterface);
  102. // Set the shader options bits
  103. m_settingsInterface->SetEnableFogLayerShaderOption(m_configuration.GetEnableFogLayerShaderOption());
  104. m_settingsInterface->SetUseNoiseTextureShaderOption(m_configuration.GetUseNoiseTextureShaderOption());
  105. // Enable / disable the pass
  106. m_settingsInterface->SetEnabled(m_configuration.GetIsEnabled());
  107. m_settingsInterface->OnSettingsChanged();
  108. }
  109. }
  110. // Auto generated getter/setter functions
  111. // The setter functions will set the values on the Atom settings class, then get the value back
  112. // from the settings class to set the local configuration. This is in case the settings class
  113. // applies some custom logic that results in the set value being different from the input
  114. #define AZ_GFX_COMMON_PARAM(ValueType, Name, MemberName, DefaultValue) \
  115. ValueType DeferredFogComponentController::Get##Name() const \
  116. { \
  117. return m_configuration.Get##Name(); \
  118. } \
  119. void DeferredFogComponentController::Set##Name(ValueType val) \
  120. { \
  121. if(m_settingsInterface) \
  122. { \
  123. m_configuration.Set##Name( val ); \
  124. m_settingsInterface->Set##Name(val); \
  125. m_settingsInterface->OnSettingsChanged(); \
  126. } \
  127. else \
  128. { \
  129. m_configuration.Set##Name( val ); \
  130. } \
  131. } \
  132. #include <Atom/Feature/ParamMacros/MapParamCommon.inl>
  133. #include <Atom/Feature/ScreenSpace/DeferredFogParams.inl>
  134. #include <Atom/Feature/ParamMacros/EndParams.inl>
  135. } // namespace Render
  136. } // namespace AZ