p.Chaos.Joint.LinearVelocityThresholdToApplyRestitution

p.Chaos.Joint.LinearVelocityThresholdToApplyRestitution

#Overview

name: p.Chaos.Joint.LinearVelocityThresholdToApplyRestitution

This variable is created as a Console Variable (cvar).

It is referenced in 8 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of p.Chaos.Joint.LinearVelocityThresholdToApplyRestitution is to set a threshold for applying restitution in joint constraints within the Chaos physics system of Unreal Engine 5. It is specifically used in the Quasi-Position Based Dynamics (QuasiPBD) solver.

This setting variable is primarily used in the Chaos physics system, which is an experimental physics engine in Unreal Engine 5. It’s part of the joint constraint system, which handles connections between rigid bodies in the physics simulation.

The value of this variable is set in the JointConstraintsCVars.cpp file, with a default value of 1e-2f (0.01). It’s initialized as a console variable, which means it can be adjusted at runtime through the console or configuration files.

The associated variable Chaos_Joint_LinearVelocityThresholdToApplyRestitution directly interacts with it, sharing the same value. This variable is used in the actual physics calculations.

Developers must be aware that this variable affects the behavior of joint constraints in physics simulations. It determines when restitution (bounciness) is applied to joints based on their linear velocity. If the initial velocity is below this threshold, no restitution is applied, potentially reducing small jitters or vibrations in the simulation.

Best practices when using this variable include:

  1. Adjusting it carefully to balance between realistic behavior and performance.
  2. Testing different values to find the optimal setting for specific game scenarios.
  3. Considering the scale of your game world when setting this value, as it represents a velocity in the physics simulation.

Regarding the associated variable Chaos_Joint_LinearVelocityThresholdToApplyRestitution:

This variable is used directly in the physics calculations within the Chaos system. It’s referenced in several key locations:

  1. In PBDJointCachedSolverGaussSeidel.cpp, it’s used to determine whether to apply restitution in axis velocity constraints.
  2. In PBDJointSolverGaussSeidel.cpp, it’s used in various joint types (spherical, cylindrical, planar) to decide if restitution should be applied.

The variable is declared as extern in JointConstraintsCVars.h, allowing it to be accessed across different parts of the Chaos physics system.

When working with this variable, developers should consider its impact on different types of joints and how it interacts with other physics parameters like restitution coefficients. It’s a low-level setting that can have subtle but important effects on the overall feel and stability of physics simulations in the game.

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Joint/JointConstraintsCVars.cpp:20

Scope: file

Source code excerpt:


float Chaos_Joint_LinearVelocityThresholdToApplyRestitution = 1e-2f;
FAutoConsoleVariableRef CVarChaosJointLinearVelocityThresholdToApplyRestitution(TEXT("p.Chaos.Joint.LinearVelocityThresholdToApplyRestitution"), Chaos_Joint_LinearVelocityThresholdToApplyRestitution, TEXT("Apply restitution only if initial velocity is higher than this threshold (used in Quasipbd)"));

float Chaos_Joint_AngularVelocityThresholdToApplyRestitution = 1e-2f;
FAutoConsoleVariableRef CVarChaosJointAngularVelocityThresholdToApplyRestitution(TEXT("p.Chaos.Joint.AngularVelocityThresholdToApplyRestitution"), Chaos_Joint_AngularVelocityThresholdToApplyRestitution, TEXT("Apply restitution only if initial velocity is higher than this threshold (used in Quasipbd)"));

#Associated Variable and Callsites

This variable is associated with another variable named Chaos_Joint_LinearVelocityThresholdToApplyRestitution. They share the same value. See the following C++ source code.

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Joint/JointConstraintsCVars.cpp:19

Scope: file

Source code excerpt:

FAutoConsoleVariableRef CVarChaosJointPlasticityClampToLimits(TEXT("p.Chaos.Joint.Plasticity.ClampToLimits"), bChaos_Joint_Plasticity_ClampToLimits, TEXT("Clamp drive position targets to defined limits after plasticity computation"));

float Chaos_Joint_LinearVelocityThresholdToApplyRestitution = 1e-2f;
FAutoConsoleVariableRef CVarChaosJointLinearVelocityThresholdToApplyRestitution(TEXT("p.Chaos.Joint.LinearVelocityThresholdToApplyRestitution"), Chaos_Joint_LinearVelocityThresholdToApplyRestitution, TEXT("Apply restitution only if initial velocity is higher than this threshold (used in Quasipbd)"));

