From d31200ee5cf220056a61d5630be26de4b4f9a600 Mon Sep 17 00:00:00 2001 From: Benjamin Jillich <43751992+amzn-jillich@users.noreply.github.com> Date: Mon, 21 Feb 2022 08:51:53 +0100 Subject: [PATCH] EMotion FX: Update skeleton transforms when either solid mesh rendering or any of the debug visualizations is enabled (#7747) * Disabled depth testing for joint orientation debug rendering, so that we can also see them through the solid mesh rendering. * Update transforms in case solid mesh rendering or any of the debug visualizations are enabled. Signed-off-by: Benjamin Jillich --- .../EMotionFXAtom/Code/Source/AtomActorDebugDraw.cpp | 5 +++++ .../Source/Integration/Components/ActorComponent.cpp | 9 ++++++--- .../Code/Source/Integration/Rendering/RenderFlag.h | 8 ++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorDebugDraw.cpp b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorDebugDraw.cpp index 00e7f12fe9..1e74bc264a 100644 --- a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorDebugDraw.cpp +++ b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorDebugDraw.cpp @@ -758,6 +758,9 @@ namespace AZ::Render EMotionFX::JointSelectionRequestBus::BroadcastResult( cachedSelectedJointIndices, &EMotionFX::JointSelectionRequests::FindSelectedJointIndices, actorInstance); + const int oldState = debugDisplay->GetState(); + debugDisplay->DepthTestOff(); + const size_t numEnabled = actorInstance->GetNumEnabledNodes(); for (size_t i = 0; i < numEnabled; ++i) { @@ -774,6 +777,8 @@ namespace AZ::Render } RenderLineAxis(debugDisplay, worldTM, size, selected); } + + debugDisplay->SetState(oldState); } void AtomActorDebugDraw::RenderLineAxis( diff --git a/Gems/EMotionFX/Code/Source/Integration/Components/ActorComponent.cpp b/Gems/EMotionFX/Code/Source/Integration/Components/ActorComponent.cpp index a44882694f..be7e99eaaf 100644 --- a/Gems/EMotionFX/Code/Source/Integration/Components/ActorComponent.cpp +++ b/Gems/EMotionFX/Code/Source/Integration/Components/ActorComponent.cpp @@ -569,17 +569,20 @@ namespace EMotionFX m_renderActorInstance->OnTick(deltaTime); m_renderActorInstance->UpdateBounds(); AZ::Interface::Get()->RefreshEntityLocalBoundsUnion(GetEntityId()); + + const bool isInCameraFrustum = m_renderActorInstance->IsInCameraFrustum(); const bool renderActorSolid = AZ::RHI::CheckBitsAny(m_configuration.m_renderFlags, ActorRenderFlags::Solid); + m_renderActorInstance->SetIsVisible(isInCameraFrustum && renderActorSolid); // Optimization: Set the actor instance invisible when character is out of camera view. This will stop the joint transforms update, except the root joint. // Calling it after the bounds on the render actor updated. if (!m_configuration.m_forceUpdateJointsOOV) { - const bool isInCameraFrustum = m_renderActorInstance->IsInCameraFrustum(); - m_actorInstance->SetIsVisible(isInCameraFrustum && renderActorSolid); + // Update the skeleton in case solid mesh rendering or any of the debug visualizations are enabled and the character is in the camera frustum. + const bool updateTransforms = AZ::RHI::CheckBitsAny(m_configuration.m_renderFlags, s_requireUpdateTransforms); + m_actorInstance->SetIsVisible(isInCameraFrustum && updateTransforms); } - m_renderActorInstance->SetIsVisible(renderActorSolid); m_renderActorInstance->DebugDraw(m_configuration.m_renderFlags); } } diff --git a/Gems/EMotionFX/Code/Source/Integration/Rendering/RenderFlag.h b/Gems/EMotionFX/Code/Source/Integration/Rendering/RenderFlag.h index 4640fdfcb1..767c1d8ab7 100644 --- a/Gems/EMotionFX/Code/Source/Integration/Rendering/RenderFlag.h +++ b/Gems/EMotionFX/Code/Source/Integration/Rendering/RenderFlag.h @@ -75,6 +75,14 @@ namespace EMotionFX AZ_DEFINE_ENUM_BITWISE_OPERATORS(ActorRenderFlags); + static constexpr ActorRenderFlags s_requireUpdateTransforms = + ActorRenderFlags::Solid | ActorRenderFlags::Wireframe | ActorRenderFlags::AABB | + ActorRenderFlags::FaceNormals |ActorRenderFlags::VertexNormals | ActorRenderFlags::Tangents | + ActorRenderFlags::Skeleton | ActorRenderFlags::LineSkeleton | ActorRenderFlags::NodeOrientation | ActorRenderFlags::NodeNames | + ActorRenderFlags::RagdollColliders | ActorRenderFlags::RagdollJointLimits | ActorRenderFlags::HitDetectionColliders | + ActorRenderFlags::ClothColliders | ActorRenderFlags::SimulatedObjectColliders | ActorRenderFlags::SimulatedJoints | + ActorRenderFlags::EmfxDebug; + class ActorRenderFlagUtil { public: