r.RayTracing.Geometry.InstancedStaticMeshes.Culling
r.RayTracing.Geometry.InstancedStaticMeshes.Culling
#Overview
name: r.RayTracing.Geometry.InstancedStaticMeshes.Culling
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Enable culling for instances in ray tracing (default = 1 (Culling enabled))
It is referenced in 4
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.RayTracing.Geometry.InstancedStaticMeshes.Culling is to control the culling of instanced static meshes in ray tracing rendering. This setting variable is part of Unreal Engine’s ray tracing system, specifically focusing on optimizing the rendering of instanced static meshes.
This setting variable is primarily used in the Engine module, specifically within the InstancedStaticMesh rendering system. It’s referenced in the file “InstancedStaticMesh.cpp”, which suggests it’s closely tied to the rendering of instanced static meshes in ray tracing scenarios.
The value of this variable is set using a TAutoConsoleVariable, which means it can be adjusted at runtime through console commands. By default, it’s set to 1, enabling culling for instances in ray tracing.
This variable interacts closely with other ray tracing-related variables, such as CVarRayTracingInstancesCullClusterMaxRadiusMultiplier and CVarRayTracingInstancesCullAngle, which are used in conjunction to determine the culling behavior.
Developers must be aware that this variable significantly impacts performance and visual quality in ray tracing scenarios involving instanced static meshes. When enabled (set to 1), it can improve performance by reducing the number of instances that need to be processed for ray tracing. However, if set incorrectly, it might lead to visual artifacts or missing objects in the rendered scene.
Best practices when using this variable include:
- Keep it enabled (set to 1) for better performance in most scenarios.
- If experiencing issues with missing objects in ray traced renders, consider disabling it (set to 0) for debugging.
- Fine-tune it in conjunction with related variables like CVarRayTracingInstancesCullAngle for optimal results.
Regarding the associated variable CVarRayTracingRenderInstancesCulling:
This is the actual console variable that controls the r.RayTracing.Geometry.InstancedStaticMeshes.Culling setting. It’s an integer variable that directly represents the state of culling for instanced static meshes in ray tracing.
The purpose of CVarRayTracingRenderInstancesCulling is to provide a runtime-adjustable way to enable or disable culling for instanced static meshes in ray tracing scenarios.
This variable is used in the GetDynamicRayTracingInstances function of the FInstancedStaticMeshSceneProxy class, which is responsible for preparing instanced static meshes for ray tracing. The value of this variable determines whether culling logic is applied when generating ray tracing instances.
The value of CVarRayTracingRenderInstancesCulling can be set through console commands or adjusted in code using the GetValueOnRenderThread() method.
Developers should be aware that changes to this variable will immediately affect the ray tracing behavior of instanced static meshes. Setting it to 0 will disable culling, which might be useful for debugging but could impact performance in complex scenes.
Best practices for using CVarRayTracingRenderInstancesCulling include:
- Use it in conjunction with profiling tools to find the optimal balance between performance and visual quality.
- Consider exposing it as a configurable option in development builds for easier testing and optimization.
- Be cautious when disabling it (setting to 0) in production builds, as it may significantly impact performance.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp:116
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarRayTracingRenderInstancesCulling(
TEXT("r.RayTracing.Geometry.InstancedStaticMeshes.Culling"),
1,
TEXT("Enable culling for instances in ray tracing (default = 1 (Culling enabled))"));
static TAutoConsoleVariable<float> CVarRayTracingInstancesCullClusterMaxRadiusMultiplier(
TEXT("r.RayTracing.Geometry.InstancedStaticMeshes.CullClusterMaxRadiusMultiplier"),
20.0f,
#Associated Variable and Callsites
This variable is associated with another variable named CVarRayTracingRenderInstancesCulling
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp:115
Scope: file
Source code excerpt:
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,
TEXT("Enable culling for instances in ray tracing (default = 1 (Culling enabled))"));
static TAutoConsoleVariable<float> CVarRayTracingInstancesCullClusterMaxRadiusMultiplier(
TEXT("r.RayTracing.Geometry.InstancedStaticMeshes.CullClusterMaxRadiusMultiplier"),
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp:1730
Scope (from outer to inner):
file
function void FInstancedStaticMeshSceneProxy::GetDynamicRayTracingInstances
Source code excerpt:
};
if (CVarRayTracingRenderInstancesCulling.GetValueOnRenderThread() > 0)
{
// whether to use angular culling instead of distance, angle is halved as it is compared against the projection of the radius rather than the diameter
const float CullAngle = FMath::Min(CVarRayTracingInstancesCullAngle.GetValueOnRenderThread(), 179.9f) * 0.5f;
if (CullAngle < 0.0f)
{
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp:1809
Scope (from outer to inner):
file
function void FInstancedStaticMeshSceneProxy::GetDynamicRayTracingInstances
Source code excerpt:
// In no culling case, we are missing distance to view, so fill it in now
if (CVarRayTracingRenderInstancesCulling.GetValueOnRenderThread() == 0)
{
for (uint32 InstanceIndex = 0; InstanceIndex < (uint32)VisibleInstances.Num(); InstanceIndex++)
{
float InstanceRadius, DistanceToInstanceCenter, DistanceToInstanceStart;
GetDistanceToInstance(InstanceIndex, InstanceRadius, DistanceToInstanceCenter, DistanceToInstanceStart);