r.Nanite.MinPixelsPerEdgeHW
r.Nanite.MinPixelsPerEdgeHW
#Overview
name: r.Nanite.MinPixelsPerEdgeHW
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
The triangle edge length in pixels at which Nanite starts using the hardware rasterizer.
It is referenced in 6
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.Nanite.MinPixelsPerEdgeHW is to control the threshold at which Nanite, Unreal Engine 5’s geometry system, switches from software rasterization to hardware rasterization for rendering triangles. Specifically, it sets the minimum triangle edge length in pixels at which Nanite begins using the hardware rasterizer.
This setting variable is primarily used in the Nanite rendering system, which is part of Unreal Engine 5’s renderer module. Based on the callsites, it’s referenced in the Nanite culling and rasterization subsystem (NaniteCullRaster.cpp) and in the Virtual Shadow Map system (VirtualShadowMapArray.cpp).
The value of this variable is set as a console variable with a default value of 32.0f. It can be changed at runtime through the console or configuration files.
This variable interacts closely with CVarNaniteMaxPixelsPerEdge, as seen in the code snippets. Together, these variables define the range of triangle sizes where Nanite transitions between different rendering techniques.
Developers should be aware that adjusting this value can affect the performance and visual quality of Nanite-rendered geometry. Lower values may increase the use of hardware rasterization, potentially improving performance but possibly at the cost of visual fidelity for smaller triangles.
Best practices when using this variable include:
- Testing different values to find the optimal balance between performance and visual quality for your specific project.
- Considering the target hardware capabilities when adjusting this value.
- Using it in conjunction with r.Nanite.MaxPixelsPerEdge for fine-tuning Nanite’s behavior.
Regarding the associated variable CVarNaniteMinPixelsPerEdgeHW:
The purpose of CVarNaniteMinPixelsPerEdgeHW is to provide a programmatic interface to the r.Nanite.MinPixelsPerEdgeHW console variable within the engine’s C++ code. It allows the engine to read and potentially modify this value at runtime.
This variable is used in the same subsystems as r.Nanite.MinPixelsPerEdgeHW, primarily in the Nanite rendering pipeline and Virtual Shadow Map system.
The value of CVarNaniteMinPixelsPerEdgeHW is set when the console variable is initialized, and it reflects any changes made to r.Nanite.MinPixelsPerEdgeHW.
CVarNaniteMinPixelsPerEdgeHW interacts directly with r.Nanite.MinPixelsPerEdgeHW, essentially serving as its in-code representation.
Developers should be aware that this variable is used to access the console variable’s value in C++ code, typically via the GetValueOnRenderThread() method.
Best practices for using CVarNaniteMinPixelsPerEdgeHW include:
- Using it to read the current value of r.Nanite.MinPixelsPerEdgeHW in render thread code.
- Avoiding direct modification of this variable; instead, modify r.Nanite.MinPixelsPerEdgeHW through the console or configuration files.
- Being aware of potential thread safety issues when accessing this variable outside of the render thread.
#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:153
Scope: file
Source code excerpt:
TAutoConsoleVariable<float> CVarNaniteMinPixelsPerEdgeHW(
TEXT("r.Nanite.MinPixelsPerEdgeHW"),
32.0f,
TEXT("The triangle edge length in pixels at which Nanite starts using the hardware rasterizer."),
ECVF_RenderThreadSafe
);
TAutoConsoleVariable<float> CVarNaniteDicingRate(
#Associated Variable and Callsites
This variable is associated with another variable named CVarNaniteMinPixelsPerEdgeHW
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Nanite/NaniteCullRaster.cpp:152
Scope: file
Source code excerpt:
);
TAutoConsoleVariable<float> CVarNaniteMinPixelsPerEdgeHW(
TEXT("r.Nanite.MinPixelsPerEdgeHW"),
32.0f,
TEXT("The triangle edge length in pixels at which Nanite starts using the hardware rasterizer."),
ECVF_RenderThreadSafe
);
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Nanite/NaniteShared.cpp:18
Scope: file
Source code excerpt:
extern TAutoConsoleVariable<float> CVarNaniteMaxPixelsPerEdge;
extern TAutoConsoleVariable<float> CVarNaniteMinPixelsPerEdgeHW;
// Optimized compute dual depth export pass on supported platforms.
int32 GNaniteExportDepth = 1;
static FAutoConsoleVariableRef CVarNaniteExportDepth(
TEXT("r.Nanite.ExportDepth"),
GNaniteExportDepth,
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Nanite/NaniteShared.cpp:118
Scope (from outer to inner):
file
namespace Nanite
function FPackedView CreatePackedView
Source code excerpt:
const float NaniteMaxPixelsPerEdge = CVarNaniteMaxPixelsPerEdge.GetValueOnRenderThread() * Params.MaxPixelsPerEdgeMultipler;
const float NaniteMinPixelsPerEdgeHW = CVarNaniteMinPixelsPerEdgeHW.GetValueOnRenderThread();
const FVector CullingViewOrigin = Params.bUseCullingViewOverrides ? Params.CullingViewOrigin : Params.ViewMatrices.GetViewOrigin();
// We bake the view lod scales into ScreenMultiple since the two things are always used together.
const float ViewDistanceLODScale = GetCachedScalabilityCVars().StaticMeshLODDistanceScale * Params.ViewLODDistanceFactor;
const float ScreenMultiple = FMath::Max(Params.ViewMatrices.GetProjectionMatrix().M[0][0], Params.ViewMatrices.GetProjectionMatrix().M[1][1]) / ViewDistanceLODScale;
const float CullingViewScreenMulitple = Params.bUseCullingViewOverrides && Params.CullingViewScreenMultiple > 0.f ? Params.CullingViewScreenMultiple : ScreenMultiple;
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VirtualShadowMaps/VirtualShadowMapArray.cpp:39
Scope: file
Source code excerpt:
extern int32 GVSMMaxPageAgeSinceLastRequest;
extern TAutoConsoleVariable<float> CVarNaniteMaxPixelsPerEdge;
extern TAutoConsoleVariable<float> CVarNaniteMinPixelsPerEdgeHW;
int32 GVSMShowLightDrawEvents = 0;
FAutoConsoleVariableRef CVarVSMShowLightDrawEvents(
TEXT("r.Shadow.Virtual.ShowLightDrawEvents"),
GVSMShowLightDrawEvents,
TEXT("Enable Virtual Shadow Maps per-light draw events - may affect performance especially when there are many small lights in the scene."),
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VirtualShadowMaps/VirtualShadowMapArray.cpp:1986
Scope (from outer to inner):
file
function void FVirtualShadowMapArray::CreateMipViews
Source code excerpt:
const float NaniteMaxPixelsPerEdge = CVarNaniteMaxPixelsPerEdge.GetValueOnRenderThread();
const float NaniteMinPixelsPerEdgeHW = CVarNaniteMinPixelsPerEdgeHW.GetValueOnRenderThread();
// 1. create derivative views for each of the Mip levels,
Views.AddDefaulted( NumPrimaryViews * ( FVirtualShadowMap::MaxMipLevels - 1) );
int32 MaxMips = 0;
for (int32 ViewIndex = 0; ViewIndex < NumPrimaryViews; ++ViewIndex)