DirectionalLightComponentController.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 <Atom/Feature/CoreLights/DirectionalLightFeatureProcessorInterface.h>
  10. #include <AtomLyIntegration/CommonFeatures/CoreLights/DirectionalLightBus.h>
  11. #include <AtomLyIntegration/CommonFeatures/CoreLights/DirectionalLightComponentConfig.h>
  12. #include <AzCore/Component/Component.h>
  13. #include <AzCore/Component/TickBus.h>
  14. #include <AzCore/Component/TransformBus.h>
  15. #include <AzFramework/Components/CameraBus.h>
  16. namespace AZ
  17. {
  18. namespace Render
  19. {
  20. class EditorDirectionalLightComponent;
  21. class DirectionalLightComponentController final
  22. : public DirectionalLightRequestBus::Handler
  23. , public TickBus::Handler
  24. , TransformNotificationBus::MultiHandler
  25. , Camera::CameraNotificationBus::Handler
  26. {
  27. public:
  28. friend class EditorDirectionaLightComponent;
  29. AZ_TYPE_INFO(AZ::Render::DirectionalLightComponentController, "60A9DFF4-6A05-4D83-81BD-13ADEB95B29C");
  30. static void Reflect(ReflectContext* context);
  31. static void GetDependentServices(ComponentDescriptor::DependencyArrayType& dependent);
  32. static void GetProvidedServices(ComponentDescriptor::DependencyArrayType& provided);
  33. static void GetIncompatibleServices(ComponentDescriptor::DependencyArrayType& incompatible);
  34. DirectionalLightComponentController() = default;
  35. DirectionalLightComponentController(const DirectionalLightComponentConfig& config);
  36. virtual ~DirectionalLightComponentController() = default;
  37. void Activate(EntityId entityId);
  38. void Deactivate();
  39. void SetConfiguration(const DirectionalLightComponentConfig& config);
  40. const DirectionalLightComponentConfig& GetConfiguration() const;
  41. // DirectionalLightRequestBus::Handler overrides...
  42. const Color& GetColor() const override;
  43. void SetColor(const Color& color) override;
  44. float GetIntensity() const override;
  45. void SetIntensity(float intensity, PhotometricUnit unit) override;
  46. void SetIntensity(float intensity) override;
  47. float GetAngularDiameter() const override;
  48. void SetAngularDiameter(float angularDiameter) override;
  49. ShadowmapSize GetShadowmapSize() const override;
  50. void SetShadowmapSize(ShadowmapSize size) override;
  51. uint32_t GetCascadeCount() const override;
  52. void SetCascadeCount(uint32_t cascadeCount) override;
  53. float GetShadowmapFrustumSplitSchemeRatio() const override;
  54. void SetShadowmapFrustumSplitSchemeRatio(float ratio) override;
  55. const Vector4& GetCascadeFarDepth() override;
  56. void SetCascadeFarDepth(const Vector4& farDepth) override;
  57. bool GetShadowmapFrustumSplitAutomatic() const override;
  58. void SetShadowmapFrustumSplitAutomatic(bool isAutomatic) override;
  59. EntityId GetCameraEntityId() const override;
  60. void SetCameraEntityId(EntityId entityId) override;
  61. float GetShadowFarClipDistance() const override;
  62. void SetShadowFarClipDistance(float farDist) override;
  63. float GetGroundHeight() const override;
  64. void SetGroundHeight(float groundHeight) override;
  65. bool GetViewFrustumCorrectionEnabled() const override;
  66. void SetViewFrustumCorrectionEnabled(bool enabled) override;
  67. bool GetDebugColoringEnabled() const override;
  68. void SetDebugColoringEnabled(bool enabled) override;
  69. ShadowFilterMethod GetShadowFilterMethod() const override;
  70. void SetShadowFilterMethod(ShadowFilterMethod method) override;
  71. uint32_t GetFilteringSampleCount() const override;
  72. void SetFilteringSampleCount(uint32_t count) override;
  73. bool GetShadowReceiverPlaneBiasEnabled() const override;
  74. void SetShadowReceiverPlaneBiasEnabled(bool enable) override;
  75. float GetShadowBias() const override;
  76. void SetShadowBias(float bias) override;
  77. float GetNormalShadowBias() const override;
  78. void SetNormalShadowBias(float bias) override;
  79. bool GetCascadeBlendingEnabled() const override;
  80. void SetCascadeBlendingEnabled(bool enable) override;
  81. void SetFullscreenBlurEnabled(bool enable);
  82. void SetFullscreenBlurConstFalloff(float blurConstFalloff);
  83. void SetFullscreenBlurDepthFalloffStrength(float blurDepthFalloffStrength);
  84. bool GetAffectsGI() const override;
  85. void SetAffectsGI(bool affectsGI) override;
  86. float GetAffectsGIFactor() const override;
  87. void SetAffectsGIFactor(float affectsGIFactor) override;
  88. void BindConfigurationChangedEventHandler(DirectionalLightConfigurationChangedEvent::Handler& configurationChangedHandler) override;
  89. private:
  90. friend class EditorDirectionalLightComponent;
  91. // TickBus::Handler overrides...
  92. void OnTick(float deltaTime, ScriptTimePoint time) override;
  93. // TransformNotificationBus::MultiHandler overrides...
  94. void OnTransformChanged(const Transform& /*local*/, const Transform& /*world*/) override;
  95. // Camera::CameraNotificationBus::Handler overrides...
  96. void OnCameraAdded(const AZ::EntityId& cameraId) override;
  97. void OnCameraRemoved(const AZ::EntityId& cameraId) override;
  98. //! This apply the contents of m_configuration to the light.
  99. void ApplyConfiguration();
  100. //! This returns the configuration of camera.
  101. Camera::Configuration GetCameraConfiguration() const;
  102. //! This updates the current camera transform.
  103. //! The camera transform defines the camera view frustum.
  104. void UpdateCameraTransform();
  105. //! This updates the current directional light transform.
  106. void UpdateLightTransform();
  107. //! Updates current directional light color and intensity.
  108. void ColorIntensityChanged();
  109. DirectionalLightComponentConfig m_configuration;
  110. EntityId m_entityId{ EntityId::InvalidEntityId };
  111. Transform m_lastCameraTransform = Transform::CreateTranslation(AZ::Vector3(std::numeric_limits<float>::max()));
  112. PhotometricValue m_photometricValue;
  113. DirectionalLightFeatureProcessorInterface* m_featureProcessor = nullptr;
  114. DirectionalLightFeatureProcessorInterface::LightHandle m_lightHandle;
  115. //! Event used to signal when at least one of the properties changes.
  116. DirectionalLightConfigurationChangedEvent m_configurationChangedEvent;
  117. };
  118. } // namespace Render
  119. } // namespace AZ