3
0

DirectionalLightComponentController.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. void SetShadowEnabled(bool enable) override;
  50. bool GetShadowEnabled() const override;
  51. ShadowmapSize GetShadowmapSize() const override;
  52. void SetShadowmapSize(ShadowmapSize size) override;
  53. uint32_t GetCascadeCount() const override;
  54. void SetCascadeCount(uint32_t cascadeCount) override;
  55. float GetShadowmapFrustumSplitSchemeRatio() const override;
  56. void SetShadowmapFrustumSplitSchemeRatio(float ratio) override;
  57. const Vector4& GetCascadeFarDepth() override;
  58. void SetCascadeFarDepth(const Vector4& farDepth) override;
  59. bool GetShadowmapFrustumSplitAutomatic() const override;
  60. void SetShadowmapFrustumSplitAutomatic(bool isAutomatic) override;
  61. EntityId GetCameraEntityId() const override;
  62. void SetCameraEntityId(EntityId entityId) override;
  63. float GetShadowFarClipDistance() const override;
  64. void SetShadowFarClipDistance(float farDist) override;
  65. float GetGroundHeight() const override;
  66. void SetGroundHeight(float groundHeight) override;
  67. bool GetViewFrustumCorrectionEnabled() const override;
  68. void SetViewFrustumCorrectionEnabled(bool enabled) override;
  69. bool GetDebugColoringEnabled() const override;
  70. void SetDebugColoringEnabled(bool enabled) override;
  71. ShadowFilterMethod GetShadowFilterMethod() const override;
  72. void SetShadowFilterMethod(ShadowFilterMethod method) override;
  73. uint32_t GetFilteringSampleCount() const override;
  74. void SetFilteringSampleCount(uint32_t count) override;
  75. bool GetShadowReceiverPlaneBiasEnabled() const override;
  76. void SetShadowReceiverPlaneBiasEnabled(bool enable) override;
  77. float GetShadowBias() const override;
  78. void SetShadowBias(float bias) override;
  79. float GetNormalShadowBias() const override;
  80. void SetNormalShadowBias(float bias) override;
  81. bool GetCascadeBlendingEnabled() const override;
  82. void SetCascadeBlendingEnabled(bool enable) override;
  83. void SetFullscreenBlurEnabled(bool enable);
  84. void SetFullscreenBlurConstFalloff(float blurConstFalloff);
  85. void SetFullscreenBlurDepthFalloffStrength(float blurDepthFalloffStrength);
  86. bool GetAffectsGI() const override;
  87. void SetAffectsGI(bool affectsGI) override;
  88. float GetAffectsGIFactor() const override;
  89. void SetAffectsGIFactor(float affectsGIFactor) override;
  90. void BindConfigurationChangedEventHandler(DirectionalLightConfigurationChangedEvent::Handler& configurationChangedHandler) override;
  91. uint32_t GetLightingChannelMask() const override;
  92. void SetLightingChannelMask(const uint32_t mask) override;
  93. private:
  94. friend class EditorDirectionalLightComponent;
  95. // TickBus::Handler overrides...
  96. void OnTick(float deltaTime, ScriptTimePoint time) override;
  97. // TransformNotificationBus::MultiHandler overrides...
  98. void OnTransformChanged(const Transform& /*local*/, const Transform& /*world*/) override;
  99. // Camera::CameraNotificationBus::Handler overrides...
  100. void OnCameraAdded(const AZ::EntityId& cameraId) override;
  101. void OnCameraRemoved(const AZ::EntityId& cameraId) override;
  102. //! This apply the contents of m_configuration to the light.
  103. void ApplyConfiguration();
  104. //! This returns the configuration of camera.
  105. Camera::Configuration GetCameraConfiguration() const;
  106. //! This updates the current camera transform.
  107. //! The camera transform defines the camera view frustum.
  108. void UpdateCameraTransform();
  109. //! This updates the current directional light transform.
  110. void UpdateLightTransform();
  111. //! Updates current directional light color and intensity.
  112. void ColorIntensityChanged();
  113. //! Updates light channel mask.
  114. void LightingChannelMaskChanged();
  115. DirectionalLightComponentConfig m_configuration;
  116. EntityId m_entityId{ EntityId::InvalidEntityId };
  117. Transform m_lastCameraTransform = Transform::CreateTranslation(AZ::Vector3(std::numeric_limits<float>::max()));
  118. PhotometricValue m_photometricValue;
  119. DirectionalLightFeatureProcessorInterface* m_featureProcessor = nullptr;
  120. DirectionalLightFeatureProcessorInterface::LightHandle m_lightHandle;
  121. //! Event used to signal when at least one of the properties changes.
  122. DirectionalLightConfigurationChangedEvent m_configurationChangedEvent;
  123. };
  124. } // namespace Render
  125. } // namespace AZ