p.ClosestIntersectionStepSizeMultiplier

p.ClosestIntersectionStepSizeMultiplier

#Overview

name: p.ClosestIntersectionStepSizeMultiplier

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.ClosestIntersectionStepSizeMultiplier is to control the step size in raycasting operations within the Chaos physics engine of Unreal Engine 5. It is used specifically in the process of finding the closest intersection point between a ray and an implicit object.

This setting variable is primarily used in the Chaos physics module, which is part of Unreal Engine’s experimental features. It’s referenced in the ImplicitObject.cpp file, which suggests it’s used in calculations involving implicit geometric shapes in the physics simulation.

The value of this variable is set to a default of 0.5f, but it can be modified at runtime through the console variable system. The associated C++ variable ClosestIntersectionStepSizeMultiplier shares the same value and is used directly in the code.

The variable interacts with the raycast algorithm in the FindClosestIntersectionImp function of the FImplicitObject class. It’s used to calculate the step size when moving along the ray during the intersection search.

Developers must be aware that this variable directly affects the trade-off between accuracy and performance in raycast operations. A smaller value will result in more accurate intersections but at a higher computational cost.

Best practices when using this variable include:

  1. Adjusting it carefully based on the specific needs of your project, balancing accuracy and performance.
  2. Testing thoroughly with different values to ensure it doesn’t negatively impact your game’s performance or physics behavior.
  3. Considering exposing it as a configurable setting for advanced users or developers, but not for end-users unless necessary.

Regarding the associated variable ClosestIntersectionStepSizeMultiplier:

The purpose of ClosestIntersectionStepSizeMultiplier is the same as p.ClosestIntersectionStepSizeMultiplier, as they share the same value. It’s the C++ variable that directly holds the value used in the calculations.

This variable is used within the Chaos physics module, specifically in the FImplicitObject class’s FindClosestIntersectionImp method.

The value of this variable is set initially to 0.5f, but it can be modified through the console variable system using p.ClosestIntersectionStepSizeMultiplier.

It interacts directly with the raycast algorithm, influencing how quickly the algorithm steps along the ray when searching for intersections.

Developers should be aware that modifying this variable directly in the code will be overridden by any console variable settings. Always use the console variable p.ClosestIntersectionStepSizeMultiplier to modify this value at runtime.

Best practices include using this variable consistently throughout the codebase where similar raycast operations are performed, and considering its impact on both accuracy and performance when making changes.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/ImplicitObject.cpp:226

Scope (from outer to inner):

file
namespace    Chaos

Source code excerpt:


	FRealSingle ClosestIntersectionStepSizeMultiplier = 0.5f;
	FAutoConsoleVariableRef CVarClosestIntersectionStepSizeMultiplier(TEXT("p.ClosestIntersectionStepSizeMultiplier"), ClosestIntersectionStepSizeMultiplier, TEXT("When raycasting we use this multiplier to substep the travel distance along the ray. Smaller number gives better accuracy at higher cost"));

	Pair<FVec3, bool> FImplicitObject::FindClosestIntersectionImp(const FVec3& StartPoint, const FVec3& EndPoint, const FReal Thickness) const
	{
		FReal Epsilon = (FReal)1e-4;

		FVec3 Ray = EndPoint - StartPoint;

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/ImplicitObject.cpp:225

Scope (from outer to inner):

file
namespace    Chaos

Source code excerpt:

	}

	FRealSingle ClosestIntersectionStepSizeMultiplier = 0.5f;
	FAutoConsoleVariableRef CVarClosestIntersectionStepSizeMultiplier(TEXT("p.ClosestIntersectionStepSizeMultiplier"), ClosestIntersectionStepSizeMultiplier, TEXT("When raycasting we use this multiplier to substep the travel distance along the ray. Smaller number gives better accuracy at higher cost"));

	Pair<FVec3, bool> FImplicitObject::FindClosestIntersectionImp(const FVec3& StartPoint, const FVec3& EndPoint, const FReal Thickness) const
	{
		FReal Epsilon = (FReal)1e-4;

		FVec3 Ray = EndPoint - StartPoint;

#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/ImplicitObject.cpp:244

Scope (from outer to inner):

file
namespace    Chaos
function     Pair<FVec3, bool> FImplicitObject::FindClosestIntersectionImp

Source code excerpt:

		while(Phi > Thickness + Epsilon)
		{
			ClosestPoint += Direction * (Phi - Thickness) * (FReal)ClosestIntersectionStepSizeMultiplier;
			if((ClosestPoint - StartPoint).Size() > Length)
			{
				if(EndPhi < Thickness + Epsilon)
				{
					return MakePair(FVec3(EndPoint + EndNormal * (-EndPhi + Thickness)), true);
				}