r.RayTracing.Geometry.InstancedStaticMeshes.EvaluateWPO

r.RayTracing.Geometry.InstancedStaticMeshes.EvaluateWPO

#Overview

name: r.RayTracing.Geometry.InstancedStaticMeshes.EvaluateWPO

This variable is created as a Console Variable (cvar).

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.RayTracing.Geometry.InstancedStaticMeshes.EvaluateWPO is to control whether World Position Offset (WPO) should be evaluated on instanced static meshes in ray tracing scenarios.

This setting variable is primarily used in the ray tracing subsystem of Unreal Engine 5, specifically for handling instanced static meshes. It is part of the rendering system, focusing on the interaction between ray tracing and geometry instancing.

The value of this variable is set through the console variable system in Unreal Engine. It’s defined as a TAutoConsoleVariable named CVarRayTracingInstancesEvaluateWPO in the InstancedStaticMesh.cpp file.

The variable interacts closely with the ray tracing and instanced static mesh rendering systems. It’s used to determine whether World Position Offset should be evaluated for instanced static meshes in ray tracing scenarios.

Developers must be aware that this variable has three possible values: 0: WPO evaluation is off (default) 1: WPO evaluation is on for all instanced static meshes with WPO -1: WPO evaluation is on only for meshes with “evaluate WPO” explicitly enabled

Best practices when using this variable include:

  1. Use the default (0) for optimal performance when WPO is not needed.
  2. Use 1 when you need WPO on all eligible instanced static meshes.
  3. Use -1 for fine-grained control, enabling WPO only on specific meshes.

Regarding the associated variable CVarRayTracingInstancesEvaluateWPO:

This is the actual console variable that stores and manages the value of r.RayTracing.Geometry.InstancedStaticMeshes.EvaluateWPO. It’s defined using the TAutoConsoleVariable template, which is a part of Unreal Engine’s console variable system.

The purpose of CVarRayTracingInstancesEvaluateWPO is to provide a runtime-accessible way to control the WPO evaluation behavior for instanced static meshes in ray tracing.

This variable is used in the FInstancedStaticMeshSceneProxy::GetDynamicRayTracingInstances function to determine whether and how to apply World Position Offset for ray tracing instances.

Developers should be aware that changes to this console variable will affect ray tracing performance and visual accuracy, especially for instanced static meshes using World Position Offset.

Best practices for using CVarRayTracingInstancesEvaluateWPO include:

  1. Use it for debugging and performance tuning in development builds.
  2. Consider exposing it as a configurable option for advanced users if WPO evaluation has a significant impact on your game’s performance or visual quality.
  3. Be cautious about changing its value at runtime, as it may have performance implications.

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp:148

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarRayTracingInstancesEvaluateWPO(
	TEXT("r.RayTracing.Geometry.InstancedStaticMeshes.EvaluateWPO"),
	0,
	TEXT("Whether to evaluate WPO on instanced static meshes\n")
	TEXT("  0 - off (default)")
	TEXT("  1 - on for all with WPO")
	TEXT(" -1 - on only for meshes with evaluate WPO enabled")
);

#Associated Variable and Callsites

This variable is associated with another variable named CVarRayTracingInstancesEvaluateWPO. They share the same value. See the following C++ source code.

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp:147

Scope: file

Source code excerpt:

);

static TAutoConsoleVariable<int32> CVarRayTracingInstancesEvaluateWPO(
	TEXT("r.RayTracing.Geometry.InstancedStaticMeshes.EvaluateWPO"),
	0,
	TEXT("Whether to evaluate WPO on instanced static meshes\n")
	TEXT("  0 - off (default)")
	TEXT("  1 - on for all with WPO")
	TEXT(" -1 - on only for meshes with evaluate WPO enabled")

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp:1662

Scope (from outer to inner):

file
function     void FInstancedStaticMeshSceneProxy::GetDynamicRayTracingInstances

Source code excerpt:

	const uint32 SimulatedInstances = FMath::Min(RequestedSimulatedInstances == -1 ? InstanceCount : FMath::Clamp(RequestedSimulatedInstances, 1u, InstanceCount), MaxSimulatedInstances);

	const int32 WPOEvalMode = CVarRayTracingInstancesEvaluateWPO.GetValueOnRenderThread();
	const bool bWantsWPOEvaluation = WPOEvalMode < 0 ? bDynamicRayTracingGeometry : WPOEvalMode != 0;
	const bool bHasWorldPositionOffset = bWantsWPOEvaluation && bAnySegmentUsesWorldPositionOffset;

	if (bHasWorldPositionOffset)
	{
		int32 SectionCount = InstancedRenderData.LODModels[LOD].Sections.Num();