r.RayTracing.Geometry.InstancedStaticMeshes.CullAngle

r.RayTracing.Geometry.InstancedStaticMeshes.CullAngle

#Overview

name: r.RayTracing.Geometry.InstancedStaticMeshes.CullAngle

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.CullAngle is to control the culling of instanced static meshes in ray tracing geometry. It defines a solid angle used for testing instance bounds against for culling purposes.

This setting variable is primarily used in the Unreal Engine’s rendering system, specifically in the ray tracing subsystem for instanced static meshes. It is referenced in the Engine module, as seen in the InstancedStaticMesh.cpp file.

The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 2.0 degrees, but can be modified at runtime through console commands or project settings.

The associated variable CVarRayTracingInstancesCullAngle interacts directly with r.RayTracing.Geometry.InstancedStaticMeshes.CullAngle. They share the same value and purpose.

Developers must be aware that:

  1. The value represents a solid angle in degrees.
  2. Setting it to -1 switches the culling method to distance-based culling instead of angle-based.
  3. The actual angle used in calculations is halved, as it’s compared against the projection of the radius rather than the diameter.
  4. There’s an upper limit of 179.9 degrees enforced in the code.

Best practices when using this variable include:

  1. Fine-tuning the value to balance between performance and visual quality.
  2. Consider using distance-based culling (-1) for scenes where angular culling might not be optimal.
  3. Monitor performance impact when adjusting this value, especially in scenes with many instanced static meshes.

Regarding the associated variable CVarRayTracingInstancesCullAngle:

The purpose of CVarRayTracingInstancesCullAngle is to provide a programmatic interface to the r.RayTracing.Geometry.InstancedStaticMeshes.CullAngle setting. It allows the engine to access and modify the culling angle value at runtime.

This variable is used in the same Unreal Engine subsystem (ray tracing for instanced static meshes) and module (Engine) as r.RayTracing.Geometry.InstancedStaticMeshes.CullAngle.

The value of CVarRayTracingInstancesCullAngle is set when the engine initializes the console variable system. It can be accessed and modified through the GetValueOnRenderThread() method.

CVarRayTracingInstancesCullAngle directly interacts with r.RayTracing.Geometry.InstancedStaticMeshes.CullAngle, as they represent the same setting.

Developers should be aware that:

  1. This is a TAutoConsoleVariable, meaning it’s type-safe and automatically registered with the console variable system.
  2. Changes to this variable will affect ray tracing performance and potentially visual output.

Best practices for using CVarRayTracingInstancesCullAngle include:

  1. Use GetValueOnRenderThread() when accessing the value in render thread code.
  2. Consider exposing this variable in debug UI for easy tweaking during development.
  3. Document any project-specific optimal values found during development for future reference.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:


static TAutoConsoleVariable<float> CVarRayTracingInstancesCullAngle(
	TEXT("r.RayTracing.Geometry.InstancedStaticMeshes.CullAngle"),
	2.0f,
	TEXT("Solid angle to test instance bounds against for culling (default 2 degrees)\n")
	TEXT("  -1 => use distance based culling")
);

static TAutoConsoleVariable<int32> CVarRayTracingInstancesEvaluateWPO(

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

	TEXT("Cull radius for small instances (default = 1000 (10m))"));

static TAutoConsoleVariable<float> CVarRayTracingInstancesCullAngle(
	TEXT("r.RayTracing.Geometry.InstancedStaticMeshes.CullAngle"),
	2.0f,
	TEXT("Solid angle to test instance bounds against for culling (default 2 degrees)\n")
	TEXT("  -1 => use distance based culling")
);

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

Scope (from outer to inner):

file
function     void FInstancedStaticMeshSceneProxy::GetDynamicRayTracingInstances

Source code excerpt:

	{
		// 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)
		{
			//
			//  Distance based culling
			//    Check nodes for being within minimum distances