SimplePointLightDelegate.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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/SimplePointLightFeatureProcessorInterface.h>
  9. #include <Atom/RPI.Public/Scene.h>
  10. #include <AtomLyIntegration/CommonFeatures/CoreLights/AreaLightComponentConfig.h>
  11. #include <CoreLights/SimplePointLightDelegate.h>
  12. namespace AZ::Render
  13. {
  14. SimplePointLightDelegate::SimplePointLightDelegate(EntityId entityId, bool isVisible)
  15. : LightDelegateBase<SimplePointLightFeatureProcessorInterface>(entityId, isVisible)
  16. {
  17. InitBase(entityId);
  18. if (GetLightHandle().IsValid())
  19. {
  20. GetFeatureProcessor()->SetPosition(GetLightHandle(), GetTransform().GetTranslation());
  21. }
  22. }
  23. float SimplePointLightDelegate::CalculateAttenuationRadius(float lightThreshold) const
  24. {
  25. // Calculate the radius at which the irradiance will be equal to cutoffIntensity.
  26. const float intensity = GetPhotometricValue().GetCombinedIntensity(PhotometricUnit::Lumen);
  27. return Sqrt(intensity / lightThreshold);
  28. }
  29. float SimplePointLightDelegate::GetSurfaceArea() const
  30. {
  31. return 0.0f;
  32. }
  33. void SimplePointLightDelegate::HandleShapeChanged()
  34. {
  35. if (GetLightHandle().IsValid())
  36. {
  37. GetFeatureProcessor()->SetPosition(GetLightHandle(), GetTransform().GetTranslation());
  38. }
  39. }
  40. void SimplePointLightDelegate::DrawDebugDisplay(
  41. const Transform& transform, const Color& color, AzFramework::DebugDisplayRequests& debugDisplay, bool isSelected) const
  42. {
  43. if (isSelected)
  44. {
  45. debugDisplay.SetColor(color);
  46. // Draw a sphere for the attenuation radius
  47. debugDisplay.DrawWireSphere(transform.GetTranslation(), GetConfig()->m_attenuationRadius);
  48. }
  49. }
  50. void SimplePointLightDelegate::SetAffectsGI(bool affectsGI)
  51. {
  52. if (GetLightHandle().IsValid())
  53. {
  54. GetFeatureProcessor()->SetAffectsGI(GetLightHandle(), affectsGI);
  55. }
  56. }
  57. void SimplePointLightDelegate::SetAffectsGIFactor(float affectsGIFactor)
  58. {
  59. if (GetLightHandle().IsValid())
  60. {
  61. GetFeatureProcessor()->SetAffectsGIFactor(GetLightHandle(), affectsGIFactor);
  62. }
  63. }
  64. Aabb SimplePointLightDelegate::GetLocalVisualizationBounds() const
  65. {
  66. return Aabb::CreateCenterRadius(Vector3::CreateZero(), GetConfig()->m_attenuationRadius);
  67. }
  68. } // namespace AZ::Render