p.chaos.UseContactSpeedForStrainEval

p.chaos.UseContactSpeedForStrainEval

#Overview

name: p.chaos.UseContactSpeedForStrainEval

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

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of p.chaos.UseContactSpeedForStrainEval is to control the method used for evaluating strain in collision detection within Unreal Engine’s Chaos physics system. Specifically, it determines whether to use contact speed or impulse when updating cluster strain during collision handling.

This setting variable is primarily used in the Chaos physics module, which is part of Unreal Engine’s experimental physics simulation system. It is referenced in the PBDRigidClustering.cpp file, which deals with rigid body clustering in physics-based simulations.

The value of this variable is set using an FAutoConsoleVariableRef, which means it can be modified at runtime through console commands or configuration files. It is initialized to true by default.

This variable interacts closely with two other variables:

  1. bUseContactSpeedForStrainThreshold, which is the associated variable that directly controls the behavior.
  2. MinContactSpeedForStrainEval, which sets the minimum speed threshold for strain evaluation when contact speed is used.

Developers should be aware that:

  1. This variable affects the performance and accuracy of collision detection in clustered rigid body simulations.
  2. Changing this variable will switch between two different methods of strain evaluation: contact speed-based or impulse-based.

Best practices when using this variable include:

  1. Experimenting with both true and false values to determine which gives better results for your specific simulation scenario.
  2. Considering the performance implications of each method in your particular use case.
  3. Using this in conjunction with MinContactSpeedForStrainEval or MinImpulseForStrainEval, depending on which method is chosen.

Regarding the associated variable bUseContactSpeedForStrainThreshold:

The purpose of bUseContactSpeedForStrainThreshold is to directly control whether contact speed or impulse is used for strain evaluation in collision detection.

This variable is used within the ComputeStrainFromCollision function of the FRigidClustering class in the Chaos physics module.

Its value is set by the p.chaos.UseContactSpeedForStrainEval console variable, allowing for runtime configuration.

It interacts with MinContactSpeedForStrainEval when true, and likely with MinImpulseForStrainEval when false (though this is not directly shown in the provided code).

Developers should be aware that:

  1. This variable directly affects the collision detection logic in clustered rigid body simulations.
  2. Changing its value will switch between using contact speed and impulse for strain evaluation.

Best practices include:

  1. Ensuring that the appropriate minimum threshold variable (MinContactSpeedForStrainEval or MinImpulseForStrainEval) is properly set based on the value of this variable.
  2. Testing both true and false values to determine which provides better simulation results for your specific use case.
  3. Considering the performance implications of each method in your particular scenario.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDRigidClustering.cpp:2217

Scope (from outer to inner):

file
namespace    Chaos

Source code excerpt:


	bool bUseContactSpeedForStrainThreshold = true;
	FAutoConsoleVariableRef CVarUseContactSpeedForStrainEval(TEXT("p.chaos.UseContactSpeedForStrainEval"), bUseContactSpeedForStrainThreshold, TEXT("Whether to use contact speed to discard contacts when updating cluster strain (true: use speed, false: use impulse)"));

	FRealSingle MinContactSpeedForStrainEval = 1.0f; // Ignore contacts where the two bodies are resting together
	FAutoConsoleVariableRef CVarMinContactSpeedForStrainEval(TEXT("p.chaos.MinContactSpeedForStrainEval"), MinContactSpeedForStrainEval, TEXT("Minimum speed at the contact before accumulating for strain eval "));

	DECLARE_CYCLE_STAT(TEXT("ComputeStrainFromCollision"), STAT_ComputeStrainFromCollision, STATGROUP_Chaos);
	void FRigidClustering::ComputeStrainFromCollision(const FPBDCollisionConstraints& CollisionRule, const FReal Dt)

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDRigidClustering.cpp:2216

Scope (from outer to inner):

file
namespace    Chaos

Source code excerpt:

	FAutoConsoleVariableRef CVarMinImpulseForStrainEval(TEXT("p.chaos.MinImpulseForStrainEval"), MinImpulseForStrainEval, TEXT("Minimum accumulated impulse before accumulating for strain eval "));

	bool bUseContactSpeedForStrainThreshold = true;
	FAutoConsoleVariableRef CVarUseContactSpeedForStrainEval(TEXT("p.chaos.UseContactSpeedForStrainEval"), bUseContactSpeedForStrainThreshold, TEXT("Whether to use contact speed to discard contacts when updating cluster strain (true: use speed, false: use impulse)"));

	FRealSingle MinContactSpeedForStrainEval = 1.0f; // Ignore contacts where the two bodies are resting together
	FAutoConsoleVariableRef CVarMinContactSpeedForStrainEval(TEXT("p.chaos.MinContactSpeedForStrainEval"), MinContactSpeedForStrainEval, TEXT("Minimum speed at the contact before accumulating for strain eval "));

	DECLARE_CYCLE_STAT(TEXT("ComputeStrainFromCollision"), STAT_ComputeStrainFromCollision, STATGROUP_Chaos);
	void FRigidClustering::ComputeStrainFromCollision(const FPBDCollisionConstraints& CollisionRule, const FReal Dt)

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/PBDRigidClustering.cpp:2255

Scope (from outer to inner):

file
namespace    Chaos
function     void FRigidClustering::ComputeStrainFromCollision

Source code excerpt:

			const FPBDRigidParticleHandle* Rigid1 = ConstrainedParticles[1]->CastToRigidParticle();

			if (bUseContactSpeedForStrainThreshold)
			{
				// Get dV between the two particles and project onto the normal to get the approach speed (take PreV as V is the new velocity post-solve)
				const FVec3 V0 = Rigid0 ? Rigid0->GetPreV() : FVec3(0);
				const FVec3 V1 = Rigid1 ? Rigid1->GetPreV() : FVec3(0);
				const FVec3 DeltaV = V0 - V1;
				const FReal SpeedAlongNormal = FVec3::DotProduct(DeltaV, ContactHandle->GetContact().CalculateWorldContactNormal());