r.Nanite
r.Nanite
#Overview
name: r.Nanite
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Render static meshes using Nanite.
It is referenced in 8
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.Nanite is to control whether Unreal Engine’s Nanite virtualized geometry system is enabled for rendering static meshes. Nanite is a revolutionary technology in Unreal Engine 5 that allows for highly detailed geometric meshes to be rendered efficiently.
This setting variable is primarily used in the rendering system and affects various subsystems and modules within Unreal Engine, including:
- Static Mesh Rendering
- Instanced Static Mesh Components
- Landscape System
- Scene Rendering
The value of this variable is set as a console variable, which can be modified at runtime. It is initialized with a default value of 1 (enabled).
Several other variables and systems interact with r.Nanite:
- landscape.RenderNanite: Controls Nanite rendering specifically for landscapes
- DetailMode: Affects the level of detail in rendering
- GrassDensityScale and GrassCullDistanceScale: Related to landscape grass rendering
Developers should be aware of the following when using this variable:
- Changing the value of r.Nanite can trigger a global component recreation of render states.
- It affects the rendering of static meshes, instanced static meshes, and landscapes.
- The variable is checked in various parts of the engine to determine whether to use Nanite rendering.
Best practices when using this variable include:
- Ensure that your hardware and project settings support Nanite before enabling it.
- Be cautious when modifying this variable at runtime, as it can have performance implications.
- Consider the interaction with other rendering settings, especially those related to landscapes and level of detail.
- When developing for multiple platforms, be aware that some may not support Nanite, so you should provide fallback options.
- Use the UseNanite() function to check if Nanite is available and enabled, rather than directly accessing the console variable in most cases.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/StaticMeshRender.cpp:95
Scope: file
Source code excerpt:
// TODO: Should move this outside of SM, since Nanite can be used for multiple primitive types
TAutoConsoleVariable<int32> CVarRenderNaniteMeshes(
TEXT("r.Nanite"),
1,
TEXT("Render static meshes using Nanite."),
FConsoleVariableDelegate::CreateLambda([](IConsoleVariable* InVariable)
{
FGlobalComponentRecreateRenderStateContext Context;
}),
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp:4635
Scope (from outer to inner):
file
function static bool ComponentRequestsCPUAccess
Source code excerpt:
{
// TODO: Call UseNanite(GetScene()->GetShaderPlatform())?
//static const auto CVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Nanite"));
#if WITH_EDITOR
const bool bHasNaniteData = StaticMesh->IsNaniteEnabled();
#else
const FStaticMeshRenderData* RenderData = StaticMesh->GetRenderData();
const bool bHasNaniteData = RenderData->HasValidNaniteData();
#Loc: <Workspace>/Engine/Source/Runtime/Landscape/Private/LandscapeGrass.cpp:839
Scope (from outer to inner):
file
function static void GrassCVarSinkFunction
Source code excerpt:
int32 DetailMode = DetailModeCVar ? DetailModeCVar->GetInt() : 0;
static const IConsoleVariable* NaniteEnabledCVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Nanite"));
static int32 CachedNaniteEnabled = NaniteEnabledCVar ? NaniteEnabledCVar->GetInt() : 0;
int32 NaniteEnabled = NaniteEnabledCVar ? NaniteEnabledCVar->GetInt() : 0;
if (DetailMode != CachedDetailMode ||
GrassDensityScale != CachedGrassDensityScale ||
GrassCullDistanceScale != CachedGrassCullDistanceScale ||
#Loc: <Workspace>/Engine/Source/Runtime/Landscape/Private/LandscapeSubsystem.cpp:168
Scope (from outer to inner):
file
function void ULandscapeSubsystem::Initialize
Source code excerpt:
}
static IConsoleVariable* NaniteEnabledCVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Nanite"));
if (NaniteEnabledCVar && !NaniteEnabledCVar->OnChangedDelegate().IsBoundToObject(this))
{
NaniteEnabledCVar->OnChangedDelegate().AddUObject(this, &ULandscapeSubsystem::OnNaniteEnabledChanged);
}
static IConsoleVariable* LandscapeNaniteEnabledCVar = IConsoleManager::Get().FindConsoleVariable(TEXT("landscape.RenderNanite"));
#Loc: <Workspace>/Engine/Source/Runtime/Landscape/Private/LandscapeSubsystem.cpp:222
Scope (from outer to inner):
file
function void ULandscapeSubsystem::Deinitialize
Source code excerpt:
}
static IConsoleVariable* NaniteEnabledCVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Nanite"));
if (NaniteEnabledCVar)
{
NaniteEnabledCVar->OnChangedDelegate().RemoveAll(this);
}
static IConsoleVariable* LandscapeNaniteEnabledCVar = IConsoleManager::Get().FindConsoleVariable(TEXT("landscape.RenderNanite"));
#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/RenderUtils.cpp:1359
Scope (from outer to inner):
file
function bool UseNanite
Source code excerpt:
bool UseNanite(EShaderPlatform ShaderPlatform, bool bCheckForAtomicSupport /*= true*/, bool bCheckForProjectSetting /*= true*/)
{
static const auto EnableNaniteCVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Nanite"));
const bool bNaniteEnabled = (EnableNaniteCVar != nullptr) ? (EnableNaniteCVar->GetInt() != 0) : true;
return bNaniteEnabled && DoesRuntimeSupportNanite(ShaderPlatform, bCheckForAtomicSupport, bCheckForProjectSetting);
}
bool UseVirtualShadowMaps(EShaderPlatform ShaderPlatform, const FStaticFeatureLevel FeatureLevel)
{
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessVisualizeLevelInstance.cpp:55
Scope: file
Source code excerpt:
check(Inputs.SceneDepth.IsValid());
const bool bNaniteEnabled = DoesPlatformSupportNanite(GMaxRHIShaderPlatform); // TODO: Respect r.Nanite
RDG_EVENT_SCOPE(GraphBuilder, "EditorVisualizeLevelInstance");
const uint32 NumSamples = View.GetSceneTexturesConfig().NumSamples;
// Patch uniform buffers with updated state for rendering the outline mesh draw commands.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:2951
Scope (from outer to inner):
file
function FIntPoint FSceneRenderer::QuantizeViewRectMin
Source code excerpt:
// Some code paths of Nanite require that view rect is aligned on 8x8 boundary.
static const auto EnableNaniteCVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Nanite"));
const bool bNaniteEnabled = (EnableNaniteCVar != nullptr) ? (EnableNaniteCVar->GetInt() != 0) : true;
const int kMinimumNaniteDivisor = 8; // HTILE size
QuantizeSceneBufferSize(ViewRectMin, Out, bNaniteEnabled ? kMinimumNaniteDivisor : 0);
return Out;
}