AreaLightComponentConfig.cpp 8.7 KB

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