r.Shadow.Nanite

r.Shadow.Nanite

#Overview

name: r.Shadow.Nanite

This variable is created as a Console Variable (cvar).

It is referenced in 6 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.Shadow.Nanite is to enable or disable shadows from Nanite meshes in Unreal Engine 5. This setting variable is primarily used in the rendering system, specifically for shadow rendering.

The Unreal Engine subsystem that relies on this setting variable is the Renderer module, particularly the shadow depth rendering components. This can be seen from the file locations where the variable is referenced, such as ShadowDepthRendering.cpp and Nanite.cpp.

The value of this variable is set as a console variable with a default value of 1 (enabled). It can be changed at runtime through the console or programmatically.

This variable interacts with other variables and systems:

  1. It’s associated with CVarNaniteShadows, which shares the same value.
  2. It’s used in conjunction with CVarNaniteShadowsUseHZB, which determines whether to use Hierarchical Z-Buffer (HZB) for Nanite shadows.
  3. It’s checked alongside other conditions like UseNanite(ShaderPlatform) and ViewFamily.EngineShowFlags.NaniteMeshes.

Developers must be aware that:

  1. This variable affects performance, as enabling Nanite shadows may have a performance impact.
  2. It’s render thread safe, meaning it can be safely accessed from the render thread.
  3. It’s used in conjunction with other Nanite and shadow-related settings.

Best practices when using this variable include:

  1. Consider performance implications when enabling Nanite shadows, especially on lower-end hardware.
  2. Test thoroughly with both enabled and disabled states to ensure your game performs well in both scenarios.
  3. Use in combination with other Nanite and shadow settings for optimal results.

Regarding the associated variable CVarNaniteShadows:

The purpose of CVarNaniteShadows is the same as r.Shadow.Nanite - to enable or disable shadows from Nanite meshes. It’s an internal representation of the console variable.

This variable is used in the Renderer module, specifically in the Nanite system and shadow depth rendering.

The value is set through the console variable r.Shadow.Nanite and can be accessed using GetValueOnRenderThread().

It interacts with other systems in the same way as r.Shadow.Nanite, being used in shadow rendering decisions and Nanite-related functions.

Developers should be aware that this is the internal variable used in the C++ code, while r.Shadow.Nanite is the console-accessible name.

Best practices include using this variable for render-thread safe checks on whether Nanite shadows are enabled, and ensuring it’s only accessed from appropriate threads (typically 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/ShadowDepthRendering.cpp:121

Scope: file

Source code excerpt:


TAutoConsoleVariable<int32> CVarNaniteShadows(
	TEXT("r.Shadow.Nanite"),
	1,
	TEXT("Enables shadows from Nanite meshes."),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarNaniteShadowsUseHZB(
	TEXT("r.Shadow.NaniteUseHZB"),

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Nanite/Nanite.cpp:29

Scope: file

Source code excerpt:

);

extern TAutoConsoleVariable<int32> CVarNaniteShadows;

bool bNaniteListStatFilters = false;

void NaniteStatsFilterExec(const TCHAR* Cmd, FOutputDevice& Ar)
{
	check(IsInGameThread());

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Nanite/Nanite.cpp:314

Scope (from outer to inner):

file
namespace    Nanite
function     void ListStatFilters

Source code excerpt:

		UE_LOG(LogNanite, Warning, TEXT("Primary"));

		const bool bListShadows = CVarNaniteShadows.GetValueOnRenderThread() != 0;

		// Virtual shadow maps
		if (bListShadows)
		{
			const auto& VirtualShadowMaps = SceneRenderer->SortedShadowsForShadowDepthPass.VirtualShadowMapShadows;
			const auto& VirtualShadowClipmaps = SceneRenderer->SortedShadowsForShadowDepthPass.VirtualShadowMapClipmaps;

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowDepthRendering.cpp:120

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe);

TAutoConsoleVariable<int32> CVarNaniteShadows(
	TEXT("r.Shadow.Nanite"),
	1,
	TEXT("Enables shadows from Nanite meshes."),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarNaniteShadowsUseHZB(

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowDepthRendering.cpp:1582

Scope (from outer to inner):

file
function     void FSceneRenderer::RenderShadowDepthMapAtlases

Source code excerpt:

		UseNanite(ShaderPlatform) &&
		ViewFamily.EngineShowFlags.NaniteMeshes &&
		CVarNaniteShadows.GetValueOnRenderThread() != 0 &&
		Nanite::GStreamingManager.HasResourceEntries();

	Scene->PrevAtlasHZBs.SetNum(SortedShadowsForShadowDepthPass.ShadowMapAtlases.Num());

	FRDGExternalAccessQueue ExternalAccessQueue;

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowDepthRendering.cpp:1768

Scope (from outer to inner):

file
function     void FSceneRenderer::RenderShadowDepthMaps

Source code excerpt:

		}

		if (bNaniteEnabled && CVarNaniteShadows.GetValueOnRenderThread())
		{
			const bool bUseHZB = (CVarNaniteShadowsUseHZB.GetValueOnRenderThread() != 0);

			FString LightName;
			GetLightNameForDrawEvent(ProjectedShadowInfo->GetLightSceneInfo().Proxy, LightName);