foliage.CullDistanceScale

foliage.CullDistanceScale

#Overview

name: foliage.CullDistanceScale

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

It is referenced in 6 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of foliage.CullDistanceScale is to control the cull distance scale for foliage in Unreal Engine 5. This setting variable is primarily used in the rendering system, specifically for managing the visibility and performance of foliage elements in the game world.

The Unreal Engine subsystem that relies on this setting variable is the Foliage system, which is part of the engine’s rendering and environmental modules. This can be seen from the file paths where the variable is referenced, such as “Engine/Source/Runtime/Foliage/Private/InstancedFoliage.cpp” and “Engine/Source/Runtime/Foliage/Public/FoliageType.h”.

The value of this variable is set through a console variable (CVar) named CVarFoliageCullDistanceScale. It is initialized with a default value of 1.0 and can be adjusted at runtime through console commands or scalability settings.

The associated variable CVarFoliageCullDistanceScale interacts directly with foliage.CullDistanceScale. They share the same value and purpose, with CVarFoliageCullDistanceScale being the actual implementation of the console variable.

Developers must be aware of several things when using this variable:

  1. The value is clamped between 0.0 and 1.0 for safety.
  2. Foliage types must opt-in to use this scaling through the ‘bEnableCullDistanceScaling’ property.
  3. Changes to this value will affect the rendering performance and visibility of foliage in the game.

Best practices when using this variable include:

  1. Use it as a scalability option to balance between visual quality and performance.
  2. Carefully consider which foliage types should have ‘bEnableCullDistanceScaling’ enabled.
  3. Test the game with different values to find the optimal balance for your specific use case.

Regarding the associated variable CVarFoliageCullDistanceScale:

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Foliage/Private/InstancedFoliage.cpp:81

Scope: file

Source code excerpt:


static TAutoConsoleVariable<float> CVarFoliageCullDistanceScale(
	TEXT("foliage.CullDistanceScale"),
	1.0,
	TEXT("Controls the cull distance scale. Foliage must opt-in to cull distance scaling through the foliage type."),
	ECVF_Scalability);

const FGuid FFoliageCustomVersion::GUID(0x430C4D19, 0x71544970, 0x87699B69, 0xDF90B0E5);
// Register the custom version with core

#Loc: <Workspace>/Engine/Source/Runtime/Foliage/Public/FoliageType.h:590

Scope (from outer to inner):

file
class        class UFoliageType : public UObject

Source code excerpt:


	/*
	 * Whether this foliage type should be affected by the Engine's "foliage.CullDistanceScale" setting 
	 */
	UPROPERTY(EditAnywhere, Category = Scalability)
	uint32 bEnableCullDistanceScaling : 1;

public:
	// VIRTUAL TEXTURE

	/** 

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Foliage/Private/InstancedFoliage.cpp:80

Scope: file

Source code excerpt:

	ECVF_Scalability);

static TAutoConsoleVariable<float> CVarFoliageCullDistanceScale(
	TEXT("foliage.CullDistanceScale"),
	1.0,
	TEXT("Controls the cull distance scale. Foliage must opt-in to cull distance scaling through the foliage type."),
	ECVF_Scalability);

const FGuid FFoliageCustomVersion::GUID(0x430C4D19, 0x71544970, 0x87699B69, 0xDF90B0E5);

#Loc: <Workspace>/Engine/Source/Runtime/Foliage/Private/InstancedFoliage.cpp:228

Scope (from outer to inner):

file
namespace    FoliageUtil
function     static void CVarSinkFunction

Source code excerpt:

	{
		static float CachedCullDistanceScale = 1.0f;
		float CullDistanceScale = CVarFoliageCullDistanceScale.GetValueOnGameThread();

		if (CullDistanceScale != CachedCullDistanceScale)
		{
			CachedCullDistanceScale = CullDistanceScale;
			CullDistanceScale = FMath::Clamp(CullDistanceScale, 0.0f, 1.0f);

#Loc: <Workspace>/Engine/Source/Runtime/Foliage/Private/InstancedFoliage.cpp:1610

Scope (from outer to inner):

file
function     void FFoliageStaticMesh::UpdateComponentSettings

Source code excerpt:

		}

		const float FoliageCullDistanceScale = FMath::Clamp(CVarFoliageCullDistanceScale.GetValueOnGameThread(), 0.0f, 1.0f);
		FoliageUtil::UpdateComponentCullDistance(FoliageType, Component, FoliageCullDistanceScale);

		if (Component->CastShadow != FoliageType->CastShadow)
		{
			Component->CastShadow = FoliageType->CastShadow;
			bNeedsMarkRenderStateDirty = true;

#Loc: <Workspace>/Engine/Source/Runtime/Foliage/Private/InstancedFoliage.cpp:4798

Scope (from outer to inner):

file
function     void AInstancedFoliageActor::PostLoad

Source code excerpt:

	{
		const bool bFoliageDiscardOnLoad = !!CVarFoliageDiscardDataOnLoad.GetValueOnGameThread();
		const float FoliageCullDistanceScale = FMath::Clamp(CVarFoliageCullDistanceScale.GetValueOnGameThread(), 0.0f, 1.0f);

		bool bHasISMFoliage = false;
		for (auto& Pair : FoliageInfos)
		{
			if (bFoliageDiscardOnLoad && (!Pair.Key || Pair.Key->bEnableDiscardOnLoad))
			{