foliage.MaxTrianglesToRender
foliage.MaxTrianglesToRender
#Overview
name: foliage.MaxTrianglesToRender
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
This is an absolute limit on the number of foliage triangles to render in one traversal. This is used to prevent a silly LOD parameter mistake from causing the OS to kill the GPU.
It is referenced in 4
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of foliage.MaxTrianglesToRender is to set an absolute limit on the number of foliage triangles that can be rendered in a single traversal. This setting is primarily used in the rendering system, specifically for managing the rendering of foliage and hierarchical instanced static meshes.
This setting variable is utilized by the Unreal Engine’s rendering subsystem, particularly within the Engine module. It’s specifically used in the HierarchicalInstancedStaticMesh component, which is responsible for efficiently rendering large numbers of instanced static meshes, such as foliage.
The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 100,000,000 triangles, but can be modified at runtime through console commands or configuration files.
The associated variable CVarMaxTrianglesToRender directly interacts with foliage.MaxTrianglesToRender. They share the same value and purpose.
Developers must be aware that this variable acts as a safety measure to prevent potential GPU crashes due to rendering an excessive number of triangles. It’s particularly useful in scenarios where LOD (Level of Detail) parameters might be misconfigured, leading to an unexpectedly high triangle count.
Best practices when using this variable include:
- Keeping the default value unless there’s a specific need to change it.
- If modifying, ensure the new value is appropriate for the target hardware and doesn’t risk overwhelming the GPU.
- Using this in conjunction with proper LOD setup for foliage and instanced meshes.
- Monitoring performance when approaching this limit and optimizing foliage rendering if necessary.
Regarding the associated variable CVarMaxTrianglesToRender: It serves the same purpose as foliage.MaxTrianglesToRender, acting as the C++ interface for the console variable. It’s used within the rendering code to actually enforce the triangle limit. The value is retrieved using GetValueOnRenderThread() to ensure thread-safe access during rendering.
Developers should be aware that modifying CVarMaxTrianglesToRender directly in code will have the same effect as changing foliage.MaxTrianglesToRender through the console or configuration files. It’s generally preferable to use the console variable interface (foliage.MaxTrianglesToRender) for runtime modifications and leave CVarMaxTrianglesToRender for internal engine use.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/HierarchicalInstancedStaticMesh.cpp:76
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarMaxTrianglesToRender(
TEXT("foliage.MaxTrianglesToRender"),
100000000,
TEXT("This is an absolute limit on the number of foliage triangles to render in one traversal. This is used to prevent a silly LOD parameter mistake from causing the OS to kill the GPU."));
TAutoConsoleVariable<float> CVarFoliageMinimumScreenSize(
TEXT("foliage.MinimumScreenSize"),
0.000005f,
#Associated Variable and Callsites
This variable is associated with another variable named CVarMaxTrianglesToRender
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/HierarchicalInstancedStaticMesh.cpp:75
Scope: file
Source code excerpt:
TEXT("If greater than zero and dithered LOD is not used, then we use an overestimate of LOD instead of an underestimate."));
static TAutoConsoleVariable<int32> CVarMaxTrianglesToRender(
TEXT("foliage.MaxTrianglesToRender"),
100000000,
TEXT("This is an absolute limit on the number of foliage triangles to render in one traversal. This is used to prevent a silly LOD parameter mistake from causing the OS to kill the GPU."));
TAutoConsoleVariable<float> CVarFoliageMinimumScreenSize(
TEXT("foliage.MinimumScreenSize"),
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/HierarchicalInstancedStaticMesh.cpp:1318
Scope (from outer to inner):
file
function void FHierarchicalStaticMeshSceneProxy::FillDynamicMeshElements
Source code excerpt:
MeshBatchElement.bIsInstanceRuns = true;
if (TotalTriangles < (int64)CVarMaxTrianglesToRender.GetValueOnRenderThread())
{
Collector.AddMesh(ElementParams.ViewIndex, MeshBatch);
if (OverlayMaterial != nullptr)
{
FMeshBatch& OverlayMeshBatch = Collector.AllocateMesh();
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/HierarchicalInstancedStaticMesh.cpp:1449
Scope (from outer to inner):
file
function void FHierarchicalStaticMeshSceneProxy::FillDynamicMeshElements
Source code excerpt:
}
if (TotalTriangles < (int64)CVarMaxTrianglesToRender.GetValueOnRenderThread())
{
Collector.AddMesh(ElementParams.ViewIndex, MeshElement);
if (OverlayMaterial != nullptr)
{
FMeshBatch& OverlayMeshBatch = Collector.AllocateMesh();