浏览代码

handle shape translation offsets in diffuse probe grid

Signed-off-by: greerdv <[email protected]>
greerdv 2 年之前
父节点
当前提交
04ea7ab47e

+ 23 - 2
Gems/DiffuseProbeGrid/Code/Source/Components/DiffuseProbeGridComponentController.cpp

@@ -141,7 +141,9 @@ namespace AZ
 
             // add this diffuse probe grid to the feature processor
             const AZ::Transform& transform = m_transformInterface->GetWorldTM();
-            m_handle = m_featureProcessor->AddProbeGrid(transform, m_configuration.m_extents, m_configuration.m_probeSpacing);
+
+            m_handle = m_featureProcessor->AddProbeGrid(
+                ComputeOverallTransform(transform), m_configuration.m_extents, m_configuration.m_probeSpacing);
 
             m_featureProcessor->SetAmbientMultiplier(m_handle, m_configuration.m_ambientMultiplier);
             m_featureProcessor->SetViewBias(m_handle, m_configuration.m_viewBias);
@@ -251,7 +253,7 @@ namespace AZ
                 return;
             }
 
-            m_featureProcessor->SetTransform(m_handle, world);
+            m_featureProcessor->SetTransform(m_handle, ComputeOverallTransform(world));
         }
 
         void DiffuseProbeGridComponentController::OnShapeChanged(ShapeChangeReasons changeReason)
@@ -284,6 +286,9 @@ namespace AZ
                     m_boxShapeInterface->SetBoxDimensions(m_configuration.m_extents);
                     m_boxChangedByGridEvent.Signal(true);
                 }
+
+                // the shape translation offset may have changed, which would affect the overall transform
+                m_featureProcessor->SetTransform(m_handle, ComputeOverallTransform(m_transformInterface->GetWorldTM()));
             }
 
             m_inShapeChangeHandler = false;
@@ -486,5 +491,21 @@ namespace AZ
 
            m_featureProcessor->SetBakedTextures(m_handle, bakedTextures);
         }
+
+        AZ::Transform DiffuseProbeGridComponentController::ComputeOverallTransform(const AZ::Transform& entityTransform) const
+        {
+            const bool isTypeAxisAligned = m_boxShapeInterface ? m_boxShapeInterface->IsTypeAxisAligned() : false;
+            const AZ::Vector3 translationOffset = m_shapeBus ? m_shapeBus->GetTranslationOffset() : AZ::Vector3::CreateZero();
+            const AZ::Transform translationOffsetTransform = AZ::Transform::CreateTranslation(translationOffset);
+
+            if (isTypeAxisAligned)
+            {
+                AZ::Transform entityTransformNoRotation = entityTransform;
+                entityTransformNoRotation.SetRotation(AZ::Quaternion::CreateIdentity());
+                return entityTransformNoRotation * translationOffsetTransform;
+            }
+
+            return entityTransform * translationOffsetTransform;
+        }
     } // namespace Render
 } // namespace AZ

+ 3 - 0
Gems/DiffuseProbeGrid/Code/Source/Components/DiffuseProbeGridComponentController.h

@@ -126,6 +126,9 @@ namespace AZ
             // Update the baked texture assets from the configuration
             void UpdateBakedTextures();
 
+            // Computes the effective transform taking both the entity transform and the shape translation offset into account
+            AZ::Transform ComputeOverallTransform(const AZ::Transform& entityTransform) const;
+
             // box shape component, used for defining the outer extents of the probe area
             LmbrCentral::BoxShapeComponentRequests* m_boxShapeInterface = nullptr;
             LmbrCentral::ShapeComponentRequests* m_shapeBus = nullptr;