r.Nanite.Culling.DrawDistance

r.Nanite.Culling.DrawDistance

#Overview

name: r.Nanite.Culling.DrawDistance

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.Nanite.Culling.DrawDistance is to control the culling behavior of Nanite geometry based on draw distance. Specifically, it allows developers to test disabling Nanite culling due to instance draw distance when set to 0.

This setting variable is primarily used in the rendering system, particularly in the Nanite subsystem of Unreal Engine 5. It is part of the culling mechanism that optimizes rendering performance by determining which geometry should be drawn based on its distance from the camera.

The Unreal Engine renderer module relies on this setting variable, as evidenced by its usage in the NaniteCullRaster.cpp file.

The value of this variable is set through a console variable (CVar) system. It is initialized with a default value of 1, meaning draw distance culling is enabled by default.

This variable interacts with the debug flags used in the Nanite rendering process. When set to 0, it adds the NANITE_DEBUG_FLAG_DISABLE_CULL_DRAW_DISTANCE flag to the DebugFlags variable, which disables draw distance culling for debugging purposes.

Developers must be aware that changing this variable can significantly impact rendering performance and visual output. Disabling draw distance culling may result in more geometry being rendered than necessary, potentially affecting frame rates.

Best practices when using this variable include:

  1. Keep it at its default value (1) for normal operation to maintain optimal performance.
  2. Use it temporarily for debugging or testing purposes when investigating culling-related issues.
  3. Be cautious when disabling it in production builds, as it may negatively impact performance.

Regarding the associated variable CVarNaniteCullingDrawDistance:

The purpose of CVarNaniteCullingDrawDistance is to provide a programmatic interface to control the r.Nanite.Culling.DrawDistance setting within the C++ code of the engine.

This variable is used directly in the Nanite renderer implementation to check the current state of the draw distance culling setting. It’s part of the engine’s internal systems and not typically manipulated directly by game developers.

The value of CVarNaniteCullingDrawDistance is set automatically based on the r.Nanite.Culling.DrawDistance console variable.

CVarNaniteCullingDrawDistance interacts with the DebugFlags variable in the Nanite renderer, influencing the culling behavior of the system.

Developers should be aware that this variable is part of the engine’s internal implementation and should not be modified directly. Instead, they should use the r.Nanite.Culling.DrawDistance console variable to control this behavior.

Best practices for CVarNaniteCullingDrawDistance include:

  1. Avoid modifying it directly in custom engine code unless absolutely necessary.
  2. Use the corresponding console variable (r.Nanite.Culling.DrawDistance) to control this setting.
  3. Be aware of its existence when debugging Nanite-related rendering issues.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Nanite/NaniteCullRaster.cpp:214

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarNaniteCullingDrawDistance(
	TEXT("r.Nanite.Culling.DrawDistance"),
	1,
	TEXT("Set to 0 to test disabling Nanite culling due to instance draw distance."),
	ECVF_RenderThreadSafe
);

static TAutoConsoleVariable<int32> CVarNaniteCullingWPODisableDistance(

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Nanite/NaniteCullRaster.cpp:213

Scope: file

Source code excerpt:

);

static TAutoConsoleVariable<int32> CVarNaniteCullingDrawDistance(
	TEXT("r.Nanite.Culling.DrawDistance"),
	1,
	TEXT("Set to 0 to test disabling Nanite culling due to instance draw distance."),
	ECVF_RenderThreadSafe
);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Nanite/NaniteCullRaster.cpp:2957

Scope (from outer to inner):

file
namespace    Nanite
function     FRenderer::FRenderer

Source code excerpt:

		}

		if (CVarNaniteCullingDrawDistance.GetValueOnRenderThread() == 0)
		{
			DebugFlags |= NANITE_DEBUG_FLAG_DISABLE_CULL_DRAW_DISTANCE;
		}

		if (CVarNaniteCullingWPODisableDistance.GetValueOnRenderThread() == 0)
		{