foliage.CullDistanceScale
foliage.CullDistanceScale
#Overview
name: foliage.CullDistanceScale
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Controls the cull distance scale. Foliage must opt-in to cull distance scaling through the foliage type.
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:
- The value is clamped between 0.0 and 1.0 for safety.
- Foliage types must opt-in to use this scaling through the ‘bEnableCullDistanceScaling’ property.
- Changes to this value will affect the rendering performance and visibility of foliage in the game.
Best practices when using this variable include:
- Use it as a scalability option to balance between visual quality and performance.
- Carefully consider which foliage types should have ‘bEnableCullDistanceScaling’ enabled.
- Test the game with different values to find the optimal balance for your specific use case.
Regarding the associated variable CVarFoliageCullDistanceScale:
- Its purpose is to implement the console variable for foliage.CullDistanceScale.
- It is used in the Foliage system to retrieve and apply the current cull distance scale value.
- The value is set through engine console commands or scalability settings.
- It interacts directly with foliage.CullDistanceScale and is used to update component cull distances.
- Developers should be aware that changes to this variable will trigger updates to foliage components.
- Best practices include using this variable for dynamic adjustments to foliage rendering based on performance needs.
#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))
{