DiffuseProbeGridComponentController.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  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 <Components/DiffuseProbeGridComponentController.h>
  9. #include <Components/DiffuseProbeGridComponentConstants.h>
  10. #include <Atom/RPI.Public/Model/Model.h>
  11. #include <Atom/RPI.Public/Image/StreamingImage.h>
  12. #include <Atom/RPI.Public/Scene.h>
  13. #include <AzCore/Asset/AssetManager.h>
  14. #include <AzCore/Asset/AssetManagerBus.h>
  15. #include <AzCore/Asset/AssetSerializer.h>
  16. #include <AzCore/Serialization/SerializeContext.h>
  17. #include <AzFramework/Entity/EntityContextBus.h>
  18. #include <AzFramework/Entity/EntityContext.h>
  19. #include <AzFramework/Scene/Scene.h>
  20. #include <AzFramework/Scene/SceneSystemInterface.h>
  21. #include <AzCore/RTTI/BehaviorContext.h>
  22. #include <DiffuseProbeGrid_Traits_Platform.h>
  23. namespace AZ
  24. {
  25. namespace Render
  26. {
  27. void DiffuseProbeGridComponentConfig::Reflect(ReflectContext* context)
  28. {
  29. if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
  30. {
  31. serializeContext->Class<DiffuseProbeGridComponentConfig>()
  32. ->Version(6) // Added EmissiveMultiplier
  33. ->Field("ProbeSpacing", &DiffuseProbeGridComponentConfig::m_probeSpacing)
  34. ->Field("Extents", &DiffuseProbeGridComponentConfig::m_extents)
  35. ->Field("AmbientMultiplier", &DiffuseProbeGridComponentConfig::m_ambientMultiplier)
  36. ->Field("ViewBias", &DiffuseProbeGridComponentConfig::m_viewBias)
  37. ->Field("NormalBias", &DiffuseProbeGridComponentConfig::m_normalBias)
  38. ->Field("NumRaysPerProbe", &DiffuseProbeGridComponentConfig::m_numRaysPerProbe)
  39. ->Field("Scrolling", &DiffuseProbeGridComponentConfig::m_scrolling)
  40. ->Field("EdgeBlendIbl", &DiffuseProbeGridComponentConfig::m_edgeBlendIbl)
  41. ->Field("FrameUpdateCount", &DiffuseProbeGridComponentConfig::m_frameUpdateCount)
  42. ->Field("TransparencyMode", &DiffuseProbeGridComponentConfig::m_transparencyMode)
  43. ->Field("EmissiveMultiplier", &DiffuseProbeGridComponentConfig::m_emissiveMultiplier)
  44. ->Field("EditorMode", &DiffuseProbeGridComponentConfig::m_editorMode)
  45. ->Field("RuntimeMode", &DiffuseProbeGridComponentConfig::m_runtimeMode)
  46. ->Field("BakedIrradianceTextureRelativePath", &DiffuseProbeGridComponentConfig::m_bakedIrradianceTextureRelativePath)
  47. ->Field("BakedDistanceTextureRelativePath", &DiffuseProbeGridComponentConfig::m_bakedDistanceTextureRelativePath)
  48. ->Field("BakedProbeDataTextureRelativePath", &DiffuseProbeGridComponentConfig::m_bakedProbeDataTextureRelativePath)
  49. ->Field("BakedIrradianceTextureAsset", &DiffuseProbeGridComponentConfig::m_bakedIrradianceTextureAsset)
  50. ->Field("BakedDistanceTextureAsset", &DiffuseProbeGridComponentConfig::m_bakedDistanceTextureAsset)
  51. ->Field("BakedProbeDataTextureAsset", &DiffuseProbeGridComponentConfig::m_bakedProbeDataTextureAsset)
  52. ->Field("VisualizationEnabled", &DiffuseProbeGridComponentConfig::m_visualizationEnabled)
  53. ->Field("VisualizationShowInactiveProbes", &DiffuseProbeGridComponentConfig::m_visualizationShowInactiveProbes)
  54. ->Field("VisualizationSphereRadius", &DiffuseProbeGridComponentConfig::m_visualizationSphereRadius)
  55. ;
  56. }
  57. }
  58. void DiffuseProbeGridComponentController::Reflect(ReflectContext* context)
  59. {
  60. DiffuseProbeGridComponentConfig::Reflect(context);
  61. if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
  62. {
  63. serializeContext->Class<DiffuseProbeGridComponentController>()
  64. ->Version(0)
  65. ->Field("Configuration", &DiffuseProbeGridComponentController::m_configuration);
  66. }
  67. }
  68. void DiffuseProbeGridComponentController::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
  69. {
  70. dependent.push_back(AZ_CRC_CE("TransformService"));
  71. }
  72. void DiffuseProbeGridComponentController::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  73. {
  74. provided.push_back(AZ_CRC_CE("DiffuseProbeGridService"));
  75. }
  76. void DiffuseProbeGridComponentController::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  77. {
  78. incompatible.push_back(AZ_CRC_CE("DiffuseProbeGridService"));
  79. incompatible.push_back(AZ_CRC_CE("NonUniformScaleService"));
  80. }
  81. void DiffuseProbeGridComponentController::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  82. {
  83. required.push_back(AZ_CRC_CE("BoxShapeService"));
  84. required.push_back(AZ_CRC_CE("TransformService"));
  85. }
  86. DiffuseProbeGridComponentController::DiffuseProbeGridComponentController(const DiffuseProbeGridComponentConfig& config)
  87. : m_configuration(config)
  88. {
  89. }
  90. void DiffuseProbeGridComponentController::Activate(AZ::EntityId entityId)
  91. {
  92. if (!AZ_TRAIT_DIFFUSE_GI_PASSES_SUPPORTED)
  93. {
  94. // GI is not supported on this platform
  95. return;
  96. }
  97. m_entityId = entityId;
  98. TransformNotificationBus::Handler::BusConnect(m_entityId);
  99. m_featureProcessor = RPI::Scene::GetFeatureProcessorForEntity<DiffuseProbeGridFeatureProcessorInterface>(entityId);
  100. AZ_Assert(m_featureProcessor, "DiffuseProbeGridComponentController was unable to find a DiffuseProbeGridFeatureProcessor on the EntityContext provided.");
  101. m_transformInterface = TransformBus::FindFirstHandler(entityId);
  102. AZ_Assert(m_transformInterface, "Unable to attach to a TransformBus handler");
  103. if (!m_transformInterface)
  104. {
  105. return;
  106. }
  107. LmbrCentral::ShapeComponentNotificationsBus::Handler::BusConnect(m_entityId);
  108. m_shapeBus = LmbrCentral::ShapeComponentRequestsBus::FindFirstHandler(m_entityId);
  109. AZ_Assert(m_shapeBus, "DiffuseProbeGridComponentController was unable to find ShapeComponentNotificationsBus");
  110. m_boxShapeInterface = LmbrCentral::BoxShapeComponentRequestsBus::FindFirstHandler(m_entityId);
  111. AZ_Assert(m_boxShapeInterface, "DiffuseProbeGridComponentController was unable to find box shape component");
  112. // special handling is required if this component is being cloned in the editor:
  113. // check to see if the baked textures are already referenced by another DiffuseProbeGrid
  114. if (m_featureProcessor->AreBakedTexturesReferenced(
  115. m_configuration.m_bakedIrradianceTextureRelativePath,
  116. m_configuration.m_bakedDistanceTextureRelativePath,
  117. m_configuration.m_bakedProbeDataTextureRelativePath))
  118. {
  119. // clear the baked texture paths and assets, since they belong to the original entity (not the clone)
  120. m_configuration.m_bakedIrradianceTextureRelativePath.clear();
  121. m_configuration.m_bakedDistanceTextureRelativePath.clear();
  122. m_configuration.m_bakedProbeDataTextureRelativePath.clear();
  123. m_configuration.m_bakedIrradianceTextureAsset.Reset();
  124. m_configuration.m_bakedDistanceTextureAsset.Reset();
  125. m_configuration.m_bakedProbeDataTextureAsset.Reset();
  126. }
  127. // add this diffuse probe grid to the feature processor
  128. const AZ::Transform& transform = m_transformInterface->GetWorldTM();
  129. m_handle = m_featureProcessor->AddProbeGrid(
  130. ComputeOverallTransform(transform), m_configuration.m_extents, m_configuration.m_probeSpacing);
  131. m_featureProcessor->SetAmbientMultiplier(m_handle, m_configuration.m_ambientMultiplier);
  132. m_featureProcessor->SetViewBias(m_handle, m_configuration.m_viewBias);
  133. m_featureProcessor->SetNormalBias(m_handle, m_configuration.m_normalBias);
  134. m_featureProcessor->SetNumRaysPerProbe(m_handle, m_configuration.m_numRaysPerProbe);
  135. m_featureProcessor->SetScrolling(m_handle, m_configuration.m_scrolling);
  136. m_featureProcessor->SetEdgeBlendIbl(m_handle, m_configuration.m_edgeBlendIbl);
  137. m_featureProcessor->SetFrameUpdateCount(m_handle, m_configuration.m_frameUpdateCount);
  138. m_featureProcessor->SetTransparencyMode(m_handle, m_configuration.m_transparencyMode);
  139. m_featureProcessor->SetEmissiveMultiplier(m_handle, m_configuration.m_emissiveMultiplier);
  140. m_featureProcessor->SetVisualizationEnabled(m_handle, m_configuration.m_visualizationEnabled);
  141. m_featureProcessor->SetVisualizationShowInactiveProbes(m_handle, m_configuration.m_visualizationShowInactiveProbes);
  142. m_featureProcessor->SetVisualizationSphereRadius(m_handle, m_configuration.m_visualizationSphereRadius);
  143. // load the baked texture assets, but only if they are all valid
  144. if (m_configuration.m_bakedIrradianceTextureAsset.GetId().IsValid() &&
  145. m_configuration.m_bakedDistanceTextureAsset.GetId().IsValid() &&
  146. m_configuration.m_bakedProbeDataTextureAsset.GetId().IsValid())
  147. {
  148. Data::AssetBus::MultiHandler::BusConnect(m_configuration.m_bakedIrradianceTextureAsset.GetId());
  149. Data::AssetBus::MultiHandler::BusConnect(m_configuration.m_bakedDistanceTextureAsset.GetId());
  150. Data::AssetBus::MultiHandler::BusConnect(m_configuration.m_bakedProbeDataTextureAsset.GetId());
  151. m_configuration.m_bakedIrradianceTextureAsset.QueueLoad();
  152. m_configuration.m_bakedDistanceTextureAsset.QueueLoad();
  153. m_configuration.m_bakedProbeDataTextureAsset.QueueLoad();
  154. }
  155. else if (m_configuration.m_runtimeMode == DiffuseProbeGridMode::Baked ||
  156. m_configuration.m_runtimeMode == DiffuseProbeGridMode::AutoSelect ||
  157. m_configuration.m_editorMode == DiffuseProbeGridMode::Baked ||
  158. m_configuration.m_editorMode == DiffuseProbeGridMode::AutoSelect)
  159. {
  160. AZ_Error("DiffuseProbeGrid", false, "DiffuseProbeGrid mode is set to Baked or Auto-Select, but it does not have baked texture assets. Please re-bake this DiffuseProbeGrid.");
  161. }
  162. m_featureProcessor->SetMode(m_handle, m_configuration.m_runtimeMode);
  163. // if this is a new DiffuseProbeGrid entity and the box shape has not been changed (i.e., it's still unit sized)
  164. // then use the default extents, otherwise use the current box shape extents
  165. AZ::Vector3 extents(0.0f);
  166. AZ::Vector3 boxDimensions = m_boxShapeInterface->GetBoxDimensions();
  167. if (m_configuration.m_entityId == EntityId::InvalidEntityId && boxDimensions == AZ::Vector3(1.0f))
  168. {
  169. extents = m_configuration.m_extents;
  170. }
  171. else
  172. {
  173. extents = boxDimensions;
  174. }
  175. m_boxShapeInterface->SetBoxDimensions(extents);
  176. m_boxChangedByGridEvent.Signal(true);
  177. }
  178. void DiffuseProbeGridComponentController::OnAssetReady(Data::Asset<Data::AssetData> asset)
  179. {
  180. // if all assets are ready we can set the baked texture images
  181. if (m_configuration.m_bakedIrradianceTextureAsset.IsReady() &&
  182. m_configuration.m_bakedDistanceTextureAsset.IsReady() &&
  183. m_configuration.m_bakedProbeDataTextureAsset.IsReady())
  184. {
  185. Data::AssetBus::MultiHandler::BusDisconnect(m_configuration.m_bakedIrradianceTextureAsset.GetId());
  186. Data::AssetBus::MultiHandler::BusDisconnect(m_configuration.m_bakedDistanceTextureAsset.GetId());
  187. Data::AssetBus::MultiHandler::BusDisconnect(m_configuration.m_bakedProbeDataTextureAsset.GetId());
  188. UpdateBakedTextures();
  189. }
  190. }
  191. void DiffuseProbeGridComponentController::OnAssetError(Data::Asset<Data::AssetData> asset)
  192. {
  193. Data::AssetBus::MultiHandler::BusDisconnect(asset.GetId());
  194. AZ_Error("DiffuseProbeGrid", false, "Failed to load baked texture [%s], please re-bake this DiffuseProbeGrid.", asset.GetId().ToString<AZStd::string>().c_str());
  195. }
  196. void DiffuseProbeGridComponentController::Deactivate()
  197. {
  198. if (!AZ_TRAIT_DIFFUSE_GI_PASSES_SUPPORTED)
  199. {
  200. // GI is not supported on this platform
  201. return;
  202. }
  203. if (m_featureProcessor)
  204. {
  205. m_featureProcessor->RemoveProbeGrid(m_handle);
  206. }
  207. LmbrCentral::ShapeComponentNotificationsBus::Handler::BusDisconnect();
  208. Data::AssetBus::MultiHandler::BusDisconnect();
  209. TransformNotificationBus::Handler::BusDisconnect();
  210. m_transformInterface = nullptr;
  211. m_featureProcessor = nullptr;
  212. m_shapeBus = nullptr;
  213. m_boxShapeInterface = nullptr;
  214. }
  215. void DiffuseProbeGridComponentController::SetConfiguration(const DiffuseProbeGridComponentConfig& config)
  216. {
  217. m_configuration = config;
  218. }
  219. const DiffuseProbeGridComponentConfig& DiffuseProbeGridComponentController::GetConfiguration() const
  220. {
  221. return m_configuration;
  222. }
  223. void DiffuseProbeGridComponentController::OnTransformChanged([[maybe_unused]] const AZ::Transform& local, const AZ::Transform& world)
  224. {
  225. if (!m_featureProcessor)
  226. {
  227. return;
  228. }
  229. m_featureProcessor->SetTransform(m_handle, ComputeOverallTransform(world));
  230. }
  231. void DiffuseProbeGridComponentController::OnShapeChanged(ShapeChangeReasons changeReason)
  232. {
  233. if (!m_featureProcessor)
  234. {
  235. return;
  236. }
  237. if (m_inShapeChangeHandler)
  238. {
  239. return;
  240. }
  241. m_inShapeChangeHandler = true;
  242. AZ_Assert(m_featureProcessor->IsValidProbeGridHandle(m_handle), "OnShapeChanged handler called before probe was registered with feature processor");
  243. if (changeReason == ShapeChangeReasons::ShapeChanged)
  244. {
  245. AZ::Vector3 dimensions = m_boxShapeInterface->GetBoxDimensions();
  246. if (m_featureProcessor->ValidateExtents(m_handle, dimensions))
  247. {
  248. m_featureProcessor->SetExtents(m_handle, dimensions);
  249. m_configuration.m_extents = dimensions;
  250. }
  251. else
  252. {
  253. // restore old dimensions
  254. m_boxShapeInterface->SetBoxDimensions(m_configuration.m_extents);
  255. m_boxChangedByGridEvent.Signal(true);
  256. }
  257. // the shape translation offset may have changed, which would affect the overall transform
  258. m_featureProcessor->SetTransform(m_handle, ComputeOverallTransform(m_transformInterface->GetWorldTM()));
  259. }
  260. m_inShapeChangeHandler = false;
  261. }
  262. AZ::Aabb DiffuseProbeGridComponentController::GetAabb() const
  263. {
  264. return m_shapeBus ? m_shapeBus->GetEncompassingAabb() : AZ::Aabb::CreateNull();
  265. }
  266. void DiffuseProbeGridComponentController::RegisterBoxChangedByGridHandler(AZ::Event<bool>::Handler& handler)
  267. {
  268. handler.Connect(m_boxChangedByGridEvent);
  269. }
  270. bool DiffuseProbeGridComponentController::ValidateProbeSpacing(const AZ::Vector3& newSpacing)
  271. {
  272. return m_featureProcessor->ValidateProbeSpacing(m_handle, newSpacing);
  273. }
  274. void DiffuseProbeGridComponentController::SetProbeSpacing(const AZ::Vector3& probeSpacing)
  275. {
  276. m_configuration.m_probeSpacing = probeSpacing;
  277. m_featureProcessor->SetProbeSpacing(m_handle, m_configuration.m_probeSpacing);
  278. }
  279. void DiffuseProbeGridComponentController::SetAmbientMultiplier(float ambientMultiplier)
  280. {
  281. if (!m_featureProcessor)
  282. {
  283. return;
  284. }
  285. m_configuration.m_ambientMultiplier = ambientMultiplier;
  286. m_featureProcessor->SetAmbientMultiplier(m_handle, m_configuration.m_ambientMultiplier);
  287. }
  288. void DiffuseProbeGridComponentController::SetViewBias(float viewBias)
  289. {
  290. if (!m_featureProcessor)
  291. {
  292. return;
  293. }
  294. m_configuration.m_viewBias = viewBias;
  295. m_featureProcessor->SetViewBias(m_handle, m_configuration.m_viewBias);
  296. }
  297. void DiffuseProbeGridComponentController::SetNormalBias(float normalBias)
  298. {
  299. if (!m_featureProcessor)
  300. {
  301. return;
  302. }
  303. m_configuration.m_normalBias = normalBias;
  304. m_featureProcessor->SetNormalBias(m_handle, m_configuration.m_normalBias);
  305. }
  306. void DiffuseProbeGridComponentController::SetNumRaysPerProbe(const DiffuseProbeGridNumRaysPerProbe& numRaysPerProbe)
  307. {
  308. if (!m_featureProcessor)
  309. {
  310. return;
  311. }
  312. m_configuration.m_numRaysPerProbe = numRaysPerProbe;
  313. m_featureProcessor->SetNumRaysPerProbe(m_handle, m_configuration.m_numRaysPerProbe);
  314. }
  315. void DiffuseProbeGridComponentController::SetScrolling(bool scrolling)
  316. {
  317. if (!m_featureProcessor)
  318. {
  319. return;
  320. }
  321. m_configuration.m_scrolling = scrolling;
  322. m_featureProcessor->SetScrolling(m_handle, m_configuration.m_scrolling);
  323. }
  324. void DiffuseProbeGridComponentController::SetEdgeBlendIbl(bool edgeBlendIbl)
  325. {
  326. if (!m_featureProcessor)
  327. {
  328. return;
  329. }
  330. m_configuration.m_edgeBlendIbl = edgeBlendIbl;
  331. m_featureProcessor->SetEdgeBlendIbl(m_handle, m_configuration.m_edgeBlendIbl);
  332. }
  333. void DiffuseProbeGridComponentController::SetFrameUpdateCount(uint32_t frameUpdateCount)
  334. {
  335. if (!m_featureProcessor)
  336. {
  337. return;
  338. }
  339. m_configuration.m_frameUpdateCount = frameUpdateCount;
  340. m_featureProcessor->SetFrameUpdateCount(m_handle, m_configuration.m_frameUpdateCount);
  341. }
  342. void DiffuseProbeGridComponentController::SetTransparencyMode(DiffuseProbeGridTransparencyMode transparencyMode)
  343. {
  344. if (!m_featureProcessor)
  345. {
  346. return;
  347. }
  348. m_configuration.m_transparencyMode = transparencyMode;
  349. m_featureProcessor->SetTransparencyMode(m_handle, m_configuration.m_transparencyMode);
  350. }
  351. void DiffuseProbeGridComponentController::SetEmissiveMultiplier(float emissiveMultiplier)
  352. {
  353. if (!m_featureProcessor)
  354. {
  355. return;
  356. }
  357. m_configuration.m_emissiveMultiplier = emissiveMultiplier;
  358. m_featureProcessor->SetEmissiveMultiplier(m_handle, m_configuration.m_emissiveMultiplier);
  359. }
  360. void DiffuseProbeGridComponentController::SetEditorMode(DiffuseProbeGridMode editorMode)
  361. {
  362. if (!m_featureProcessor)
  363. {
  364. return;
  365. }
  366. // update the configuration and change the DiffuseProbeGrid mode
  367. m_configuration.m_editorMode = editorMode;
  368. m_featureProcessor->SetMode(m_handle, m_configuration.m_editorMode);
  369. }
  370. void DiffuseProbeGridComponentController::SetRuntimeMode(DiffuseProbeGridMode runtimeMode)
  371. {
  372. if (!m_featureProcessor)
  373. {
  374. return;
  375. }
  376. // only update the configuration
  377. m_configuration.m_runtimeMode = runtimeMode;
  378. }
  379. void DiffuseProbeGridComponentController::SetVisualizationEnabled(bool visualizationEnabled)
  380. {
  381. if (!m_featureProcessor)
  382. {
  383. return;
  384. }
  385. m_configuration.m_visualizationEnabled = visualizationEnabled;
  386. m_featureProcessor->SetVisualizationEnabled(m_handle, m_configuration.m_visualizationEnabled);
  387. }
  388. void DiffuseProbeGridComponentController::SetVisualizationShowInactiveProbes(bool visualizationShowInactiveProbes)
  389. {
  390. if (!m_featureProcessor)
  391. {
  392. return;
  393. }
  394. m_configuration.m_visualizationShowInactiveProbes = visualizationShowInactiveProbes;
  395. m_featureProcessor->SetVisualizationShowInactiveProbes(m_handle, m_configuration.m_visualizationShowInactiveProbes);
  396. }
  397. void DiffuseProbeGridComponentController::SetVisualizationSphereRadius(float visualizationSphereRadius)
  398. {
  399. if (!m_featureProcessor)
  400. {
  401. return;
  402. }
  403. m_configuration.m_visualizationSphereRadius = visualizationSphereRadius;
  404. m_featureProcessor->SetVisualizationSphereRadius(m_handle, m_configuration.m_visualizationSphereRadius);
  405. }
  406. bool DiffuseProbeGridComponentController::CanBakeTextures()
  407. {
  408. return m_featureProcessor && m_featureProcessor->CanBakeTextures();
  409. }
  410. void DiffuseProbeGridComponentController::BakeTextures(DiffuseProbeGridBakeTexturesCallback callback)
  411. {
  412. if (!m_featureProcessor)
  413. {
  414. return;
  415. }
  416. m_featureProcessor->BakeTextures(
  417. m_handle,
  418. callback,
  419. m_configuration.m_bakedIrradianceTextureRelativePath,
  420. m_configuration.m_bakedDistanceTextureRelativePath,
  421. m_configuration.m_bakedProbeDataTextureRelativePath);
  422. }
  423. void DiffuseProbeGridComponentController::UpdateBakedTextures()
  424. {
  425. if (!m_featureProcessor)
  426. {
  427. return;
  428. }
  429. DiffuseProbeGridBakedTextures bakedTextures;
  430. bakedTextures.m_irradianceImage = RPI::StreamingImage::FindOrCreate(m_configuration.m_bakedIrradianceTextureAsset);
  431. bakedTextures.m_irradianceImageRelativePath = m_configuration.m_bakedIrradianceTextureRelativePath;
  432. bakedTextures.m_distanceImage = RPI::StreamingImage::FindOrCreate(m_configuration.m_bakedDistanceTextureAsset);
  433. bakedTextures.m_distanceImageRelativePath = m_configuration.m_bakedDistanceTextureRelativePath;
  434. bakedTextures.m_probeDataImage = RPI::StreamingImage::FindOrCreate(m_configuration.m_bakedProbeDataTextureAsset);
  435. bakedTextures.m_probeDataImageRelativePath = m_configuration.m_bakedProbeDataTextureRelativePath;
  436. m_featureProcessor->SetBakedTextures(m_handle, bakedTextures);
  437. }
  438. AZ::Transform DiffuseProbeGridComponentController::ComputeOverallTransform(const AZ::Transform& entityTransform) const
  439. {
  440. const bool isTypeAxisAligned = m_boxShapeInterface ? m_boxShapeInterface->IsTypeAxisAligned() : false;
  441. const AZ::Vector3 translationOffset = m_shapeBus ? m_shapeBus->GetTranslationOffset() : AZ::Vector3::CreateZero();
  442. const AZ::Transform translationOffsetTransform = AZ::Transform::CreateTranslation(translationOffset);
  443. if (isTypeAxisAligned)
  444. {
  445. AZ::Transform entityTransformNoRotation = entityTransform;
  446. entityTransformNoRotation.SetRotation(AZ::Quaternion::CreateIdentity());
  447. return entityTransformNoRotation * translationOffsetTransform;
  448. }
  449. return entityTransform * translationOffsetTransform;
  450. }
  451. } // namespace Render
  452. } // namespace AZ