DirectionalLightComponentConfig.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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(9) // 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("ShadowFarClipDistance", &DirectionalLightComponentConfig::m_shadowFarClipDistance)
  29. ->Field("ShadowmapSize", &DirectionalLightComponentConfig::m_shadowmapSize)
  30. ->Field("CascadeCount", &DirectionalLightComponentConfig::m_cascadeCount)
  31. ->Field("SplitAutomatic", &DirectionalLightComponentConfig::m_isShadowmapFrustumSplitAutomatic)
  32. ->Field("SplitRatio", &DirectionalLightComponentConfig::m_shadowmapFrustumSplitSchemeRatio)
  33. ->Field("CascadeFarDepths", &DirectionalLightComponentConfig::m_cascadeFarDepths)
  34. ->Field("GroundHeight", &DirectionalLightComponentConfig::m_groundHeight)
  35. ->Field("IsCascadeCorrectionEnabled", &DirectionalLightComponentConfig::m_isCascadeCorrectionEnabled)
  36. ->Field("IsDebugColoringEnabled", &DirectionalLightComponentConfig::m_isDebugColoringEnabled)
  37. ->Field("ShadowFilterMethod", &DirectionalLightComponentConfig::m_shadowFilterMethod)
  38. ->Field("PcfFilteringSampleCount", &DirectionalLightComponentConfig::m_filteringSampleCount)
  39. ->Field("ShadowReceiverPlaneBiasEnabled", &DirectionalLightComponentConfig::m_receiverPlaneBiasEnabled)
  40. ->Field("Shadow Bias", &DirectionalLightComponentConfig::m_shadowBias)
  41. ->Field("Normal Shadow Bias", &DirectionalLightComponentConfig::m_normalShadowBias)
  42. ->Field("CascadeBlendingEnabled", &DirectionalLightComponentConfig::m_cascadeBlendingEnabled)
  43. ->Field("FullscreenBlurEnabled", &DirectionalLightComponentConfig::m_fullscreenBlurEnabled)
  44. ->Field("FullscreenBlurConstFalloff", &DirectionalLightComponentConfig::m_fullscreenBlurConstFalloff)
  45. ->Field("FullscreenBlurDepthFalloffStrength", &DirectionalLightComponentConfig::m_fullscreenBlurDepthFalloffStrength)
  46. ->Field("Affects GI", &DirectionalLightComponentConfig::m_affectsGI)
  47. ->Field("Affects GI Factor", &DirectionalLightComponentConfig::m_affectsGIFactor)
  48. ;
  49. }
  50. }
  51. const char* DirectionalLightComponentConfig::GetIntensitySuffix() const
  52. {
  53. return PhotometricValue::GetTypeSuffix(m_intensityMode);
  54. }
  55. float DirectionalLightComponentConfig::GetIntensityMin() const
  56. {
  57. switch (m_intensityMode)
  58. {
  59. case PhotometricUnit::Lux:
  60. return 0.0f;
  61. case PhotometricUnit::Ev100Illuminance:
  62. return AZStd::numeric_limits<float>::lowest();
  63. }
  64. return 0.0f;
  65. }
  66. float DirectionalLightComponentConfig::GetIntensityMax() const
  67. {
  68. // While there is no hard-max, a max must be included when there is a hard min.
  69. return AZStd::numeric_limits<float>::max();
  70. }
  71. float DirectionalLightComponentConfig::GetIntensitySoftMin() const
  72. {
  73. switch (m_intensityMode)
  74. {
  75. case PhotometricUnit::Lux:
  76. return 0.0f;
  77. case PhotometricUnit::Ev100Illuminance:
  78. return -4.0f;
  79. }
  80. return 0.0f;
  81. }
  82. float DirectionalLightComponentConfig::GetIntensitySoftMax() const
  83. {
  84. switch (m_intensityMode)
  85. {
  86. case PhotometricUnit::Lux:
  87. return 200'000.0f;
  88. case PhotometricUnit::Ev100Illuminance:
  89. return 16.0f;
  90. }
  91. return 0.0f;
  92. }
  93. bool DirectionalLightComponentConfig::IsSplitManual() const
  94. {
  95. return !m_isShadowmapFrustumSplitAutomatic;
  96. }
  97. bool DirectionalLightComponentConfig::IsSplitAutomatic() const
  98. {
  99. return m_isShadowmapFrustumSplitAutomatic;
  100. }
  101. bool DirectionalLightComponentConfig::IsCascadeCorrectionDisabled() const
  102. {
  103. return (m_cascadeCount == 1 || !m_isCascadeCorrectionEnabled);
  104. }
  105. bool DirectionalLightComponentConfig::IsShadowFilteringDisabled() const
  106. {
  107. return (m_shadowFilterMethod == ShadowFilterMethod::None);
  108. }
  109. bool DirectionalLightComponentConfig::IsShadowPcfDisabled() const
  110. {
  111. return !(m_shadowFilterMethod == ShadowFilterMethod::Pcf);
  112. }
  113. bool DirectionalLightComponentConfig::IsEsmDisabled() const
  114. {
  115. return !(m_shadowFilterMethod == ShadowFilterMethod::Esm || m_shadowFilterMethod == ShadowFilterMethod::EsmPcf);
  116. }
  117. AZ::Crc32 DirectionalLightComponentConfig::UpdateCascadeFarDepths()
  118. {
  119. if (IsSplitAutomatic())
  120. {
  121. for (uint32_t i = 0; i < Shadow::MaxNumberOfCascades; ++i)
  122. {
  123. m_cascadeFarDepths.SetElement(
  124. i, i < m_cascadeCount ? m_shadowFarClipDistance * (i + 1) / m_cascadeCount : m_shadowFarClipDistance);
  125. }
  126. }
  127. m_cascadeFarDepths =
  128. m_cascadeFarDepths.GetClamp(Vector4(DirectionalLightConstants::MIN_CASCADE_FAR_DEPTH), Vector4(m_shadowFarClipDistance));
  129. return Edit::PropertyRefreshLevels::AttributesAndValues;
  130. }
  131. } // namespace Render
  132. } // namespace AZ