From 186066edc101dcb660de65736f1884d9d9561e3b Mon Sep 17 00:00:00 2001 From: pruiksma Date: Wed, 28 Apr 2021 20:36:35 -0500 Subject: [PATCH] [ATOM-15380] Cherry picking changes from 1.0 - cfdb70978868aa5d0040d3b79994a26e9f82ca39 --- [ATOM-15380] Fix cases where light delegates will attempt to set properties on the feature processor without having a valid handle. --- .../Source/CoreLights/DiskLightDelegate.cpp | 25 ++++++++++++------- .../CoreLights/SimplePointLightDelegate.cpp | 10 ++++++-- .../CoreLights/SimpleSpotLightDelegate.cpp | 12 ++++++--- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/CoreLights/DiskLightDelegate.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/CoreLights/DiskLightDelegate.cpp index 54babd3bc1..7805a92cd1 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/CoreLights/DiskLightDelegate.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/CoreLights/DiskLightDelegate.cpp @@ -103,12 +103,15 @@ namespace AZ::Render void DiskLightDelegate::SetEnableShutters(bool enabled) { Base::SetEnableShutters(enabled); - GetFeatureProcessor()->SetConstrainToConeLight(GetLightHandle(), true); + if (GetLightHandle().IsValid()) + { + GetFeatureProcessor()->SetConstrainToConeLight(GetLightHandle(), true); + } } void DiskLightDelegate::SetShutterAngles(float innerAngleDegrees, float outerAngleDegrees) { - if (GetShuttersEnabled()) + if (GetShuttersEnabled() && GetLightHandle().IsValid()) { GetFeatureProcessor()->SetConeAngles(GetLightHandle(), DegToRad(innerAngleDegrees), DegToRad(outerAngleDegrees)); } @@ -117,12 +120,16 @@ namespace AZ::Render void DiskLightDelegate::SetEnableShadow(bool enabled) { Base::SetEnableShadow(enabled); - GetFeatureProcessor()->SetShadowsEnabled(GetLightHandle(), enabled); + + if (GetLightHandle().IsValid()) + { + GetFeatureProcessor()->SetShadowsEnabled(GetLightHandle(), enabled); + } } void DiskLightDelegate::SetShadowmapMaxSize(ShadowmapSize size) { - if (GetShadowsEnabled()) + if (GetShadowsEnabled() && GetLightHandle().IsValid()) { GetFeatureProcessor()->SetShadowmapMaxResolution(GetLightHandle(), size); } @@ -130,7 +137,7 @@ namespace AZ::Render void DiskLightDelegate::SetShadowFilterMethod(ShadowFilterMethod method) { - if (GetShadowsEnabled()) + if (GetShadowsEnabled() && GetLightHandle().IsValid()) { GetFeatureProcessor()->SetShadowFilterMethod(GetLightHandle(), method); } @@ -138,7 +145,7 @@ namespace AZ::Render void DiskLightDelegate::SetSofteningBoundaryWidthAngle(float widthInDegrees) { - if (GetShadowsEnabled()) + if (GetShadowsEnabled() && GetLightHandle().IsValid()) { GetFeatureProcessor()->SetSofteningBoundaryWidthAngle(GetLightHandle(), DegToRad(widthInDegrees)); } @@ -146,7 +153,7 @@ namespace AZ::Render void DiskLightDelegate::SetPredictionSampleCount(uint32_t count) { - if (GetShadowsEnabled()) + if (GetShadowsEnabled() && GetLightHandle().IsValid()) { GetFeatureProcessor()->SetPredictionSampleCount(GetLightHandle(), count); } @@ -154,7 +161,7 @@ namespace AZ::Render void DiskLightDelegate::SetFilteringSampleCount(uint32_t count) { - if (GetShadowsEnabled()) + if (GetShadowsEnabled() && GetLightHandle().IsValid()) { GetFeatureProcessor()->SetFilteringSampleCount(GetLightHandle(), count); } @@ -162,7 +169,7 @@ namespace AZ::Render void DiskLightDelegate::SetPcfMethod(PcfMethod method) { - if (GetShadowsEnabled()) + if (GetShadowsEnabled() && GetLightHandle().IsValid()) { GetFeatureProcessor()->SetPcfMethod(GetLightHandle(), method); } diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/CoreLights/SimplePointLightDelegate.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/CoreLights/SimplePointLightDelegate.cpp index a2a24c3055..073b74d4bc 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/CoreLights/SimplePointLightDelegate.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/CoreLights/SimplePointLightDelegate.cpp @@ -23,7 +23,10 @@ namespace AZ : LightDelegateBase(entityId, isVisible) { InitBase(entityId); - GetFeatureProcessor()->SetPosition(GetLightHandle(), GetTransform().GetTranslation()); + if (GetLightHandle().IsValid()) + { + GetFeatureProcessor()->SetPosition(GetLightHandle(), GetTransform().GetTranslation()); + } } float SimplePointLightDelegate::CalculateAttenuationRadius(float lightThreshold) const { @@ -39,7 +42,10 @@ namespace AZ void SimplePointLightDelegate::HandleShapeChanged() { - GetFeatureProcessor()->SetPosition(GetLightHandle(), GetTransform().GetTranslation()); + if (GetLightHandle().IsValid()) + { + GetFeatureProcessor()->SetPosition(GetLightHandle(), GetTransform().GetTranslation()); + } } void SimplePointLightDelegate::DrawDebugDisplay(const Transform& transform, const Color& color, AzFramework::DebugDisplayRequests& debugDisplay, bool isSelected) const diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/CoreLights/SimpleSpotLightDelegate.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/CoreLights/SimpleSpotLightDelegate.cpp index 705a71571a..5ce8f6d563 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/CoreLights/SimpleSpotLightDelegate.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/CoreLights/SimpleSpotLightDelegate.cpp @@ -24,8 +24,11 @@ namespace AZ::Render void SimpleSpotLightDelegate::HandleShapeChanged() { - GetFeatureProcessor()->SetPosition(GetLightHandle(), GetTransform().GetTranslation()); - GetFeatureProcessor()->SetDirection(GetLightHandle(), GetTransform().GetBasisZ()); + if (GetLightHandle().IsValid()) + { + GetFeatureProcessor()->SetPosition(GetLightHandle(), GetTransform().GetTranslation()); + GetFeatureProcessor()->SetDirection(GetLightHandle(), GetTransform().GetBasisZ()); + } } float SimpleSpotLightDelegate::CalculateAttenuationRadius(float lightThreshold) const @@ -42,7 +45,10 @@ namespace AZ::Render void SimpleSpotLightDelegate::SetShutterAngles(float innerAngleDegrees, float outerAngleDegrees) { - GetFeatureProcessor()->SetConeAngles(GetLightHandle(), DegToRad(innerAngleDegrees), DegToRad(outerAngleDegrees)); + if (GetLightHandle().IsValid()) + { + GetFeatureProcessor()->SetConeAngles(GetLightHandle(), DegToRad(innerAngleDegrees), DegToRad(outerAngleDegrees)); + } } void SimpleSpotLightDelegate::DrawDebugDisplay(const Transform& transform, const Color& /*color*/, AzFramework::DebugDisplayRequests& debugDisplay, bool isSelected) const