From 738883a9b07b855d4e0f7ed81a433b2601e8e83f Mon Sep 17 00:00:00 2001 From: Michael Riegger Date: Fri, 30 Apr 2021 11:43:32 -0700 Subject: [PATCH] Kens feedback --- .../CoreLights/PointLightFeatureProcessor.cpp | 4 +++- .../Source/CoreLights/SphereLightDelegate.cpp | 18 +++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Gems/Atom/Feature/Common/Code/Source/CoreLights/PointLightFeatureProcessor.cpp b/Gems/Atom/Feature/Common/Code/Source/CoreLights/PointLightFeatureProcessor.cpp index 5110674492..82f41afbee 100644 --- a/Gems/Atom/Feature/Common/Code/Source/CoreLights/PointLightFeatureProcessor.cpp +++ b/Gems/Atom/Feature/Common/Code/Source/CoreLights/PointLightFeatureProcessor.cpp @@ -231,6 +231,8 @@ namespace AZ void PointLightFeatureProcessor::UpdateShadow(LightHandle handle) { + constexpr float SqrtHalf = 0.707106781187f; // sqrt(0.5); + const auto& pointLight = m_pointLightData.GetData(handle.GetIndex()); for (int i = 0; i < PointLightData::NumShadowFaces; ++i) { @@ -246,7 +248,7 @@ namespace AZ desc.m_transform = m_pointShadowTransforms[i]; desc.m_transform.SetTranslation(pointLight.m_position[0], pointLight.m_position[1], pointLight.m_position[2]); desc.m_aspectRatio = 1.0f; - desc.m_nearPlaneDistance = 0.0f; + desc.m_nearPlaneDistance = SqrtHalf * pointLight.m_bulbRadius; const float invRadiusSquared = pointLight.m_invAttenuationRadiusSquared; if (invRadiusSquared <= 0.f) diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/CoreLights/SphereLightDelegate.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/CoreLights/SphereLightDelegate.cpp index 7a74ad4c5c..e3cf1fac78 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/CoreLights/SphereLightDelegate.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/CoreLights/SphereLightDelegate.cpp @@ -67,12 +67,16 @@ namespace AZ void SphereLightDelegate::SetEnableShadow(bool enabled) { Base::SetEnableShadow(enabled); - GetFeatureProcessor()->SetShadowsEnabled(GetLightHandle(), enabled); + + if (GetLightHandle().IsValid()) + { + GetFeatureProcessor()->SetShadowsEnabled(GetLightHandle(), enabled); + } } void SphereLightDelegate::SetShadowmapMaxSize(ShadowmapSize size) { - if (GetShadowsEnabled()) + if (GetShadowsEnabled() && GetLightHandle().IsValid()) { GetFeatureProcessor()->SetShadowmapMaxResolution(GetLightHandle(), size); } @@ -80,7 +84,7 @@ namespace AZ void SphereLightDelegate::SetShadowFilterMethod(ShadowFilterMethod method) { - if (GetShadowsEnabled()) + if (GetShadowsEnabled() && GetLightHandle().IsValid()) { GetFeatureProcessor()->SetShadowFilterMethod(GetLightHandle(), method); } @@ -88,7 +92,7 @@ namespace AZ void SphereLightDelegate::SetSofteningBoundaryWidthAngle(float widthInDegrees) { - if (GetShadowsEnabled()) + if (GetShadowsEnabled() && GetLightHandle().IsValid()) { GetFeatureProcessor()->SetSofteningBoundaryWidthAngle(GetLightHandle(), DegToRad(widthInDegrees)); } @@ -96,7 +100,7 @@ namespace AZ void SphereLightDelegate::SetPredictionSampleCount(uint32_t count) { - if (GetShadowsEnabled()) + if (GetShadowsEnabled() && GetLightHandle().IsValid()) { GetFeatureProcessor()->SetPredictionSampleCount(GetLightHandle(), count); } @@ -104,7 +108,7 @@ namespace AZ void SphereLightDelegate::SetFilteringSampleCount(uint32_t count) { - if (GetShadowsEnabled()) + if (GetShadowsEnabled() && GetLightHandle().IsValid()) { GetFeatureProcessor()->SetFilteringSampleCount(GetLightHandle(), count); } @@ -112,7 +116,7 @@ namespace AZ void SphereLightDelegate::SetPcfMethod(PcfMethod method) { - if (GetShadowsEnabled()) + if (GetShadowsEnabled() && GetLightHandle().IsValid()) { GetFeatureProcessor()->SetPcfMethod(GetLightHandle(), method); }