r.Nanite.AllowLegacyMaterials

r.Nanite.AllowLegacyMaterials

#Overview

name: r.Nanite.AllowLegacyMaterials

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.AllowLegacyMaterials is to control whether support for Nanite legacy materials is enabled in Unreal Engine 5’s rendering system.

This setting variable is primarily used by the Nanite rendering subsystem within Unreal Engine 5. It is referenced in the Engine and RenderCore modules, specifically in files related to Nanite resources and rendering utilities.

The value of this variable is set as a console variable (CVar) with a default value of 1, meaning legacy materials support is enabled by default. It can be modified through the console or configuration files.

This variable interacts with other Nanite-related variables, such as r.Nanite.ComputeMaterials and r.Nanite.AllowTessellation. Together, these variables control various aspects of Nanite’s material rendering capabilities.

Developers must be aware that this variable is marked as read-only and render thread safe. Changing its value at runtime may not be possible or may require special handling.

Best practices when using this variable include:

  1. Consider performance implications when enabling legacy materials support for Nanite.
  2. Use in conjunction with other Nanite-related variables to fine-tune rendering behavior.
  3. Be cautious about changing its value, as it may affect shader compilation and overall rendering pipeline.
  4. Test thoroughly when modifying this setting to ensure compatibility with existing materials and desired visual outcomes.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Rendering/NaniteResources.cpp:64

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarNaniteAllowLegacyMaterials(
	TEXT("r.Nanite.AllowLegacyMaterials"),
	1,
	TEXT("Whether to enable support for Nanite legacy materials"),
	ECVF_RenderThreadSafe | ECVF_ReadOnly);

static TAutoConsoleVariable<int32> CVarNaniteUseComputeMaterials(
	TEXT("r.Nanite.ComputeMaterials"),

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/RenderUtils.cpp:1289

Scope (from outer to inner):

file
function     bool NaniteLegacyMaterialsSupported

Source code excerpt:

bool NaniteLegacyMaterialsSupported()
{
	static const auto AllowLegacyMaterials = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Nanite.AllowLegacyMaterials"));
	static const bool bAllowLegacyMaterials = (AllowLegacyMaterials && AllowLegacyMaterials->GetValueOnAnyThread() != 0);
	return bAllowLegacyMaterials;
}

bool UseNaniteComputeMaterials()
{

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/Shader.cpp:2370

Scope (from outer to inner):

file
function     void ShaderMapAppendKeyString

Source code excerpt:

		static const auto CVarAllowTess = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Nanite.AllowTessellation"));
		static const auto CVarAllowCSMat = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Nanite.AllowComputeMaterials"));
		static const auto CVarAllowPSMat = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Nanite.AllowLegacyMaterials"));

		KeyString.Appendf(
			TEXT("_Nanite-Tess%dCSMat%dPSMat%d"),
			CVarAllowTess ? CVarAllowTess->GetInt() : 0,
			CVarAllowCSMat ? CVarAllowCSMat->GetInt() : 0,
			CVarAllowPSMat ? CVarAllowPSMat->GetInt() : 0