foliage.OnlyLOD
foliage.OnlyLOD
#Overview
name: foliage.OnlyLOD
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
If greater than or equal to zero, only renders the foliage LOD at that level.
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of foliage.OnlyLOD is to control the rendering of foliage LODs (Levels of Detail) in Unreal Engine 5. It allows developers to force the rendering of a specific LOD level for foliage, which can be useful for debugging, performance testing, or achieving specific visual effects.
This setting variable is primarily used in the rendering system, specifically for foliage rendering. Based on the callsites, it appears to be utilized in the Hierarchical Instanced Static Mesh component of the Engine module.
The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of -1, which means all LODs are rendered normally. If set to a value greater than or equal to zero, it will only render the foliage LOD at that specific level.
The associated variable CVarOnlyLOD interacts directly with foliage.OnlyLOD. They share the same value and purpose, with CVarOnlyLOD being the actual C++ variable that stores and provides access to the console variable’s value.
Developers should be aware that:
- Setting this variable to a non-negative value will override the normal LOD selection process for foliage.
- It affects all foliage in the scene, not just specific instances.
- Using this variable may impact performance and visual quality, depending on the chosen LOD level.
Best practices when using this variable include:
- Use it primarily for debugging or testing purposes.
- Remember to reset it to -1 when normal LOD behavior is desired.
- Be cautious when using it in production builds, as it can significantly affect visual quality and performance.
- Consider using it in conjunction with other foliage-related settings for comprehensive testing and optimization.
Regarding the associated variable CVarOnlyLOD:
The purpose of CVarOnlyLOD is to provide programmatic access to the foliage.OnlyLOD console variable within the C++ code. It allows the engine to retrieve the current value of the setting and use it in rendering decisions.
CVarOnlyLOD is used in the Engine module, specifically in the HierarchicalInstancedStaticMesh component. It’s accessed in the FillDynamicMeshElements function to determine which LOD levels should be rendered for foliage instances.
The value of CVarOnlyLOD is set indirectly through the foliage.OnlyLOD console variable. It’s retrieved in the render thread using the GetValueOnRenderThread() method.
CVarOnlyLOD interacts directly with the LOD selection logic in the foliage rendering system. It’s used to override the normal LOD selection process when set to a non-negative value.
Developers should be aware that:
- Changes to foliage.OnlyLOD will be reflected in CVarOnlyLOD.
- The value is clamped to the range of available LOD levels for the foliage mesh.
Best practices when working with CVarOnlyLOD include:
- Use it for reading the console variable value, not for direct modification.
- Be aware of potential performance implications when frequently accessing its value in performance-critical code paths.
- Consider caching its value if used frequently within a single frame or update cycle.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/HierarchicalInstancedStaticMesh.cpp:50
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarOnlyLOD(
TEXT("foliage.OnlyLOD"),
-1,
TEXT("If greater than or equal to zero, only renders the foliage LOD at that level."));
static TAutoConsoleVariable<int32> CVarDisableCull(
TEXT("foliage.DisableCull"),
0,
#Associated Variable and Callsites
This variable is associated with another variable named CVarOnlyLOD
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/HierarchicalInstancedStaticMesh.cpp:49
Scope: file
Source code excerpt:
TEXT("If greater than or equal to zero, forces the foliage LOD to that level."));
static TAutoConsoleVariable<int32> CVarOnlyLOD(
TEXT("foliage.OnlyLOD"),
-1,
TEXT("If greater than or equal to zero, only renders the foliage LOD at that level."));
static TAutoConsoleVariable<int32> CVarDisableCull(
TEXT("foliage.DisableCull"),
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/HierarchicalInstancedStaticMesh.cpp:1215
Scope (from outer to inner):
file
function void FHierarchicalStaticMeshSceneProxy::FillDynamicMeshElements
Source code excerpt:
int64 TotalTriangles = 0;
int32 OnlyLOD = FMath::Min<int32>(CVarOnlyLOD.GetValueOnRenderThread(),InstancedRenderData.VertexFactories.Num() - 1);
int32 FirstLOD = FMath::Max((OnlyLOD < 0) ? 0 : OnlyLOD, static_cast<int32>(this->GetCurrentFirstLODIdx_Internal()));
int32 LastLODPlusOne = (OnlyLOD < 0) ? InstancedRenderData.VertexFactories.Num() : (OnlyLOD+1);
const bool bUseGPUScene = UseGPUScene(GetScene().GetShaderPlatform(), GetScene().GetFeatureLevel());
for (int32 LODIndex = FirstLOD; LODIndex < LastLODPlusOne; LODIndex++)