r.Shadow.NaniteLODBias

r.Shadow.NaniteLODBias

#Overview

name: r.Shadow.NaniteLODBias

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.Shadow.NaniteLODBias is to control the Level of Detail (LOD) bias for Nanite geometry when rendering shadows. This setting variable is part of Unreal Engine 5’s rendering system, specifically targeting the shadow rendering pipeline for Nanite-based geometry.

This setting variable is primarily used in the Renderer module of Unreal Engine, as evidenced by its location in the ShadowSceneRenderer.cpp file. It’s specifically related to the shadow rendering subsystem and how it handles Nanite geometry.

The value of this variable is set as a console variable with a default value of 1.0f. It can be modified at runtime through the console or through project settings.

The variable interacts directly with its associated variable CVarNaniteShadowsLODBias, which is defined in the same file. This associated variable is used to actually store and access the value set by r.Shadow.NaniteLODBias.

Developers must be aware that this variable affects the detail level of Nanite geometry in shadows. A value of 0 means full detail, while values greater than 0 result in reduced detail. This can have implications for both visual quality and performance.

Best practices when using this variable include:

  1. Adjusting it to find the right balance between shadow detail and performance for your specific project.
  2. Testing different values in various scenarios to ensure consistent visual quality across different types of scenes.
  3. Considering its impact on different hardware configurations, as higher detail settings may affect performance on less powerful systems.

Regarding the associated variable CVarNaniteShadowsLODBias:

The purpose of CVarNaniteShadowsLODBias is to provide a programmatic way to access and modify the r.Shadow.NaniteLODBias setting within the engine’s C++ code.

This variable is used directly in the Renderer module, specifically in the FShadowSceneRenderer::ComputeNaniteShadowsLODScaleFactor() function. This function appears to calculate a scale factor for Nanite shadows based on the LOD bias.

The value of this variable is set when r.Shadow.NaniteLODBias is modified, as they share the same value.

CVarNaniteShadowsLODBias interacts with the rendering code that determines the LOD for Nanite geometry in shadows. It’s used to compute a scale factor that likely influences how detailed the Nanite geometry is rendered in shadows.

Developers should be aware that modifying this variable directly in code will have the same effect as changing r.Shadow.NaniteLODBias through the console or settings.

Best practices for using CVarNaniteShadowsLODBias include:

  1. Using GetValueOnRenderThread() when accessing its value, as demonstrated in the ComputeNaniteShadowsLODScaleFactor() function, to ensure thread-safe access.
  2. Consider caching the computed scale factor if it’s used frequently, rather than recomputing it every frame, to optimize performance.
  3. Be cautious when modifying this variable directly in code, as it could override user or project settings.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Shadows/ShadowSceneRenderer.cpp:50

Scope: file

Source code excerpt:


static TAutoConsoleVariable<float> CVarNaniteShadowsLODBias(
	TEXT("r.Shadow.NaniteLODBias"),
	1.0f,
	TEXT("LOD bias for nanite geometry in shadows. 0 = full detail. >0 = reduced detail."),
	ECVF_RenderThreadSafe);

TAutoConsoleVariable<int32> CVarVirtualShadowOnePassProjection(
	TEXT("r.Shadow.Virtual.OnePassProjection"),

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Shadows/ShadowSceneRenderer.cpp:49

Scope: file

Source code excerpt:

);

static TAutoConsoleVariable<float> CVarNaniteShadowsLODBias(
	TEXT("r.Shadow.NaniteLODBias"),
	1.0f,
	TEXT("LOD bias for nanite geometry in shadows. 0 = full detail. >0 = reduced detail."),
	ECVF_RenderThreadSafe);

TAutoConsoleVariable<int32> CVarVirtualShadowOnePassProjection(

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Shadows/ShadowSceneRenderer.cpp:103

Scope (from outer to inner):

file
function     float FShadowSceneRenderer::ComputeNaniteShadowsLODScaleFactor

Source code excerpt:

float FShadowSceneRenderer::ComputeNaniteShadowsLODScaleFactor()
{
	return FMath::Pow(2.0f, -CVarNaniteShadowsLODBias.GetValueOnRenderThread());
}

namespace
{

struct FHeapPair