p.NormalAveraging2
p.NormalAveraging2
#Overview
name: p.NormalAveraging2
This variable is created as a Console Variable (cvar).
- type:
Var
- help: ``
It is referenced in 14
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of p.NormalAveraging2 is to control normal averaging in collision detection and resolution within the Chaos physics system of Unreal Engine 5. This setting variable is used to determine whether normal averaging should be applied when sampling collision objects for contact points.
-
The Chaos physics subsystem, part of Unreal Engine’s experimental features, relies on this setting variable. Specifically, it’s used in the collision resolution utilities.
-
The value of this variable is set using an FAutoConsoleVariableRef, which allows it to be modified at runtime through the console or configuration files.
-
This variable interacts closely with the associated variable NormalAveraging. They share the same value, and NormalAveraging is used throughout the code to control the behavior of normal averaging.
-
Developers must be aware that this variable affects the accuracy and performance of collision detection. When enabled, it performs additional calculations to average normals, which can provide more stable results but at the cost of increased computational overhead.
-
Best practices when using this variable include:
- Testing the impact on performance and collision stability with it enabled and disabled.
- Considering enabling it for scenarios where more accurate collision normals are crucial.
- Being cautious when modifying it at runtime, as it can significantly change physics behavior.
Regarding the associated variable NormalAveraging:
The purpose of NormalAveraging is to serve as the actual control flag for normal averaging operations within the collision resolution code. It’s directly used in conditional statements to determine whether normal averaging should be performed.
-
It’s used extensively in the SampleObject function within the Chaos::Collisions namespace.
-
The value is set by the p.NormalAveraging2 console variable.
-
It interacts with various collision object types, including level sets, boxes, planes, and spheres.
-
Developers should be aware that when NormalAveraging is true, additional computations are performed for each sampled point, which can impact performance.
-
Best practices include:
- Profiling the impact of enabling/disabling normal averaging on your specific use cases.
- Considering the trade-off between accuracy and performance when deciding to use normal averaging.
- Ensuring that any code relying on collision normals is aware of whether normal averaging is being used, as it can affect the resulting contact points and normals.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/CollisionResolutionUtil.cpp:158
Scope (from outer to inner):
file
namespace Chaos
namespace Collisions
Source code excerpt:
int32 NormalAveraging = 0;
FAutoConsoleVariableRef CVarNormalAveraging(TEXT("p.NormalAveraging2"), NormalAveraging, TEXT(""));
int32 SampleMinParticlesForAcceleration = 2048;
FAutoConsoleVariableRef CVarSampleMinParticlesForAcceleration(TEXT("p.SampleMinParticlesForAcceleration"), SampleMinParticlesForAcceleration, TEXT("The minimum number of particles needed before using an acceleration structure when sampling"));
#if INTEL_ISPC && 0
#Associated Variable and Callsites
This variable is associated with another variable named NormalAveraging
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/CollisionResolutionUtil.cpp:157
Scope (from outer to inner):
file
namespace Chaos
namespace Collisions
Source code excerpt:
DECLARE_CYCLE_STAT(TEXT("TPBDCollisionConstraints::SampleObject"), STAT_SampleObject, STATGROUP_ChaosWide);
int32 NormalAveraging = 0;
FAutoConsoleVariableRef CVarNormalAveraging(TEXT("p.NormalAveraging2"), NormalAveraging, TEXT(""));
int32 SampleMinParticlesForAcceleration = 2048;
FAutoConsoleVariableRef CVarSampleMinParticlesForAcceleration(TEXT("p.SampleMinParticlesForAcceleration"), SampleMinParticlesForAcceleration, TEXT("The minimum number of particles needed before using an acceleration structure when sampling"));
#if INTEL_ISPC && 0
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/CollisionResolutionUtil.cpp:209
Scope (from outer to inner):
file
namespace Chaos
namespace Collisions
function FContactPoint SampleObject
Source code excerpt:
const TUniformGrid<FReal, 3>& Grid = LevelSet->GetGrid();
if (NormalAveraging && UpdateType != ECollisionUpdateType::Any)
{
ispc::SampleLevelSetNormalAverage(
(ispc::FVector&)Grid.MinCorner(),
(ispc::FVector&)Grid.MaxCorner(),
(ispc::FVector&)Grid.Dx(),
(ispc::FIntVector&)Grid.Counts(),
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/CollisionResolutionUtil.cpp:254
Scope (from outer to inner):
file
namespace Chaos
namespace Collisions
function FContactPoint SampleObject
Source code excerpt:
const FVec3 BoxMax = Box->Max();
if (NormalAveraging && UpdateType != ECollisionUpdateType::Any)
{
ispc::SampleBoxNormalAverage(
(ispc::FVector&)BoxMin,
(ispc::FVector&)BoxMax,
(ispc::FTransform&)SampleToObjectTM,
(ispc::FVector*)&SampleParticles.XArray()[0],
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/CollisionResolutionUtil.cpp:291
Scope (from outer to inner):
file
namespace Collisions
function FContactPoint SampleObject
Source code excerpt:
for (int32 i : PotentialParticles)
{
if (NormalAveraging && UpdateType != ECollisionUpdateType::Any)
{
SampleObjectNormalAverageHelper(Object, ObjectTransform, SampleToObjectTM, SampleParticles.X(i), CullingDistance, WeightSum, AvgContact);
}
else
{
if (SampleObjectNoNormal(Object, ObjectTransform, SampleToObjectTM, SampleParticles.X(i), CullingDistance, AvgContact))
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/CollisionResolutionUtil.cpp:319
Scope (from outer to inner):
file
namespace Chaos
namespace Collisions
function FContactPoint SampleObject
Source code excerpt:
const TUniformGrid<FReal, 3>& Grid = LevelSet->GetGrid();
if (NormalAveraging && UpdateType != ECollisionUpdateType::Any)
{
ispc::SampleLevelSetNormalAverageAll(
(ispc::FVector&)Grid.MinCorner(),
(ispc::FVector&)Grid.MaxCorner(),
(ispc::FVector&)Grid.Dx(),
(ispc::FIntVector&)Grid.Counts(),
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/CollisionResolutionUtil.cpp:359
Scope (from outer to inner):
file
namespace Chaos
namespace Collisions
function FContactPoint SampleObject
Source code excerpt:
const TPlane<FReal, 3>* Plane = Object.GetObject<Chaos::TPlane<FReal, 3>>();
if (NormalAveraging && UpdateType != ECollisionUpdateType::Any)
{
ispc::SamplePlaneNormalAverageAll(
(ispc::FVector&)Plane->Normal(),
(ispc::FVector&)Plane->X(),
(ispc::FTransform&)SampleToObjectTM,
(ispc::FVector*)&SampleParticles.XArray()[0],
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/CollisionResolutionUtil.cpp:393
Scope (from outer to inner):
file
namespace Chaos
namespace Collisions
function FContactPoint SampleObject
Source code excerpt:
const TSphere<FReal, 3>* Sphere = Object.GetObject<Chaos::TSphere<FReal, 3>>();
if (NormalAveraging && UpdateType != ECollisionUpdateType::Any)
{
ispc::SampleSphereNormalAverageAll(
Sphere->GetRadius(),
(ispc::FVector&)Sphere->GetCenter(),
(ispc::FTransform&)SampleToObjectTM,
(ispc::FVector*) & SampleParticles.XArray()[0],
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/CollisionResolutionUtil.cpp:429
Scope (from outer to inner):
file
namespace Collisions
function FContactPoint SampleObject
Source code excerpt:
const FVec3 BoxMax = Box->Max();
if (NormalAveraging && UpdateType != ECollisionUpdateType::Any)
{
ispc::SampleBoxNormalAverageAll(
(ispc::FVector&)BoxMin,
(ispc::FVector&)BoxMax,
(ispc::FTransform&)SampleToObjectTM,
(ispc::FVector*)&SampleParticles.XArray()[0],
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/CollisionResolutionUtil.cpp:464
Scope (from outer to inner):
file
function FContactPoint SampleObject
Source code excerpt:
for (int32 i = 0; i < NumParticles; ++i)
{
if (NormalAveraging && UpdateType != ECollisionUpdateType::Any)
{
SampleObjectNormalAverageHelper(Object, ObjectTransform, SampleToObjectTM, SampleParticles.X(i), CullingDistance, WeightSum, AvgContact);
}
else
{
if (SampleObjectNoNormal(Object, ObjectTransform, SampleToObjectTM, SampleParticles.X(i), CullingDistance, AvgContact))
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/CollisionResolutionUtil.cpp:484
Scope (from outer to inner):
file
namespace Chaos
namespace Collisions
function FContactPoint SampleObject
Source code excerpt:
}
if (NormalAveraging)
{
if (WeightSum < -KINDA_SMALL_NUMBER)
{
FVec3 LocalPoint = AvgContact.ShapeContactPoints[0] / WeightSum;
FVec3 LocalNormal;
const FReal NewPhi = Object.PhiWithNormal(LocalPoint, LocalNormal);
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/CollisionResolutionUtil.cpp:553
Scope (from outer to inner):
file
namespace Chaos
namespace Collisions
function FContactPoint SampleObject
Source code excerpt:
for (int32 i : PotentialParticles)
{
if (NormalAveraging && UpdateType != ECollisionUpdateType::Any) //if we just want one don't bother with normal
{
SampleObjectNormalAverageHelper(Object, ObjectTransform, SampleToObjectTM, SampleParticles.GetX(i), CullingDistance, WeightSum, AvgContact);
}
else
{
if (SampleObjectNoNormal(Object, ObjectTransform, SampleToObjectTM, SampleParticles.GetX(i), CullingDistance, AvgContact))
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/CollisionResolutionUtil.cpp:577
Scope (from outer to inner):
file
namespace Chaos
namespace Collisions
function FContactPoint SampleObject
Source code excerpt:
for (int32 i = 0; i < NumParticles; ++i)
{
if (NormalAveraging && UpdateType != ECollisionUpdateType::Any) //if we just want one don't bother with normal
{
const bool bInside = SampleObjectNormalAverageHelper(Object, ObjectTransform, SampleToObjectTM, SampleParticles.GetX(i), CullingDistance, WeightSum, AvgContact);
}
else
{
if (SampleObjectNoNormal(Object, ObjectTransform, SampleToObjectTM, SampleParticles.GetX(i), CullingDistance, AvgContact))
#Loc: <Workspace>/Engine/Source/Runtime/Experimental/Chaos/Private/Chaos/CollisionResolutionUtil.cpp:596
Scope (from outer to inner):
file
namespace Chaos
namespace Collisions
function FContactPoint SampleObject
Source code excerpt:
}
if (NormalAveraging)
{
if (WeightSum < -UE_KINDA_SMALL_NUMBER)
{
FVec3 LocalPoint = AvgContact.ShapeContactPoints[0] / WeightSum;
FVec3 LocalNormal;
const FReal NewPhi = Object.PhiWithNormal(LocalPoint, LocalNormal);