float Chaos_Joint_AngularVelocityThresholdToApplyRestitution = 1e-2f;
FAutoConsoleVariableRef CVarChaosJointAngularVelocityThresholdToApplyRestitution(TEXT("p.Chaos.Joint.AngularVelocityThresholdToApplyRestitution"), Chaos_Joint_AngularVelocityThresholdToApplyRestitution, TEXT("Apply restitution only if initial velocity is higher than this threshold (used in Quasipbd)"));

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Joint/JointConstraintsCVars.h:24

Scope: file

Source code excerpt:

extern bool bChaos_Joint_Plasticity_ClampToLimits;

extern float Chaos_Joint_LinearVelocityThresholdToApplyRestitution;

extern float Chaos_Joint_AngularVelocityThresholdToApplyRestitution;

extern bool bChaos_Joint_UseCachedSolver;

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Joint/PBDJointCachedSolverGaussSeidel.cpp:784

Scope (from outer to inner):

file
namespace    Chaos
function     void FPBDJointCachedSolver::ApplyAxisVelocityConstraint

Source code excerpt:

		{
			const FReal InitVel = InitConstraintAxisLinearVelocities[ConstraintIndex];
			const FReal Threshold = Chaos_Joint_LinearVelocityThresholdToApplyRestitution;
			TargetVel = (InitVel > Threshold) ? -Restitution * InitVel : 0.0f;
		}
		SolveLinearVelocityConstraint(ConstraintIndex, TargetVel);
	}
}

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Joint/PBDJointSolverGaussSeidel.cpp:2488

Scope (from outer to inner):

file
namespace    Chaos
function     void FPBDJointSolver::ApplySphericalVelocityConstraint

Source code excerpt:

			{
				const FReal InitVel = InitConstraintAxisLinearVelocities[0];
				TargetVel = InitVel > Chaos_Joint_LinearVelocityThresholdToApplyRestitution ? -JointSettings.LinearRestitution * InitVel : 0.0f; 
			}
			ApplyLinearVelocityConstraint(Stiffness, Axis, Connector0Correction, TargetVel);
		}
	}

	void FPBDJointSolver::ApplyCylindricalVelocityConstraint(

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Joint/PBDJointSolverGaussSeidel.cpp:2531

Scope (from outer to inner):

file
namespace    Chaos
function     void FPBDJointSolver::ApplyCylindricalVelocityConstraint

Source code excerpt:

				{
					const FReal InitVel = InitConstraintAxisLinearVelocities[(int32)EJointCylindricalPositionConstraintType::Axial];
					TargetVel = InitVel > Chaos_Joint_LinearVelocityThresholdToApplyRestitution ? -JointSettings.LinearRestitution * InitVel : 0.0f; 
				}

				ApplyLinearVelocityConstraint(Stiffness, Axis, Connector0Correction, TargetVel);
			}

			if (LinearHardLambda[(int32)EJointCylindricalPositionConstraintType::Radial] > UE_SMALL_NUMBER)

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Joint/PBDJointSolverGaussSeidel.cpp:2548

Scope (from outer to inner):

file
namespace    Chaos
function     void FPBDJointSolver::ApplyCylindricalVelocityConstraint

Source code excerpt:

				{
					const FReal InitVel = InitConstraintAxisLinearVelocities[(int32)EJointCylindricalPositionConstraintType::Radial];
					TargetVel = InitVel > Chaos_Joint_LinearVelocityThresholdToApplyRestitution ? -JointSettings.LinearRestitution * InitVel : 0.0f; 
				}
				ApplyLinearVelocityConstraint(Stiffness, RadialAxis, Connector0Correction, TargetVel);
			}
		}
	}

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/Joint/PBDJointSolverGaussSeidel.cpp:2585

Scope (from outer to inner):

file
namespace    Chaos
function     void FPBDJointSolver::ApplyPlanarVelocityConstraint

Source code excerpt:

			{
				const FReal InitVel = InitConstraintAxisLinearVelocities[0];
				TargetVel = InitVel > Chaos_Joint_LinearVelocityThresholdToApplyRestitution ? -JointSettings.LinearRestitution * InitVel : 0.0f; 
			}
			ApplyLinearVelocityConstraint(Stiffness, Axis, Connector0Correction, TargetVel);
		}
	}

	void FPBDJointSolver::CalculateConstraintAxisLinearVelocities(