r.RayTracing.Geometry.StaticMeshes
r.RayTracing.Geometry.StaticMeshes
#Overview
name: r.RayTracing.Geometry.StaticMeshes
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Include static meshes in ray tracing effects (default = 1 (static meshes enabled in ray tracing))
It is referenced in 6
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.RayTracing.Geometry.StaticMeshes is to control the inclusion of static meshes in ray tracing effects within Unreal Engine 5. This setting variable is primarily used in the rendering system, specifically for ray tracing functionality.
Based on the callsites, this variable is utilized by the following Unreal Engine subsystems and modules:
- Engine module (StaticMeshRender.cpp, PrimitiveSceneProxy.cpp)
- Rendering module (NaniteResources.cpp)
- Renderer module (RayTracing.cpp)
The value of this variable is set through a console variable (CVar) system. It is initialized with a default value of 1, which means static meshes are enabled in ray tracing by default.
This variable interacts with several other ray tracing-related variables, such as:
- r.RayTracing.Geometry.StaticMeshes.WPO
- r.RayTracing.Geometry.HierarchicalInstancedStaticMesh
- r.RayTracing.Geometry.NaniteProxies
- r.RayTracing.Geometry.LandscapeGrass
Developers must be aware of the following when using this variable:
- Setting it to 0 will exclude static meshes from ray tracing effects, which can significantly impact visual quality but may improve performance.
- It affects both regular static meshes and Nanite meshes.
- Changes to this variable may require a refresh of ray tracing instances in the scene.
Best practices when using this variable include:
- Keep it enabled (set to 1) for the best visual quality in ray-traced scenes.
- Consider disabling it temporarily for performance profiling or debugging.
- Be aware of its interaction with other ray tracing geometry settings for a comprehensive understanding of the ray tracing setup.
Regarding the associated variable CVarRayTracingStaticMeshes:
The purpose of CVarRayTracingStaticMeshes is to serve as the actual console variable that controls the r.RayTracing.Geometry.StaticMeshes setting. It is defined using the TAutoConsoleVariable template class, which allows for easy integration with Unreal Engine’s console variable system.
This variable is set in the Engine module, specifically in StaticMeshRender.cpp. It shares the same value and purpose as r.RayTracing.Geometry.StaticMeshes.
Developers should be aware that:
- This is the actual variable that should be modified when changing the setting through code or console commands.
- It is used directly in some parts of the code, such as in the FStaticMeshSceneProxy::GetDynamicRayTracingInstances function.
Best practices for using CVarRayTracingStaticMeshes include:
- Use IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT(“r.RayTracing.Geometry.StaticMeshes”)) to access its value in C++ code.
- When modifying the value, be aware that it may require a scene update or recompilation of ray tracing acceleration structures.
- Consider the performance implications of changing this value at runtime, especially in performance-critical sections of code.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/StaticMeshRender.cpp:150
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarRayTracingStaticMeshes(
TEXT("r.RayTracing.Geometry.StaticMeshes"),
1,
TEXT("Include static meshes in ray tracing effects (default = 1 (static meshes enabled in ray tracing))"));
static TAutoConsoleVariable<int32> CVarRayTracingStaticMeshesWPO(
TEXT("r.RayTracing.Geometry.StaticMeshes.WPO"),
1,
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PrimitiveSceneProxy.cpp:1781
Scope (from outer to inner):
file
function ERayTracingPrimitiveFlags FPrimitiveSceneProxy::GetCachedRayTracingInstance
Source code excerpt:
}
static const auto RayTracingStaticMeshesCVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.RayTracing.Geometry.StaticMeshes"));
if ((bIsStaticMesh || bIsNaniteMesh) && RayTracingStaticMeshesCVar && RayTracingStaticMeshesCVar->GetValueOnRenderThread() <= 0)
{
return ERayTracingPrimitiveFlags::Exclude;
}
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Rendering/NaniteResources.cpp:1923
Scope (from outer to inner):
file
namespace Nanite
function ERayTracingPrimitiveFlags FSceneProxy::GetCachedRayTracingInstance
Source code excerpt:
}
static const auto RayTracingStaticMeshesCVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.RayTracing.Geometry.StaticMeshes"));
if (RayTracingStaticMeshesCVar && RayTracingStaticMeshesCVar->GetValueOnRenderThread() <= 0)
{
return ERayTracingPrimitiveFlags::Exclude;
}
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/RayTracing/RayTracing.cpp:104
Scope (from outer to inner):
file
function static void RefreshRayTracingInstancesSinkFunction
Source code excerpt:
static void RefreshRayTracingInstancesSinkFunction()
{
static const auto RayTracingStaticMeshesCVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.RayTracing.Geometry.StaticMeshes"));
static const auto RayTracingHISMCVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.RayTracing.Geometry.HierarchicalInstancedStaticMesh"));
static const auto RayTracingNaniteProxiesCVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.RayTracing.Geometry.NaniteProxies"));
static const auto RayTracingLandscapeGrassCVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.RayTracing.Geometry.LandscapeGrass"));
static int32 CachedRayTracingStaticMeshes = RayTracingStaticMeshesCVar->GetValueOnGameThread();
static int32 CachedRayTracingHISM = RayTracingHISMCVar->GetValueOnGameThread();
#Associated Variable and Callsites
This variable is associated with another variable named CVarRayTracingStaticMeshes
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/StaticMeshRender.cpp:149
Scope: file
Source code excerpt:
);
static TAutoConsoleVariable<int32> CVarRayTracingStaticMeshes(
TEXT("r.RayTracing.Geometry.StaticMeshes"),
1,
TEXT("Include static meshes in ray tracing effects (default = 1 (static meshes enabled in ray tracing))"));
static TAutoConsoleVariable<int32> CVarRayTracingStaticMeshesWPO(
TEXT("r.RayTracing.Geometry.StaticMeshes.WPO"),
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/StaticMeshRender.cpp:1885
Scope (from outer to inner):
file
function void FStaticMeshSceneProxy::GetDynamicRayTracingInstances
Source code excerpt:
void FStaticMeshSceneProxy::GetDynamicRayTracingInstances(FRayTracingMaterialGatheringContext& Context, TArray<FRayTracingInstance>& OutRayTracingInstances )
{
if (DynamicRayTracingGeometries.IsEmpty() || CVarRayTracingStaticMeshes.GetValueOnRenderThread() == 0)
{
return;
}
checkf(CVarRayTracingStaticMeshesWPO.GetValueOnRenderThread() == 1,
TEXT("Proxy should only have entries in DynamicRayTracingGeometries when WPO evaluation is enabled"));