3
0

QuadLightDelegate.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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/RPI.Public/Scene.h>
  9. #include <AtomLyIntegration/CommonFeatures/CoreLights/AreaLightComponentConfig.h>
  10. #include <CoreLights/QuadLightDelegate.h>
  11. namespace AZ::Render
  12. {
  13. QuadLightDelegate::QuadLightDelegate(LmbrCentral::QuadShapeComponentRequests* shapeBus, EntityId entityId, bool isVisible)
  14. : LightDelegateBase<QuadLightFeatureProcessorInterface>(entityId, isVisible)
  15. , m_shapeBus(shapeBus)
  16. {
  17. InitBase(entityId);
  18. }
  19. void QuadLightDelegate::SetLightEmitsBothDirections(bool lightEmitsBothDirections)
  20. {
  21. if (GetLightHandle().IsValid())
  22. {
  23. GetFeatureProcessor()->SetLightEmitsBothDirections(GetLightHandle(), lightEmitsBothDirections);
  24. }
  25. }
  26. void QuadLightDelegate::SetUseFastApproximation(bool useFastApproximation)
  27. {
  28. if (GetLightHandle().IsValid())
  29. {
  30. GetFeatureProcessor()->SetUseFastApproximation(GetLightHandle(), useFastApproximation);
  31. }
  32. }
  33. float QuadLightDelegate::CalculateAttenuationRadius(float lightThreshold) const
  34. {
  35. // Calculate the radius at which the irradiance will be equal to cutoffIntensity.
  36. const float intensity = GetPhotometricValue().GetCombinedIntensity(PhotometricUnit::Lumen);
  37. return Sqrt(intensity / lightThreshold);
  38. }
  39. void QuadLightDelegate::HandleShapeChanged()
  40. {
  41. if (GetLightHandle().IsValid())
  42. {
  43. GetFeatureProcessor()->SetPosition(GetLightHandle(), GetTransform().GetTranslation());
  44. GetFeatureProcessor()->SetOrientation(GetLightHandle(), m_shapeBus->GetQuadOrientation());
  45. GetFeatureProcessor()->SetQuadDimensions(GetLightHandle(), GetWidth(), GetHeight());
  46. }
  47. }
  48. float QuadLightDelegate::GetSurfaceArea() const
  49. {
  50. return GetWidth() * GetHeight();
  51. }
  52. void QuadLightDelegate::DrawDebugDisplay(
  53. const Transform& transform, const Color& color, AzFramework::DebugDisplayRequests& debugDisplay, bool isSelected) const
  54. {
  55. if (isSelected)
  56. {
  57. debugDisplay.SetColor(color);
  58. // Draw a quad for the attenuation radius
  59. debugDisplay.DrawWireSphere(transform.GetTranslation(), GetConfig()->m_attenuationRadius);
  60. }
  61. }
  62. float QuadLightDelegate::GetWidth() const
  63. {
  64. return m_shapeBus->GetQuadWidth() * GetTransform().GetUniformScale();
  65. }
  66. float QuadLightDelegate::GetHeight() const
  67. {
  68. return m_shapeBus->GetQuadHeight() * GetTransform().GetUniformScale();
  69. }
  70. void QuadLightDelegate::SetAffectsGI(bool affectsGI)
  71. {
  72. if (GetLightHandle().IsValid())
  73. {
  74. GetFeatureProcessor()->SetAffectsGI(GetLightHandle(), affectsGI);
  75. }
  76. }
  77. void QuadLightDelegate::SetAffectsGIFactor(float affectsGIFactor)
  78. {
  79. if (GetLightHandle().IsValid())
  80. {
  81. GetFeatureProcessor()->SetAffectsGIFactor(GetLightHandle(), affectsGIFactor);
  82. }
  83. }
  84. Aabb QuadLightDelegate::GetLocalVisualizationBounds() const
  85. {
  86. return Aabb::CreateCenterRadius(Vector3::CreateZero(), GetConfig()->m_attenuationRadius);
  87. }
  88. } // namespace AZ::Render