3
0

DisplayMapperComponentController.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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 "AtomLyIntegration/CommonFeatures/CoreLights/AreaLightBus.h"
  9. #include <AzCore/RTTI/BehaviorContext.h>
  10. #include <Atom/RPI.Public/Scene.h>
  11. #include <PostProcess/DisplayMapper/DisplayMapperComponentController.h>
  12. #include <Atom/Feature/ACES/AcesDisplayMapperFeatureProcessor.h>
  13. #include <Atom/Feature/DisplayMapper/DisplayMapperConfigurationDescriptor.h>
  14. namespace AZ
  15. {
  16. namespace Render
  17. {
  18. void DisplayMapperComponentController::Reflect(ReflectContext* context)
  19. {
  20. DisplayMapperComponentConfig::Reflect(context);
  21. if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
  22. {
  23. serializeContext->Class<DisplayMapperComponentController>()
  24. ->Version(0)
  25. ->Field("Configuration", &DisplayMapperComponentController::m_configuration);
  26. }
  27. if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  28. {
  29. behaviorContext->EBus<DisplayMapperComponentRequestBus>("DisplayMapperComponentRequestBus")
  30. ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
  31. ->Attribute(AZ::Script::Attributes::Category, "render")
  32. ->Attribute(AZ::Script::Attributes::Module, "render")
  33. // LoadPreset
  34. ->Event("LoadPreset", &DisplayMapperComponentRequestBus::Events::LoadPreset)
  35. // DisplayMapperOperationType
  36. ->Event("SetDisplayMapperOperationType", &DisplayMapperComponentRequestBus::Events::SetDisplayMapperOperationType)
  37. ->Event("GetDisplayMapperOperationType", &DisplayMapperComponentRequestBus::Events::GetDisplayMapperOperationType)
  38. ->VirtualProperty("DisplayMapperOperationType", "GetDisplayMapperOperationType", "SetDisplayMapperOperationType")
  39. // AcesParameterOverrides
  40. ->Event("SetAcesParameterOverrides", &DisplayMapperComponentRequestBus::Events::SetAcesParameterOverrides)
  41. ->Event("GetAcesParameterOverrides", &DisplayMapperComponentRequestBus::Events::GetAcesParameterOverrides)
  42. ->VirtualProperty("AcesParameterOverrides", "GetAcesParameterOverrides", "SetAcesParameterOverrides")
  43. // OverrideAcesParameters
  44. ->Event("SetOverrideAcesParameters", &DisplayMapperComponentRequestBus::Events::SetOverrideAcesParameters)
  45. ->Event("GetOverrideAcesParameters", &DisplayMapperComponentRequestBus::Events::GetOverrideAcesParameters)
  46. ->VirtualProperty("OverrideAcesParameters", "GetOverrideAcesParameters", "SetOverrideAcesParameters")
  47. // AlterSurround
  48. ->Event("SetAlterSurround", &DisplayMapperComponentRequestBus::Events::SetAlterSurround)
  49. ->Event("GetAlterSurround", &DisplayMapperComponentRequestBus::Events::GetAlterSurround)
  50. ->VirtualProperty("AlterSurround", "GetAlterSurround", "SetAlterSurround")
  51. // ApplyDesaturation
  52. ->Event("SetApplyDesaturation", &DisplayMapperComponentRequestBus::Events::SetApplyDesaturation)
  53. ->Event("GetApplyDesaturation", &DisplayMapperComponentRequestBus::Events::GetApplyDesaturation)
  54. ->VirtualProperty("ApplyDesaturation", "GetApplyDesaturation", "SetApplyDesaturation")
  55. // ApplyCATD60toD65
  56. ->Event("SetApplyCATD60toD65", &DisplayMapperComponentRequestBus::Events::SetApplyCATD60toD65)
  57. ->Event("GetApplyCATD60toD65", &DisplayMapperComponentRequestBus::Events::GetApplyCATD60toD65)
  58. ->VirtualProperty("ApplyCATD60toD65", "GetApplyCATD60toD65", "SetApplyCATD60toD65")
  59. // CinemaLimitsBlack
  60. ->Event("SetCinemaLimitsBlack", &DisplayMapperComponentRequestBus::Events::SetCinemaLimitsBlack)
  61. ->Event("GetCinemaLimitsBlack", &DisplayMapperComponentRequestBus::Events::GetCinemaLimitsBlack)
  62. ->VirtualProperty("CinemaLimitsBlack", "GetCinemaLimitsBlack", "SetCinemaLimitsBlack")
  63. // CinemaLimitsWhite
  64. ->Event("SetCinemaLimitsWhite", &DisplayMapperComponentRequestBus::Events::SetCinemaLimitsWhite)
  65. ->Event("GetCinemaLimitsWhite", &DisplayMapperComponentRequestBus::Events::GetCinemaLimitsWhite)
  66. ->VirtualProperty("CinemaLimitsWhite", "GetCinemaLimitsWhite", "SetCinemaLimitsWhite")
  67. // MinPoint
  68. ->Event("SetMinPoint", &DisplayMapperComponentRequestBus::Events::SetMinPoint)
  69. ->Event("GetMinPoint", &DisplayMapperComponentRequestBus::Events::GetMinPoint)
  70. ->VirtualProperty("MinPoint", "GetMinPoint", "SetMinPoint")
  71. // MidPoint
  72. ->Event("SetMidPoint", &DisplayMapperComponentRequestBus::Events::SetMidPoint)
  73. ->Event("GetMidPoint", &DisplayMapperComponentRequestBus::Events::GetMidPoint)
  74. ->VirtualProperty("MidPoint", "GetMidPoint", "SetMidPoint")
  75. // MaxPoint
  76. ->Event("SetMaxPoint", &DisplayMapperComponentRequestBus::Events::SetMaxPoint)
  77. ->Event("GetMaxPoint", &DisplayMapperComponentRequestBus::Events::GetMaxPoint)
  78. ->VirtualProperty("MaxPoint", "GetMaxPoint", "SetMaxPoint")
  79. // SurroundGamma
  80. ->Event("SetSurroundGamma", &DisplayMapperComponentRequestBus::Events::SetSurroundGamma)
  81. ->Event("GetSurroundGamma", &DisplayMapperComponentRequestBus::Events::GetSurroundGamma)
  82. ->VirtualProperty("SurroundGamma", "GetSurroundGamma", "SetSurroundGamma")
  83. // Gamma
  84. ->Event("SetGamma", &DisplayMapperComponentRequestBus::Events::SetGamma)
  85. ->Event("GetGamma", &DisplayMapperComponentRequestBus::Events::GetGamma)
  86. ->VirtualProperty("Gamma", "GetGamma", "SetGamma")
  87. ;
  88. }
  89. }
  90. void DisplayMapperComponentController::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  91. {
  92. provided.push_back(AZ_CRC("ToneMapperService", 0xb8f814e8));
  93. }
  94. void DisplayMapperComponentController::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  95. {
  96. incompatible.push_back(AZ_CRC("ToneMapperService", 0xb8f814e8));
  97. }
  98. void DisplayMapperComponentController::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  99. {
  100. AZ_UNUSED(required);
  101. }
  102. DisplayMapperComponentController::DisplayMapperComponentController(const DisplayMapperComponentConfig& config)
  103. : m_configuration(config)
  104. {
  105. }
  106. void DisplayMapperComponentController::Activate(EntityId entityId)
  107. {
  108. m_entityId = entityId;
  109. DisplayMapperComponentRequestBus::Handler::BusConnect(m_entityId);
  110. OnConfigChanged();
  111. }
  112. void DisplayMapperComponentController::Deactivate()
  113. {
  114. DisplayMapperFeatureProcessorInterface* fp =
  115. AZ::RPI::Scene::GetFeatureProcessorForEntity<DisplayMapperFeatureProcessorInterface>(m_entityId);
  116. if (fp)
  117. {
  118. fp->UnregisterDisplayMapperConfiguration();
  119. }
  120. DisplayMapperComponentRequestBus::Handler::BusDisconnect(m_entityId);
  121. m_postProcessInterface = nullptr;
  122. m_entityId.SetInvalid();
  123. }
  124. void DisplayMapperComponentController::SetConfiguration(const DisplayMapperComponentConfig& config)
  125. {
  126. m_configuration = config;
  127. OnConfigChanged();
  128. }
  129. const DisplayMapperComponentConfig& DisplayMapperComponentController::GetConfiguration() const
  130. {
  131. return m_configuration;
  132. }
  133. void DisplayMapperComponentController::LoadPreset(OutputDeviceTransformType preset)
  134. {
  135. AcesParameterOverrides propertyOverrides;
  136. propertyOverrides.m_preset = preset;
  137. propertyOverrides.m_overrideDefaults = true;
  138. propertyOverrides.LoadPreset();
  139. SetAcesParameterOverrides(propertyOverrides);
  140. }
  141. void DisplayMapperComponentController::SetDisplayMapperOperationType(DisplayMapperOperationType displayMapperOperationType)
  142. {
  143. if (m_configuration.m_displayMapperOperation != displayMapperOperationType)
  144. {
  145. m_configuration.m_displayMapperOperation = displayMapperOperationType;
  146. OnConfigChanged();
  147. DisplayMapperComponentNotificationBus::Broadcast(
  148. &DisplayMapperComponentNotificationBus::Handler::OnDisplayMapperOperationTypeUpdated,
  149. m_configuration.m_displayMapperOperation);
  150. }
  151. }
  152. DisplayMapperOperationType DisplayMapperComponentController::GetDisplayMapperOperationType() const
  153. {
  154. return m_configuration.m_displayMapperOperation;
  155. }
  156. void DisplayMapperComponentController::SetAcesParameterOverrides(const AcesParameterOverrides& parameterOverrides)
  157. {
  158. m_configuration.m_acesParameterOverrides = parameterOverrides;
  159. if (m_configuration.m_displayMapperOperation == DisplayMapperOperationType::Aces)
  160. {
  161. OnConfigChanged();
  162. }
  163. DisplayMapperComponentNotificationBus::Broadcast(
  164. &DisplayMapperComponentNotificationBus::Handler::OnAcesParameterOverridesUpdated,
  165. m_configuration.m_acesParameterOverrides);
  166. }
  167. const AcesParameterOverrides& DisplayMapperComponentController::GetAcesParameterOverrides() const
  168. {
  169. return m_configuration.m_acesParameterOverrides;
  170. }
  171. void DisplayMapperComponentController::SetOverrideAcesParameters(bool value)
  172. {
  173. if (m_configuration.m_acesParameterOverrides.m_overrideDefaults == value)
  174. {
  175. return; // prevents flickering when set via TrackView
  176. }
  177. m_configuration.m_acesParameterOverrides.m_overrideDefaults = value;
  178. if (m_configuration.m_displayMapperOperation == DisplayMapperOperationType::Aces)
  179. {
  180. OnConfigChanged();
  181. }
  182. }
  183. bool DisplayMapperComponentController::GetOverrideAcesParameters() const
  184. {
  185. return m_configuration.m_acesParameterOverrides.m_overrideDefaults;
  186. }
  187. void DisplayMapperComponentController::SetAlterSurround(bool value)
  188. {
  189. if (m_configuration.m_acesParameterOverrides.m_alterSurround != value)
  190. {
  191. return; // prevents flickering when set via TrackView
  192. }
  193. m_configuration.m_acesParameterOverrides.m_alterSurround = value;
  194. if (m_configuration.m_displayMapperOperation == DisplayMapperOperationType::Aces)
  195. {
  196. OnConfigChanged();
  197. }
  198. }
  199. bool DisplayMapperComponentController::GetAlterSurround() const
  200. {
  201. return m_configuration.m_acesParameterOverrides.m_alterSurround;
  202. }
  203. void DisplayMapperComponentController::SetApplyDesaturation(bool value)
  204. {
  205. if (m_configuration.m_acesParameterOverrides.m_applyDesaturation != value)
  206. {
  207. return; // prevents flickering when set via TrackView
  208. }
  209. m_configuration.m_acesParameterOverrides.m_applyDesaturation = value;
  210. if (m_configuration.m_displayMapperOperation == DisplayMapperOperationType::Aces)
  211. {
  212. OnConfigChanged();
  213. }
  214. }
  215. bool DisplayMapperComponentController::GetApplyDesaturation() const
  216. {
  217. return m_configuration.m_acesParameterOverrides.m_applyDesaturation;
  218. }
  219. void DisplayMapperComponentController::SetApplyCATD60toD65(bool value)
  220. {
  221. if (m_configuration.m_acesParameterOverrides.m_applyCATD60toD65 != value)
  222. {
  223. return; // prevents flickering when set via TrackView
  224. }
  225. m_configuration.m_acesParameterOverrides.m_applyCATD60toD65 = value;
  226. if (m_configuration.m_displayMapperOperation == DisplayMapperOperationType::Aces)
  227. {
  228. OnConfigChanged();
  229. }
  230. }
  231. bool DisplayMapperComponentController::GetApplyCATD60toD65() const
  232. {
  233. return m_configuration.m_acesParameterOverrides.m_applyCATD60toD65;
  234. }
  235. void DisplayMapperComponentController::SetCinemaLimitsBlack(float value)
  236. {
  237. m_configuration.m_acesParameterOverrides.m_cinemaLimitsBlack = value;
  238. if (m_configuration.m_displayMapperOperation == DisplayMapperOperationType::Aces)
  239. {
  240. OnConfigChanged();
  241. }
  242. }
  243. float DisplayMapperComponentController::GetCinemaLimitsBlack() const
  244. {
  245. return m_configuration.m_acesParameterOverrides.m_cinemaLimitsBlack;
  246. }
  247. void DisplayMapperComponentController::SetCinemaLimitsWhite(float value)
  248. {
  249. m_configuration.m_acesParameterOverrides.m_cinemaLimitsWhite = value;
  250. if (m_configuration.m_displayMapperOperation == DisplayMapperOperationType::Aces)
  251. {
  252. OnConfigChanged();
  253. }
  254. }
  255. float DisplayMapperComponentController::GetCinemaLimitsWhite() const
  256. {
  257. return m_configuration.m_acesParameterOverrides.m_cinemaLimitsWhite;
  258. }
  259. void DisplayMapperComponentController::SetMinPoint(float value)
  260. {
  261. m_configuration.m_acesParameterOverrides.m_minPoint = value;
  262. if (m_configuration.m_displayMapperOperation == DisplayMapperOperationType::Aces)
  263. {
  264. OnConfigChanged();
  265. }
  266. }
  267. float DisplayMapperComponentController::GetMinPoint() const
  268. {
  269. return m_configuration.m_acesParameterOverrides.m_minPoint;
  270. }
  271. void DisplayMapperComponentController::SetMidPoint(float value)
  272. {
  273. m_configuration.m_acesParameterOverrides.m_midPoint = value;
  274. if (m_configuration.m_displayMapperOperation == DisplayMapperOperationType::Aces)
  275. {
  276. OnConfigChanged();
  277. }
  278. }
  279. float DisplayMapperComponentController::GetMidPoint() const
  280. {
  281. return m_configuration.m_acesParameterOverrides.m_midPoint;
  282. }
  283. void DisplayMapperComponentController::SetMaxPoint(float value)
  284. {
  285. m_configuration.m_acesParameterOverrides.m_maxPoint = value;
  286. if (m_configuration.m_displayMapperOperation == DisplayMapperOperationType::Aces)
  287. {
  288. OnConfigChanged();
  289. }
  290. }
  291. float DisplayMapperComponentController::GetMaxPoint() const
  292. {
  293. return m_configuration.m_acesParameterOverrides.m_maxPoint;
  294. }
  295. void DisplayMapperComponentController::SetSurroundGamma(float value)
  296. {
  297. m_configuration.m_acesParameterOverrides.m_surroundGamma = value;
  298. if (m_configuration.m_displayMapperOperation == DisplayMapperOperationType::Aces)
  299. {
  300. OnConfigChanged();
  301. }
  302. }
  303. float DisplayMapperComponentController::GetSurroundGamma() const
  304. {
  305. return m_configuration.m_acesParameterOverrides.m_surroundGamma;
  306. }
  307. void DisplayMapperComponentController::SetGamma(float value)
  308. {
  309. m_configuration.m_acesParameterOverrides.m_gamma = value;
  310. if (m_configuration.m_displayMapperOperation == DisplayMapperOperationType::Aces)
  311. {
  312. OnConfigChanged();
  313. }
  314. }
  315. float DisplayMapperComponentController::GetGamma() const
  316. {
  317. return m_configuration.m_acesParameterOverrides.m_gamma;
  318. }
  319. void DisplayMapperComponentController::OnConfigChanged()
  320. {
  321. // Register the configuration with the AcesDisplayMapperFeatureProcessor for this scene.
  322. DisplayMapperFeatureProcessorInterface* fp = AZ::RPI::Scene::GetFeatureProcessorForEntity<DisplayMapperFeatureProcessorInterface>(m_entityId);
  323. DisplayMapperConfigurationDescriptor desc;
  324. desc.m_operationType = m_configuration.m_displayMapperOperation;
  325. desc.m_ldrGradingLutEnabled = m_configuration.m_ldrColorGradingLutEnabled;
  326. desc.m_ldrColorGradingLut = m_configuration.m_ldrColorGradingLut;
  327. desc.m_acesParameterOverrides = m_configuration.m_acesParameterOverrides;
  328. fp->RegisterDisplayMapperConfiguration(desc);
  329. }
  330. } // namespace Render
  331. } // namespace AZ