ReflectionProbeComponentController.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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/Asset/AssetCommon.h>
  10. #include <AzCore/Component/Component.h>
  11. #include <AzCore/Component/TransformBus.h>
  12. #include <AzFramework/Visibility/BoundsBus.h>
  13. #include <Atom/Feature/ReflectionProbe/ReflectionProbeFeatureProcessorInterface.h>
  14. #include <Atom/RPI.Public/Model/Model.h>
  15. #include <LmbrCentral/Shape/BoxShapeComponentBus.h>
  16. #include <ReflectionProbe/ReflectionProbeComponentConstants.h>
  17. #include <CubeMapCapture/EditorCubeMapRenderer.h>
  18. namespace AZ
  19. {
  20. namespace Render
  21. {
  22. class ReflectionProbeComponentConfig final
  23. : public AZ::ComponentConfig
  24. {
  25. public:
  26. AZ_RTTI(AZ::Render::ReflectionProbeComponentConfig, "{D61730A1-CAF5-448C-B2A3-50D5DC909F31}", ComponentConfig);
  27. AZ_CLASS_ALLOCATOR(ReflectionProbeComponentConfig, SystemAllocator);
  28. static void Reflect(AZ::ReflectContext* context);
  29. float m_outerHeight = DefaultReflectionProbeExtents;
  30. float m_outerLength = DefaultReflectionProbeExtents;
  31. float m_outerWidth = DefaultReflectionProbeExtents;
  32. float m_innerHeight = DefaultReflectionProbeExtents;
  33. float m_innerLength = DefaultReflectionProbeExtents;
  34. float m_innerWidth = DefaultReflectionProbeExtents;
  35. bool m_useParallaxCorrection = true;
  36. bool m_showVisualization = true;
  37. bool m_useBakedCubemap = true;
  38. CubeMapSpecularQualityLevel m_bakedCubeMapQualityLevel = CubeMapSpecularQualityLevel::Medium;
  39. AZStd::string m_bakedCubeMapRelativePath;
  40. Data::Asset<RPI::StreamingImageAsset> m_bakedCubeMapAsset;
  41. Data::Asset<RPI::StreamingImageAsset> m_authoredCubeMapAsset;
  42. AZ::u64 m_entityId{ EntityId::InvalidEntityId };
  43. float m_renderExposure = 0.0f;
  44. float m_bakeExposure = 0.0f;
  45. };
  46. class ReflectionProbeComponentController final
  47. : public Data::AssetBus::MultiHandler
  48. , private TransformNotificationBus::Handler
  49. , private LmbrCentral::ShapeComponentNotificationsBus::Handler
  50. , public AzFramework::BoundsRequestBus::Handler
  51. {
  52. public:
  53. friend class EditorReflectionProbeComponent;
  54. AZ_CLASS_ALLOCATOR(ReflectionProbeComponentController, AZ::SystemAllocator);
  55. AZ_RTTI(AZ::Render::ReflectionProbeComponentController, "{EFFA88F1-7ED2-4552-B6F6-5E6B2B6D9311}");
  56. static void Reflect(AZ::ReflectContext* context);
  57. static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
  58. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  59. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  60. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  61. ReflectionProbeComponentController() = default;
  62. ReflectionProbeComponentController(const ReflectionProbeComponentConfig& config);
  63. void Activate(AZ::EntityId entityId);
  64. void Deactivate();
  65. void SetConfiguration(const ReflectionProbeComponentConfig& config);
  66. const ReflectionProbeComponentConfig& GetConfiguration() const;
  67. // returns the outer extent Aabb for this reflection
  68. AZ::Aabb GetAabb() const;
  69. // set the exposure to use when baking the cubemap
  70. void SetBakeExposure(float bakeExposure);
  71. // initiate the reflection probe bake, invokes callback when complete
  72. void BakeReflectionProbe(BuildCubeMapCallback callback, const AZStd::string& relativePath);
  73. // update the currently rendering cubemap asset for this probe
  74. void UpdateCubeMap();
  75. // BoundsRequestBus overrides ...
  76. AZ::Aabb GetWorldBounds() const override;
  77. AZ::Aabb GetLocalBounds() const override;
  78. void RegisterInnerExtentsChangedHandler(AZ::Event<bool>::Handler& handler);
  79. private:
  80. AZ_DISABLE_COPY(ReflectionProbeComponentController);
  81. // Data::AssetBus overrides ...
  82. void OnAssetReady(Data::Asset<Data::AssetData> asset) override;
  83. void OnAssetReloaded(Data::Asset<Data::AssetData> asset) override;
  84. // TransformNotificationBus overrides ...
  85. void OnTransformChanged(const AZ::Transform& local, const AZ::Transform& world) override;
  86. // ShapeComponentNotificationsBus overrides ...
  87. void OnShapeChanged(ShapeChangeReasons changeReason) override;
  88. // update the feature processor and configuration outer extents
  89. void UpdateOuterExtents();
  90. // computes the effective transform taking both the entity transform and the shape translation offset into account
  91. AZ::Transform ComputeOverallTransform(const AZ::Transform& entityTransform) const;
  92. // box shape component, used for defining the outer extents of the probe area
  93. LmbrCentral::BoxShapeComponentRequests* m_boxShapeInterface = nullptr;
  94. LmbrCentral::ShapeComponentRequests* m_shapeBus = nullptr;
  95. // handle for this probe in the feature processor
  96. ReflectionProbeHandle m_handle;
  97. ReflectionProbeFeatureProcessorInterface* m_featureProcessor = nullptr;
  98. TransformInterface* m_transformInterface = nullptr;
  99. AZ::EntityId m_entityId;
  100. ReflectionProbeComponentConfig m_configuration;
  101. // event fired when the inner extents change
  102. AZ::Event<bool> m_innerExtentsChangedEvent;
  103. };
  104. } // namespace Render
  105. } // namespace AZ