foliage.LODDistanceScale
foliage.LODDistanceScale
#Overview
name: foliage.LODDistanceScale
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Scale factor for the distance used in computing LOD for foliage.
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of foliage.LODDistanceScale is to control the scale factor for the distance used in computing Level of Detail (LOD) for foliage in Unreal Engine 5. This setting variable is primarily used in the rendering system, specifically for managing the LOD of foliage instances.
The Unreal Engine subsystem that relies on this setting variable is the rendering system, particularly the hierarchical instanced static mesh component. This can be seen from the file name “HierarchicalInstancedStaticMesh.cpp” where the variable is defined and used.
The value of this variable is set as a console variable with a default value of 1.0f. It can be modified at runtime through the console or programmatically.
The associated variable CVarFoliageLODDistanceScale interacts directly with foliage.LODDistanceScale. They share the same value and purpose.
Developers must be aware that changing this variable will affect the distance at which LOD transitions occur for foliage instances. A higher value will cause LOD transitions to occur at greater distances, potentially improving performance at the cost of visual quality. Conversely, a lower value will cause LOD transitions to occur at shorter distances, potentially improving visual quality at the cost of performance.
Best practices when using this variable include:
- Use it to fine-tune performance and visual quality balance for foliage rendering.
- Be cautious when modifying it, as it can have a significant impact on both performance and visual quality.
- Test thoroughly after making changes, especially on target hardware, to ensure desired results.
- Consider exposing this variable in user settings if you want to give players control over foliage detail and performance.
Regarding the associated variable CVarFoliageLODDistanceScale:
- Its purpose is the same as foliage.LODDistanceScale, serving as the C++ representation of the console variable.
- It’s used within the HierarchicalInstancedStaticMesh module of the rendering system.
- Its value is set when the console variable is initialized and can be accessed using GetValueOnGameThread().
- It directly interacts with the InstanceLODDistanceScale of the component to calculate the final LOD distance scale.
- Developers should be aware that changes to this variable will trigger a recreation of the render state for affected components.
- Best practices include using this variable for runtime adjustments to foliage LOD behavior and ensuring that any modifications are thread-safe, as it’s accessed on the game thread.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/HierarchicalInstancedStaticMesh.cpp:92
Scope: file
Source code excerpt:
TAutoConsoleVariable<float> CVarFoliageLODDistanceScale(
TEXT("foliage.LODDistanceScale"),
1.0f,
TEXT("Scale factor for the distance used in computing LOD for foliage."),
FConsoleVariableDelegate::CreateLambda([](IConsoleVariable* InVariable)
{
FGlobalComponentRecreateRenderStateContext Context;
})
#Associated Variable and Callsites
This variable is associated with another variable named CVarFoliageLODDistanceScale
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/HierarchicalInstancedStaticMesh.cpp:91
Scope: file
Source code excerpt:
TEXT("Max distance for end culling (0 disabled)."));
TAutoConsoleVariable<float> CVarFoliageLODDistanceScale(
TEXT("foliage.LODDistanceScale"),
1.0f,
TEXT("Scale factor for the distance used in computing LOD for foliage."),
FConsoleVariableDelegate::CreateLambda([](IConsoleVariable* InVariable)
{
FGlobalComponentRecreateRenderStateContext Context;
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/HierarchicalInstancedStaticMesh.cpp:801
Scope (from outer to inner):
file
function FHierarchicalStaticMeshSceneProxy::FHierarchicalStaticMeshSceneProxy
Source code excerpt:
// Store LODDistanceScale so it can be used in FInstancedStaticMeshVertexFactoryShaderParameters::GetElementShaderBindings when dither LOD transitions are enabled
float LODDistanceScale = InComponent->InstanceLODDistanceScale * CVarFoliageLODDistanceScale.GetValueOnGameThread();
UserData_AllInstances.LODDistanceScale = LODDistanceScale;
UserData_SelectedInstances.LODDistanceScale = LODDistanceScale;
UserData_DeselectedInstances.LODDistanceScale = LODDistanceScale;
}
void FHierarchicalStaticMeshSceneProxy::SetupOcclusion(UHierarchicalInstancedStaticMeshComponent* InComponent)