r.Nanite.ViewMeshLODBias.Offset

r.Nanite.ViewMeshLODBias.Offset

#Overview

name: r.Nanite.ViewMeshLODBias.Offset

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.ViewMeshLODBias.Offset is to apply an LOD (Level of Detail) offset for rasterized Nanite meshes in the main viewport when using Temporal Super Resolution (TSR).

This setting variable is primarily used in the rendering system of Unreal Engine 5, specifically within the Nanite geometry system. It’s part of the Renderer module, as evidenced by its location in the DeferredShadingRenderer.cpp file.

The value of this variable is set through a console variable (CVarNaniteViewMeshLODBiasOffset) with a default value of 0.0f. It can be modified at runtime using console commands or through engine configuration files.

This variable interacts closely with another variable, CVarNaniteViewMeshLODBiasMin, which sets the minimum LOD offset for rasterizing Nanite meshes. Together, these variables control the LOD scaling for Nanite meshes in the viewport.

Developers should be aware that this variable affects the visual quality and performance of Nanite meshes. A higher offset value will result in lower detail meshes being used, potentially improving performance at the cost of visual quality.

Best practices when using this variable include:

  1. Adjust it carefully in conjunction with other Nanite and TSR settings for optimal balance between performance and visual quality.
  2. Test thoroughly across different hardware configurations to ensure consistent results.
  3. Consider exposing this setting to end-users for performance tuning, if appropriate for your project.

Regarding the associated variable CVarNaniteViewMeshLODBiasOffset:

The purpose of CVarNaniteViewMeshLODBiasOffset is to provide a programmatic interface to the r.Nanite.ViewMeshLODBias.Offset setting. It’s used internally by the engine to access and modify the LOD bias offset value.

This variable is part of the rendering system, specifically the Nanite subsystem within the Renderer module.

The value of CVarNaniteViewMeshLODBiasOffset is set when the engine initializes the console variables, and it can be modified at runtime through console commands or engine API calls.

CVarNaniteViewMeshLODBiasOffset interacts directly with the LOD scaling calculations in the RenderNanite function of the FDeferredShadingSceneRenderer class.

Developers should be aware that changes to this variable will immediately affect the Nanite mesh LOD calculations in the render thread.

Best practices for using CVarNaniteViewMeshLODBiasOffset include:

  1. Access its value using GetValueOnRenderThread() when in render thread context.
  2. Consider caching the value if used frequently to avoid repeated console variable lookups.
  3. Be cautious when modifying this value during runtime, as it can have immediate visual impacts.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DeferredShadingRenderer.cpp:242

Scope: file

Source code excerpt:


static TAutoConsoleVariable<float> CVarNaniteViewMeshLODBiasOffset(
	TEXT("r.Nanite.ViewMeshLODBias.Offset"), 0.0f,
	TEXT("LOD offset to apply for rasterized Nanite meshes for the main viewport when using TSR (Default = 0)."),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<float> CVarNaniteViewMeshLODBiasMin(
	TEXT("r.Nanite.ViewMeshLODBias.Min"), -2.0f,
	TEXT("Minimum LOD offset for rasterizing Nanite meshes for the main viewport (Default = -2)."),

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DeferredShadingRenderer.cpp:241

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<float> CVarNaniteViewMeshLODBiasOffset(
	TEXT("r.Nanite.ViewMeshLODBias.Offset"), 0.0f,
	TEXT("LOD offset to apply for rasterized Nanite meshes for the main viewport when using TSR (Default = 0)."),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<float> CVarNaniteViewMeshLODBiasMin(
	TEXT("r.Nanite.ViewMeshLODBias.Min"), -2.0f,

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DeferredShadingRenderer.cpp:1372

Scope (from outer to inner):

file
function     void FDeferredShadingSceneRenderer::RenderNanite

Source code excerpt:

				float TemporalUpscaleFactor = float(View.GetSecondaryViewRectSize().X) / float(ViewRect.Width());

				LODScaleFactor = TemporalUpscaleFactor * FMath::Exp2(-CVarNaniteViewMeshLODBiasOffset.GetValueOnRenderThread());
				LODScaleFactor = FMath::Min(LODScaleFactor, FMath::Exp2(-CVarNaniteViewMeshLODBiasMin.GetValueOnRenderThread()));
			}

			float MaxPixelsPerEdgeMultipler = 1.0f / LODScaleFactor;
			if (GDynamicNaniteScalingPrimary.GetSettings().IsEnabled())
			{