r.InstancedStaticMeshes.ConservativeBounds.Threshold

r.InstancedStaticMeshes.ConservativeBounds.Threshold

#Overview

name: r.InstancedStaticMeshes.ConservativeBounds.Threshold

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 r.InstancedStaticMeshes.ConservativeBounds.Threshold is to control when conservative bounds are used for Instanced Static Meshes (ISM) based on the number of instances. This setting is part of the rendering system, specifically for optimizing the rendering of multiple instances of static meshes.

This setting variable is primarily used in the Engine module, particularly in the InstancedStaticMesh component of Unreal Engine 5. It affects how the engine handles the bounding boxes for Instanced Static Meshes, which is crucial for rendering performance and culling.

The value of this variable is set through the console variable system in Unreal Engine. It’s initialized with a default value of 30, but can be changed at runtime using console commands or through project settings.

The associated variable GConservativeBoundsThreshold directly interacts with r.InstancedStaticMeshes.ConservativeBounds.Threshold. They share the same value, with GConservativeBoundsThreshold being the actual variable used in the C++ code to control the behavior.

Developers must be aware that:

  1. Setting this value to -1 will disable conservative bounds entirely.
  2. The threshold determines when the engine switches to using conservative bounds for an Instanced Static Mesh component.
  3. Conservative bounds can impact rendering performance and visual accuracy, so careful consideration should be given when adjusting this value.

Best practices when using this variable include:

  1. Leave it at the default value (30) unless you have specific performance issues related to Instanced Static Meshes.
  2. If you’re working with ISMs that have a large number of instances, you might want to increase this value to improve performance.
  3. Monitor performance metrics when adjusting this value to ensure you’re achieving the desired balance between rendering speed and accuracy.

Regarding the associated variable GConservativeBoundsThreshold:

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp:187

Scope: file

Source code excerpt:

static int32 GConservativeBoundsThreshold = 30;
FAutoConsoleVariableRef CVarISMConservativeBoundsThreshold(
	TEXT("r.InstancedStaticMeshes.ConservativeBounds.Threshold"),
	GConservativeBoundsThreshold,
	TEXT("Number of instances in an ISM before we start using conservative bounds. Set to -1 to disable conservative bounds."));

class FISMExecHelper : public FSelfRegisteringExec
{
	virtual bool Exec_Runtime(class UWorld* InWorld, const TCHAR* Cmd, FOutputDevice& Ar)

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp:185

Scope: file

Source code excerpt:

	TEXT("Enables the data path that allows instance count to be fetched from the Scene rather than the Mesh Draw Commands (MDCs), which removes the need to re-cache MDCs when instance count changes."));

static int32 GConservativeBoundsThreshold = 30;
FAutoConsoleVariableRef CVarISMConservativeBoundsThreshold(
	TEXT("r.InstancedStaticMeshes.ConservativeBounds.Threshold"),
	GConservativeBoundsThreshold,
	TEXT("Number of instances in an ISM before we start using conservative bounds. Set to -1 to disable conservative bounds."));

class FISMExecHelper : public FSelfRegisteringExec
{
	virtual bool Exec_Runtime(class UWorld* InWorld, const TCHAR* Cmd, FOutputDevice& Ar)
	{

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp:2443

Scope (from outer to inner):

file
function     void UInstancedStaticMeshComponent::BuildComponentInstanceData
lambda-function

Source code excerpt:

		BuildInstanceDataDeltaChangeSetCommon(ChangeSet);

		const bool bUpdateConservativeBounds = bUseConservativeBounds && GConservativeBoundsThreshold >= 0 && PerInstanceSMData.Num() > GConservativeBoundsThreshold;
		if (bUpdateConservativeBounds)
		{
			if (ChangeSet.IsFullUpdate())
			{
				CachedConservativeInstanceBounds.Init();
			}