ImageBasedLightComponentController.h 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #pragma once
  9. #include <AzCore/Component/Component.h>
  10. #include <AzCore/Component/TransformBus.h>
  11. #include <Atom/Feature/ImageBasedLights/ImageBasedLightFeatureProcessorInterface.h>
  12. #include <AtomLyIntegration/CommonFeatures/ImageBasedLights/ImageBasedLightComponentBus.h>
  13. #include <AtomLyIntegration/CommonFeatures/ImageBasedLights/ImageBasedLightComponentConfig.h>
  14. namespace AZ
  15. {
  16. namespace Render
  17. {
  18. //! Controls behavior of an image based light that affects a scene
  19. class ImageBasedLightComponentController final
  20. : ImageBasedLightComponentRequestBus::Handler
  21. , Data::AssetBus::MultiHandler
  22. , TransformNotificationBus::Handler
  23. {
  24. public:
  25. friend class EditorImageBasedLightComponent;
  26. AZ_CLASS_ALLOCATOR(ImageBasedLightComponentController, SystemAllocator);
  27. AZ_RTTI(AZ::Render::ImageBasedLightComponentController, "{73DBD008-4E77-471C-B7DE-F2217A256FE2}");
  28. static void Reflect(ReflectContext* context);
  29. static void GetProvidedServices(ComponentDescriptor::DependencyArrayType& provided);
  30. static void GetIncompatibleServices(ComponentDescriptor::DependencyArrayType& incompatible);
  31. ImageBasedLightComponentController() = default;
  32. ImageBasedLightComponentController(const ImageBasedLightComponentConfig& config);
  33. void Activate(EntityId entityId);
  34. void Deactivate();
  35. void SetConfiguration(const ImageBasedLightComponentConfig& config);
  36. const ImageBasedLightComponentConfig& GetConfiguration() const;
  37. private:
  38. AZ_DISABLE_COPY(ImageBasedLightComponentController);
  39. //! Data::AssetBus interface
  40. void OnAssetReady(Data::Asset<Data::AssetData> asset) override;
  41. void OnAssetReloaded(Data::Asset<Data::AssetData> asset) override;
  42. void OnAssetError(Data::Asset<Data::AssetData> asset) override;
  43. //! ImageBasedLightComponentRequestBus overrides...
  44. void SetSpecularImageAsset(const Data::Asset<RPI::StreamingImageAsset>& imageAsset) override;
  45. void SetDiffuseImageAsset(const Data::Asset<RPI::StreamingImageAsset>& imageAsset) override;
  46. Data::Asset<RPI::StreamingImageAsset> GetSpecularImageAsset() const override;
  47. Data::Asset<RPI::StreamingImageAsset> GetDiffuseImageAsset() const override;
  48. void SetSpecularImageAssetId(const Data::AssetId imageAssetId) override;
  49. void SetDiffuseImageAssetId(const Data::AssetId imageAssetId) override;
  50. Data::AssetId GetSpecularImageAssetId() const override;
  51. Data::AssetId GetDiffuseImageAssetId() const override;
  52. void SetSpecularImageAssetPath(const AZStd::string path) override;
  53. void SetDiffuseImageAssetPath(const AZStd::string path) override;
  54. AZStd::string GetSpecularImageAssetPath() const override;
  55. AZStd::string GetDiffuseImageAssetPath() const override;
  56. void SetExposure(float exposure) override;
  57. float GetExposure() const override;
  58. // TransformNotificationBus::Handler overrides...
  59. void OnTransformChanged(const AZ::Transform& local, const AZ::Transform& world) override;
  60. //! Queues a load of an image Asset
  61. void LoadImage(Data::Asset<RPI::StreamingImageAsset>& imageAsset);
  62. //! Releases all image assest.
  63. void ReleaseImages();
  64. //! Handles all Data::AssetBus calls in a unified way
  65. void UpdateWithAsset(Data::Asset<Data::AssetData> updatedAsset);
  66. //! Validates individual asset updates, returns true for valid ready assets.
  67. bool HandleAssetUpdate(Data::Asset<Data::AssetData> updatedAsset, Data::Asset<RPI::StreamingImageAsset>& configAsset);
  68. EntityId m_entityId;
  69. ImageBasedLightComponentConfig m_configuration;
  70. ImageBasedLightFeatureProcessorInterface* m_featureProcessor = nullptr;
  71. };
  72. } // namespace Render
  73. } // namespace AZ