p.Chaos.SmoothedPositionLerpRate
p.Chaos.SmoothedPositionLerpRate
#Overview
name: p.Chaos.SmoothedPositionLerpRate
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
The interpolation rate for the smoothed position calculation. Used for sleeping.
It is referenced in 7
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of p.Chaos.SmoothedPositionLerpRate is to control the interpolation rate for the smoothed position calculation, which is used for sleeping in the Chaos physics system of Unreal Engine 5.
This setting variable is primarily used in the Chaos physics system, which is part of the Experimental module in Unreal Engine 5. It is specifically utilized in the rigid body dynamics and island management components of the physics simulation.
The value of this variable is set through a console variable (CVar) system, allowing it to be adjusted at runtime. It is initialized with a default value of 0.3f.
The associated variable SmoothedPositionLerpRate interacts directly with p.Chaos.SmoothedPositionLerpRate, sharing the same value. This variable is used in various parts of the physics simulation code to apply the smoothing effect.
Developers should be aware that this variable affects the sleeping behavior of rigid bodies in the physics simulation. A higher value will make the smoothed position update more quickly, while a lower value will result in a more gradual change.
Best practices when using this variable include:
- Keeping the value between 0.0 and 1.0, as it represents a lerp (linear interpolation) factor.
- Adjusting it carefully, as it can impact the performance and stability of the physics simulation.
- Testing different values to find the right balance between responsiveness and stability for your specific game scenarios.
Regarding the associated variable SmoothedPositionLerpRate:
The purpose of SmoothedPositionLerpRate is to store and provide access to the interpolation rate value within the Chaos physics code.
This variable is used in various parts of the Chaos physics system, particularly in the IslandManager and PBDRigidsEvolutionGBF classes.
The value of SmoothedPositionLerpRate is set by the p.Chaos.SmoothedPositionLerpRate console variable.
It interacts with various physics calculations, particularly those involving velocity smoothing and sleep state determination for rigid bodies.
Developers should be aware that this variable is used in performance-critical sections of the physics code, so any modifications to its usage should be done with care.
Best practices for using SmoothedPositionLerpRate include:
- Accessing it through the CVars namespace to ensure you’re using the most up-to-date value.
- Clamping its value between 0.0 and 1.0 when using it in calculations, as demonstrated in the provided code snippets.
- Consider the impact on both performance and simulation accuracy when adjusting this value.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDRigidsEvolutionGBF.cpp:57
Scope (from outer to inner):
file
namespace Chaos
namespace CVars
Source code excerpt:
FRealSingle SmoothedPositionLerpRate = 0.3f;
FAutoConsoleVariableRef CVarSmoothedPositionLerpRate(TEXT("p.Chaos.SmoothedPositionLerpRate"), SmoothedPositionLerpRate, TEXT("The interpolation rate for the smoothed position calculation. Used for sleeping."));
int DisableParticleUpdateVelocityParallelFor = 0;
FAutoConsoleVariableRef CVarDisableParticleUpdateVelocityParallelFor(TEXT("p.DisableParticleUpdateVelocityParallelFor"), DisableParticleUpdateVelocityParallelFor, TEXT("Disable Particle Update Velocity ParallelFor and run the update on a single thread"));
// NOTE: If we have mrope than 1 CCD iteration (ChaosCollisionCCDConstraintMaxProcessCount), the tight bounding box will cause us to miss secondary CCD collisions if the first one(s) result in a change in direction
bool bChaosCollisionCCDUseTightBoundingBox = true;
#Associated Variable and Callsites
This variable is associated with another variable named SmoothedPositionLerpRate
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Island/IslandManager.cpp:40
Scope (from outer to inner):
file
namespace Chaos::CVars
Source code excerpt:
extern int32 ChaosSolverCollisionVelocityShockPropagationIterations;
extern bool bChaosSolverPersistentGraph;
extern FRealSingle SmoothedPositionLerpRate;
bool bChaosConstraintGraphValidate = (CHAOS_CONSTRAINTGRAPH_CHECK_ENABLED != 0);
FAutoConsoleVariableRef CVarChaosConstraintGraphValidate(TEXT("p.Chaos.ConstraintGraph.Validate"), bChaosConstraintGraphValidate, TEXT("Enable per-tick ConstraintGraph validation checks/assertions"));
/** Cvar to enable/disable the island sleeping */
bool bChaosSolverSleepEnabled = true;
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Island/IslandManager.cpp:261
Scope (from outer to inner):
file
namespace Chaos::Private
function void UpdateParticleSleepMetrics
Source code excerpt:
if (Dt > UE_SMALL_NUMBER)
{
const FReal SmoothRate = FMath::Clamp(CVars::SmoothedPositionLerpRate, 0.0f, 1.0f);
const FVec3 VImp = FVec3::CalculateVelocity(Rigid.GetX(), Rigid.GetP(), Dt);
const FVec3 WImp = FRotation3::CalculateAngularVelocity(Rigid.GetR(), Rigid.GetQ(), Dt);
Rigid.SetVSmooth(FMath::Lerp(Rigid.VSmooth(), VImp, SmoothRate));
Rigid.SetWSmooth(FMath::Lerp(Rigid.WSmooth(), WImp, SmoothRate));
}
}
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDRigidsEvolutionGBF.cpp:56
Scope (from outer to inner):
file
namespace Chaos
namespace CVars
Source code excerpt:
FAutoConsoleVariableRef CVarDisableCulledContacts(TEXT("p.CollisionDisableCulledContacts"), CollisionDisableCulledContacts, TEXT("Allow the PBDRigidsEvolutionGBF collision constraints to throw out contacts mid solve if they are culled."));
FRealSingle SmoothedPositionLerpRate = 0.3f;
FAutoConsoleVariableRef CVarSmoothedPositionLerpRate(TEXT("p.Chaos.SmoothedPositionLerpRate"), SmoothedPositionLerpRate, TEXT("The interpolation rate for the smoothed position calculation. Used for sleeping."));
int DisableParticleUpdateVelocityParallelFor = 0;
FAutoConsoleVariableRef CVarDisableParticleUpdateVelocityParallelFor(TEXT("p.DisableParticleUpdateVelocityParallelFor"), DisableParticleUpdateVelocityParallelFor, TEXT("Disable Particle Update Velocity ParallelFor and run the update on a single thread"));
// NOTE: If we have mrope than 1 CCD iteration (ChaosCollisionCCDConstraintMaxProcessCount), the tight bounding box will cause us to miss secondary CCD collisions if the first one(s) result in a change in direction
bool bChaosCollisionCCDUseTightBoundingBox = true;
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDRigidsEvolutionGBF.cpp:1445
Scope (from outer to inner):
file
namespace Chaos
function void FPBDRigidsEvolutionGBF::OnParticleMoved
Source code excerpt:
const FReal InvDt = FReal(30.0);
const FVec3 DV = (PrevX - Rigid->GetX()) * InvDt;
const FReal SmoothRate = FMath::Clamp(CVars::SmoothedPositionLerpRate, 0.0f, 1.0f);
Rigid->VSmooth() = FMath::Lerp(Rigid->VSmooth(), Rigid->GetV() + DV, SmoothRate);
}
if (Rigid->IsSleeping())
{
SetParticleObjectState(Rigid, EObjectStateType::Dynamic);
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Public/Chaos/PBDRigidsEvolutionGBF.h:31
Scope (from outer to inner):
file
namespace Chaos
namespace CVars
Source code excerpt:
CHAOS_API extern FRealSingle HackMaxAngularVelocity;
CHAOS_API extern FRealSingle HackMaxVelocity;
CHAOS_API extern FRealSingle SmoothedPositionLerpRate;
CHAOS_API extern bool bChaosCollisionCCDUseTightBoundingBox;
CHAOS_API extern int32 ChaosCollisionCCDConstraintMaxProcessCount;
CHAOS_API extern int32 ChaosSolverDrawCCDThresholds;
}
using FPBDRigidsEvolutionCallback = TFunction<void(FReal Dt)>;
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Public/Chaos/PBDRigidsEvolutionGBF.h:241
Scope (from outer to inner):
file
namespace Chaos
class class FPBDRigidsEvolutionGBF : public FPBDRigidsEvolutionBase
function void ResetVSmoothFromForces
Source code excerpt:
void ResetVSmoothFromForces(TPBDRigidParticleHandleImp<FReal, 3, bPersistent>& Particle)
{
const FReal SmoothRate = FMath::Clamp(CVars::SmoothedPositionLerpRate, 0.0f, 1.0f);
// Reset VSmooth to something roughly in the same direction as what V will be after integration.
// This is temp fix, if this is only re-computed after solve, island will get incorrectly put back to sleep even if it was just impulsed.
FReal FakeDT = (FReal)1. / (FReal)30.;
if (Particle.LinearImpulseVelocity().IsNearlyZero() == false || Particle.Acceleration().IsNearlyZero() == false)
{