123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #include <CoreLights/SphereLightDelegate.h>
- #include <Atom/RPI.Public/Scene.h>
- #include <Atom/Feature/CoreLights/PointLightFeatureProcessorInterface.h>
- #include <AtomLyIntegration/CommonFeatures/CoreLights/AreaLightComponentConfig.h>
- namespace AZ::Render
- {
- SphereLightDelegate::SphereLightDelegate(LmbrCentral::SphereShapeComponentRequests* shapeBus, EntityId entityId, bool isVisible)
- : LightDelegateBase<PointLightFeatureProcessorInterface>(entityId, isVisible)
- , m_sphereShapeBus(shapeBus)
- {
- InitBase(entityId);
- }
- float SphereLightDelegate::CalculateAttenuationRadius(float lightThreshold) const
- {
- // Calculate the radius at which the irradiance will be equal to cutoffIntensity.
- float intensity = GetPhotometricValue().GetCombinedIntensity(PhotometricUnit::Lumen);
- return sqrt(intensity / lightThreshold);
- }
-
- void SphereLightDelegate::HandleShapeChanged()
- {
- if (GetLightHandle().IsValid())
- {
- GetFeatureProcessor()->SetPosition(GetLightHandle(), GetTransform().GetTranslation());
- GetFeatureProcessor()->SetBulbRadius(GetLightHandle(), GetRadius());
- }
- }
- float SphereLightDelegate::GetSurfaceArea() const
- {
- float radius = GetRadius();
- return 4.0f * Constants::Pi * radius * radius;
- }
- float SphereLightDelegate::GetRadius() const
- {
- return m_sphereShapeBus->GetRadius() * GetTransform().GetUniformScale();
- }
- void SphereLightDelegate::DrawDebugDisplay(const Transform& transform, const Color& color, AzFramework::DebugDisplayRequests& debugDisplay, bool isSelected) const
- {
- if (isSelected)
- {
- debugDisplay.SetColor(color);
-
- // Draw a sphere for the attenuation radius
- debugDisplay.DrawWireSphere(transform.GetTranslation(), GetConfig()->m_attenuationRadius);
- }
- }
- void SphereLightDelegate::SetEnableShadow(bool enabled)
- {
- Base::SetEnableShadow(enabled);
- if (GetLightHandle().IsValid())
- {
- GetFeatureProcessor()->SetShadowsEnabled(GetLightHandle(), enabled);
- }
- }
-
- void SphereLightDelegate::SetShadowBias(float bias)
- {
- if (GetShadowsEnabled() && GetLightHandle().IsValid())
- {
- GetFeatureProcessor()->SetShadowBias(GetLightHandle(), bias);
- }
- }
- void SphereLightDelegate::SetShadowmapMaxSize(ShadowmapSize size)
- {
- if (GetShadowsEnabled() && GetLightHandle().IsValid())
- {
- GetFeatureProcessor()->SetShadowmapMaxResolution(GetLightHandle(), size);
- }
- }
- void SphereLightDelegate::SetShadowFilterMethod(ShadowFilterMethod method)
- {
- if (GetShadowsEnabled() && GetLightHandle().IsValid())
- {
- GetFeatureProcessor()->SetShadowFilterMethod(GetLightHandle(), method);
- }
- }
- void SphereLightDelegate::SetFilteringSampleCount(uint32_t count)
- {
- if (GetShadowsEnabled() && GetLightHandle().IsValid())
- {
- GetFeatureProcessor()->SetFilteringSampleCount(GetLightHandle(), static_cast<uint16_t>(count));
- }
- }
- void SphereLightDelegate::SetEsmExponent(float esmExponent)
- {
- if (GetShadowsEnabled() && GetLightHandle().IsValid())
- {
- GetFeatureProcessor()->SetEsmExponent(GetLightHandle(), esmExponent);
- }
- }
- void SphereLightDelegate::SetNormalShadowBias(float bias)
- {
- if (GetShadowsEnabled() && GetLightHandle().IsValid())
- {
- GetFeatureProcessor()->SetNormalShadowBias(GetLightHandle(), bias);
- }
- }
- void SphereLightDelegate::SetShadowCachingMode(AreaLightComponentConfig::ShadowCachingMode cachingMode)
- {
- if (GetShadowsEnabled() && GetLightHandle().IsValid())
- {
- GetFeatureProcessor()->SetUseCachedShadows(GetLightHandle(),
- cachingMode == AreaLightComponentConfig::ShadowCachingMode::UpdateOnChange);
- }
- }
- void SphereLightDelegate::SetAffectsGI(bool affectsGI)
- {
- if (GetLightHandle().IsValid())
- {
- GetFeatureProcessor()->SetAffectsGI(GetLightHandle(), affectsGI);
- }
- }
- void SphereLightDelegate::SetAffectsGIFactor(float affectsGIFactor)
- {
- if (GetLightHandle().IsValid())
- {
- GetFeatureProcessor()->SetAffectsGIFactor(GetLightHandle(), affectsGIFactor);
- }
- }
- Aabb SphereLightDelegate::GetLocalVisualizationBounds() const
- {
- const AZ::Vector3 translationOffset = m_shapeBus ? m_shapeBus->GetTranslationOffset() : AZ::Vector3::CreateZero();
- return Aabb::CreateCenterRadius(translationOffset, GetConfig()->m_attenuationRadius);
- }
- } // namespace AZ::Render
|