r.RayTracing.Geometry.InstancedStaticMeshes.MinLOD
r.RayTracing.Geometry.InstancedStaticMeshes.MinLOD
#Overview
name: r.RayTracing.Geometry.InstancedStaticMeshes.MinLOD
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Clamps minimum LOD to this value (default = 0, highest resolution LOD may be used)
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.RayTracing.Geometry.InstancedStaticMeshes.MinLOD is to control the minimum Level of Detail (LOD) used for instanced static meshes in ray tracing calculations. This setting is part of Unreal Engine’s ray tracing system, specifically targeting the rendering of instanced static meshes.
This setting variable is primarily used by the Engine module, specifically within the InstancedStaticMesh rendering subsystem. It’s referenced in the InstancedStaticMesh.cpp file, which handles the rendering of instanced static meshes.
The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 0, which allows the highest resolution LOD to be used. Developers can change this value at runtime using console commands or through configuration files.
This variable interacts closely with the RenderData and LODResources of instanced static meshes. It’s used to clamp the minimum LOD level that can be used for ray tracing, potentially improving performance at the cost of some visual fidelity.
Developers should be aware that increasing this value will force the use of lower resolution LODs for instanced static meshes in ray tracing, which can improve performance but may reduce visual quality. It’s important to balance performance needs with visual requirements when adjusting this setting.
Best practices when using this variable include:
- Start with the default value (0) and increase it only if necessary for performance reasons.
- Test thoroughly with different values to find the optimal balance between performance and visual quality for your specific use case.
- Consider exposing this setting to end-users if your application benefits from runtime adjustment of ray tracing performance.
Regarding the associated variable CVarRayTracingInstancedStaticMeshesMinLOD:
This is the actual console variable that stores and provides access to the r.RayTracing.Geometry.InstancedStaticMeshes.MinLOD setting. It’s defined using the TAutoConsoleVariable template, which is part of Unreal Engine’s console variable system.
The purpose of CVarRayTracingInstancedStaticMeshesMinLOD is to provide a programmatic interface to read and potentially modify the minimum LOD setting for instanced static meshes in ray tracing.
This variable is used directly in the FInstancedStaticMeshSceneProxy::GetDynamicRayTracingInstances function to determine the appropriate LOD level for ray tracing calculations.
Developers should be aware that this variable is accessed on the render thread (GetValueOnRenderThread()), which is important for thread safety in rendering code.
Best practices for using CVarRayTracingInstancedStaticMeshesMinLOD include:
- Access the value on the appropriate thread (render thread in this case) to avoid race conditions.
- Use the FMath::Clamp function when applying the value to ensure it stays within valid bounds for the available LOD levels.
- Consider caching the value if it’s accessed frequently, as reading console variables can have a small performance cost.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp:111
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarRayTracingInstancedStaticMeshesMinLOD(
TEXT("r.RayTracing.Geometry.InstancedStaticMeshes.MinLOD"),
0,
TEXT("Clamps minimum LOD to this value (default = 0, highest resolution LOD may be used)"));
static TAutoConsoleVariable<int32> CVarRayTracingRenderInstancesCulling(
TEXT("r.RayTracing.Geometry.InstancedStaticMeshes.Culling"),
1,
#Associated Variable and Callsites
This variable is associated with another variable named CVarRayTracingInstancedStaticMeshesMinLOD
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp:110
Scope: file
Source code excerpt:
TEXT("Include static mesh instances in ray tracing effects (default = 1 (Instances enabled in ray tracing))"));
static TAutoConsoleVariable<int32> CVarRayTracingInstancedStaticMeshesMinLOD(
TEXT("r.RayTracing.Geometry.InstancedStaticMeshes.MinLOD"),
0,
TEXT("Clamps minimum LOD to this value (default = 0, highest resolution LOD may be used)"));
static TAutoConsoleVariable<int32> CVarRayTracingRenderInstancesCulling(
TEXT("r.RayTracing.Geometry.InstancedStaticMeshes.Culling"),
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp:1618
Scope (from outer to inner):
file
function void FInstancedStaticMeshSceneProxy::GetDynamicRayTracingInstances
Source code excerpt:
}
uint32 MinAllowedLOD = FMath::Clamp<int32>(CVarRayTracingInstancedStaticMeshesMinLOD.GetValueOnRenderThread(), 0, RenderData->LODResources.Num() - 1);
uint32 LOD = FMath::Max<uint32>(MinAllowedLOD, GetCurrentFirstLODIdx_RenderThread());
if (!RenderData->LODResources[LOD].RayTracingGeometry.IsInitialized())
{
return;
}