DirectionalLightComponentConfig.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 <Atom/Feature/CoreLights/PhotometricValue.h>
  9. #include <AtomLyIntegration/CommonFeatures/CoreLights/DirectionalLightComponentConfig.h>
  10. #include <AzCore/Serialization/SerializeContext.h>
  11. #include <AzCore/Serialization/EditContext.h>
  12. #include <AzCore/std/limits.h>
  13. namespace AZ
  14. {
  15. namespace Render
  16. {
  17. void DirectionalLightComponentConfig::Reflect(ReflectContext* context)
  18. {
  19. if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
  20. {
  21. serializeContext->Class<DirectionalLightComponentConfig, ComponentConfig>()
  22. ->Version(10) // Added AffectsGI
  23. ->Field("Color", &DirectionalLightComponentConfig::m_color)
  24. ->Field("IntensityMode", &DirectionalLightComponentConfig::m_intensityMode)
  25. ->Field("Intensity", &DirectionalLightComponentConfig::m_intensity)
  26. ->Field("AngularDiameter", &DirectionalLightComponentConfig::m_angularDiameter)
  27. ->Field("CameraEntityId", &DirectionalLightComponentConfig::m_cameraEntityId)
  28. ->Field("Shadow Enabled", &DirectionalLightComponentConfig::m_shadowEnabled)
  29. ->Field("ShadowFarClipDistance", &DirectionalLightComponentConfig::m_shadowFarClipDistance)
  30. ->Field("ShadowmapSize", &DirectionalLightComponentConfig::m_shadowmapSize)
  31. ->Field("CascadeCount", &DirectionalLightComponentConfig::m_cascadeCount)
  32. ->Field("SplitAutomatic", &DirectionalLightComponentConfig::m_isShadowmapFrustumSplitAutomatic)
  33. ->Field("SplitRatio", &DirectionalLightComponentConfig::m_shadowmapFrustumSplitSchemeRatio)
  34. ->Field("CascadeFarDepths", &DirectionalLightComponentConfig::m_cascadeFarDepths)
  35. ->Field("GroundHeight", &DirectionalLightComponentConfig::m_groundHeight)
  36. ->Field("IsCascadeCorrectionEnabled", &DirectionalLightComponentConfig::m_isCascadeCorrectionEnabled)
  37. ->Field("IsDebugColoringEnabled", &DirectionalLightComponentConfig::m_isDebugColoringEnabled)
  38. ->Field("ShadowFilterMethod", &DirectionalLightComponentConfig::m_shadowFilterMethod)
  39. ->Field("PcfFilteringSampleCount", &DirectionalLightComponentConfig::m_filteringSampleCount)
  40. ->Field("ShadowReceiverPlaneBiasEnabled", &DirectionalLightComponentConfig::m_receiverPlaneBiasEnabled)
  41. ->Field("Shadow Bias", &DirectionalLightComponentConfig::m_shadowBias)
  42. ->Field("Normal Shadow Bias", &DirectionalLightComponentConfig::m_normalShadowBias)
  43. ->Field("CascadeBlendingEnabled", &DirectionalLightComponentConfig::m_cascadeBlendingEnabled)
  44. ->Field("FullscreenBlurEnabled", &DirectionalLightComponentConfig::m_fullscreenBlurEnabled)
  45. ->Field("FullscreenBlurConstFalloff", &DirectionalLightComponentConfig::m_fullscreenBlurConstFalloff)
  46. ->Field("FullscreenBlurDepthFalloffStrength", &DirectionalLightComponentConfig::m_fullscreenBlurDepthFalloffStrength)
  47. ->Field("Affects GI", &DirectionalLightComponentConfig::m_affectsGI)
  48. ->Field("Affects GI Factor", &DirectionalLightComponentConfig::m_affectsGIFactor)
  49. ->Field("LightingChannelConfig", &DirectionalLightComponentConfig::m_lightingChannelConfig)
  50. ;
  51. }
  52. }
  53. const char* DirectionalLightComponentConfig::GetIntensitySuffix() const
  54. {
  55. return PhotometricValue::GetTypeSuffix(m_intensityMode);
  56. }
  57. float DirectionalLightComponentConfig::GetIntensityMin() const
  58. {
  59. switch (m_intensityMode)
  60. {
  61. case PhotometricUnit::Lux:
  62. return 0.0f;
  63. case PhotometricUnit::Ev100Illuminance:
  64. return AZStd::numeric_limits<float>::lowest();
  65. }
  66. return 0.0f;
  67. }
  68. float DirectionalLightComponentConfig::GetIntensityMax() const
  69. {
  70. // While there is no hard-max, a max must be included when there is a hard min.
  71. return AZStd::numeric_limits<float>::max();
  72. }
  73. float DirectionalLightComponentConfig::GetIntensitySoftMin() const
  74. {
  75. switch (m_intensityMode)
  76. {
  77. case PhotometricUnit::Lux:
  78. return 0.0f;
  79. case PhotometricUnit::Ev100Illuminance:
  80. return -4.0f;
  81. }
  82. return 0.0f;
  83. }
  84. float DirectionalLightComponentConfig::GetIntensitySoftMax() const
  85. {
  86. switch (m_intensityMode)
  87. {
  88. case PhotometricUnit::Lux:
  89. return 200'000.0f;
  90. case PhotometricUnit::Ev100Illuminance:
  91. return 16.0f;
  92. }
  93. return 0.0f;
  94. }
  95. bool DirectionalLightComponentConfig::IsSplitManual() const
  96. {
  97. return !m_isShadowmapFrustumSplitAutomatic;
  98. }
  99. bool DirectionalLightComponentConfig::IsSplitAutomatic() const
  100. {
  101. return m_isShadowmapFrustumSplitAutomatic;
  102. }
  103. bool DirectionalLightComponentConfig::IsShadowDisabled() const
  104. {
  105. return !m_shadowEnabled;
  106. }
  107. bool DirectionalLightComponentConfig::IsCascadeCorrectionDisabled() const
  108. {
  109. return (!m_shadowEnabled || m_cascadeCount == 1 || !m_isCascadeCorrectionEnabled);
  110. }
  111. bool DirectionalLightComponentConfig::IsShadowFilteringDisabled() const
  112. {
  113. return (!m_shadowEnabled || m_shadowFilterMethod == ShadowFilterMethod::None);
  114. }
  115. bool DirectionalLightComponentConfig::IsShadowPcfDisabled() const
  116. {
  117. return !m_shadowEnabled || m_shadowFilterMethod != ShadowFilterMethod::Pcf;
  118. }
  119. bool DirectionalLightComponentConfig::IsEsmDisabled() const
  120. {
  121. return !m_shadowEnabled || (m_shadowFilterMethod != ShadowFilterMethod::Esm && m_shadowFilterMethod != ShadowFilterMethod::EsmPcf);
  122. }
  123. AZ::Crc32 DirectionalLightComponentConfig::UpdateCascadeFarDepths()
  124. {
  125. if (IsSplitAutomatic())
  126. {
  127. for (uint32_t i = 0; i < Shadow::MaxNumberOfCascades; ++i)
  128. {
  129. m_cascadeFarDepths.SetElement(
  130. i, i < m_cascadeCount ? m_shadowFarClipDistance * (i + 1) / m_cascadeCount : m_shadowFarClipDistance);
  131. }
  132. }
  133. m_cascadeFarDepths =
  134. m_cascadeFarDepths.GetClamp(Vector4(DirectionalLightConstants::MIN_CASCADE_FAR_DEPTH), Vector4(m_shadowFarClipDistance));
  135. return Edit::PropertyRefreshLevels::AttributesAndValues;
  136. }
  137. } // namespace Render
  138. } // namespace AZ