AreaLightComponentConfig.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 <AtomLyIntegration/CommonFeatures/CoreLights/AreaLightComponentConfig.h>
  9. #include <AzCore/std/limits.h>
  10. namespace AZ
  11. {
  12. namespace Render
  13. {
  14. void AreaLightComponentConfig::Reflect(ReflectContext* context)
  15. {
  16. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  17. {
  18. serializeContext->Class<AreaLightComponentConfig, ComponentConfig>()
  19. ->Version(8) // Added AffectsGI
  20. ->Field("LightType", &AreaLightComponentConfig::m_lightType)
  21. ->Field("Color", &AreaLightComponentConfig::m_color)
  22. ->Field("IntensityMode", &AreaLightComponentConfig::m_intensityMode)
  23. ->Field("Intensity", &AreaLightComponentConfig::m_intensity)
  24. ->Field("AttenuationRadiusMode", &AreaLightComponentConfig::m_attenuationRadiusMode)
  25. ->Field("AttenuationRadius", &AreaLightComponentConfig::m_attenuationRadius)
  26. ->Field("LightEmitsBothDirections", &AreaLightComponentConfig::m_lightEmitsBothDirections)
  27. ->Field("UseFastApproximation", &AreaLightComponentConfig::m_useFastApproximation)
  28. // Shutters
  29. ->Field("EnableShutters", &AreaLightComponentConfig::m_enableShutters)
  30. ->Field("InnerShutterAngleDegrees", &AreaLightComponentConfig::m_innerShutterAngleDegrees)
  31. ->Field("OuterShutterAngleDegrees", &AreaLightComponentConfig::m_outerShutterAngleDegrees)
  32. // Shadows
  33. ->Field("Enable Shadow", &AreaLightComponentConfig::m_enableShadow)
  34. ->Field("Shadow Bias", &AreaLightComponentConfig::m_bias)
  35. ->Field("Normal Shadow Bias", &AreaLightComponentConfig::m_normalShadowBias)
  36. ->Field("Shadowmap Max Size", &AreaLightComponentConfig::m_shadowmapMaxSize)
  37. ->Field("Shadow Filter Method", &AreaLightComponentConfig::m_shadowFilterMethod)
  38. ->Field("Filtering Sample Count", &AreaLightComponentConfig::m_filteringSampleCount)
  39. ->Field("Esm Exponent", &AreaLightComponentConfig::m_esmExponent)
  40. ->Field("Shadow Caching Mode", &AreaLightComponentConfig::m_shadowCachingMode)
  41. ->Field("Shadow Caching Enabled", &AreaLightComponentConfig::m_cacheShadows) // temporary attribute that is used for edit context but ignored in serialize context.
  42. // Global Illumination
  43. ->Field("Affects GI", &AreaLightComponentConfig::m_affectsGI)
  44. ->Field("Affects GI Factor", &AreaLightComponentConfig::m_affectsGIFactor)
  45. ;
  46. }
  47. }
  48. AZStd::vector<Edit::EnumConstant<PhotometricUnit>> AreaLightComponentConfig::GetValidPhotometricUnits() const
  49. {
  50. AZStd::vector<Edit::EnumConstant<PhotometricUnit>> enumValues =
  51. {
  52. // Candela & lumen always supported.
  53. Edit::EnumConstant<PhotometricUnit>(PhotometricUnit::Candela, "Candela"),
  54. Edit::EnumConstant<PhotometricUnit>(PhotometricUnit::Lumen, "Lumen"),
  55. };
  56. if (RequiresShapeComponent())
  57. {
  58. // Lights with surface area also support nits and ev100.
  59. enumValues.push_back(Edit::EnumConstant<PhotometricUnit>(PhotometricUnit::Nit, "Nit"));
  60. enumValues.push_back(Edit::EnumConstant<PhotometricUnit>(PhotometricUnit::Ev100Luminance, "Ev100"));
  61. }
  62. return enumValues;
  63. }
  64. bool AreaLightComponentConfig::RequiresShapeComponent() const
  65. {
  66. return m_lightType == LightType::Sphere
  67. || m_lightType == LightType::SpotDisk
  68. || m_lightType == LightType::Capsule
  69. || m_lightType == LightType::Quad
  70. || m_lightType == LightType::Polygon;
  71. }
  72. bool AreaLightComponentConfig::LightTypeIsSelected() const
  73. {
  74. return m_lightType != LightType::Unknown;
  75. }
  76. bool AreaLightComponentConfig::IsAttenuationRadiusModeAutomatic() const
  77. {
  78. return m_attenuationRadiusMode == LightAttenuationRadiusMode::Automatic;
  79. }
  80. bool AreaLightComponentConfig::SupportsBothDirections() const
  81. {
  82. return m_lightType == LightType::Quad
  83. || m_lightType == LightType::Polygon;
  84. }
  85. bool AreaLightComponentConfig::SupportsFastApproximation() const
  86. {
  87. return m_lightType == LightType::Quad;
  88. }
  89. bool AreaLightComponentConfig::SupportsShutters() const
  90. {
  91. return m_lightType == LightType::SimpleSpot
  92. || m_lightType == LightType::SpotDisk;
  93. }
  94. bool AreaLightComponentConfig::ShuttersMustBeEnabled() const
  95. {
  96. return m_lightType == LightType::SpotDisk;
  97. }
  98. bool AreaLightComponentConfig::ShuttersDisabled() const
  99. {
  100. return m_lightType == LightType::SpotDisk && !m_enableShutters;
  101. }
  102. bool AreaLightComponentConfig::SupportsShadows() const
  103. {
  104. return m_lightType == LightType::SpotDisk || m_lightType == LightType::Sphere;
  105. }
  106. bool AreaLightComponentConfig::SupportsAffectsGI() const
  107. {
  108. return m_lightType == LightType::Sphere
  109. || m_lightType == LightType::SpotDisk
  110. || m_lightType == LightType::Capsule
  111. || m_lightType == LightType::Quad
  112. || m_lightType == LightType::SimplePoint
  113. || m_lightType == LightType::SimpleSpot;
  114. }
  115. bool AreaLightComponentConfig::ShadowsDisabled() const
  116. {
  117. return !m_enableShadow;
  118. }
  119. const char* AreaLightComponentConfig::GetIntensitySuffix() const
  120. {
  121. return PhotometricValue::GetTypeSuffix(m_intensityMode);
  122. }
  123. float AreaLightComponentConfig::GetIntensityMin() const
  124. {
  125. switch (m_intensityMode)
  126. {
  127. case PhotometricUnit::Candela:
  128. case PhotometricUnit::Lumen:
  129. case PhotometricUnit::Nit:
  130. return 0.0f;
  131. case PhotometricUnit::Ev100Luminance:
  132. return AZStd::numeric_limits<float>::lowest();
  133. }
  134. return 0.0f;
  135. }
  136. float AreaLightComponentConfig::GetIntensityMax() const
  137. {
  138. // While there is no hard-max, a max must be included when there is a hard min.
  139. return AZStd::numeric_limits<float>::max();
  140. }
  141. float AreaLightComponentConfig::GetIntensitySoftMin() const
  142. {
  143. switch (m_intensityMode)
  144. {
  145. case PhotometricUnit::Candela:
  146. case PhotometricUnit::Lumen:
  147. case PhotometricUnit::Nit:
  148. case PhotometricUnit::Ev100Luminance:
  149. return 0.0f;
  150. }
  151. return 0.0f;
  152. }
  153. float AreaLightComponentConfig::GetIntensitySoftMax() const
  154. {
  155. switch (m_intensityMode)
  156. {
  157. case PhotometricUnit::Candela:
  158. case PhotometricUnit::Lumen:
  159. case PhotometricUnit::Nit:
  160. return 1'000.0f;
  161. case PhotometricUnit::Ev100Luminance:
  162. return 16.0f;
  163. }
  164. return 0.0f;
  165. }
  166. bool AreaLightComponentConfig::IsShadowFilteringDisabled() const
  167. {
  168. return (m_shadowFilterMethod == ShadowFilterMethod::None);
  169. }
  170. bool AreaLightComponentConfig::IsShadowPcfDisabled() const
  171. {
  172. return ShadowsDisabled() || !(m_shadowFilterMethod == ShadowFilterMethod::Pcf ||
  173. m_shadowFilterMethod == ShadowFilterMethod::EsmPcf);
  174. }
  175. bool AreaLightComponentConfig::IsEsmDisabled() const
  176. {
  177. return ShadowsDisabled() ||
  178. !(m_shadowFilterMethod == ShadowFilterMethod::Esm || m_shadowFilterMethod == ShadowFilterMethod::EsmPcf);
  179. }
  180. }
  181. }