r.Shadow.Virtual.Clipmap.LastLevel

r.Shadow.Virtual.Clipmap.LastLevel

#Overview

name: r.Shadow.Virtual.Clipmap.LastLevel

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

It is referenced in 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.Shadow.Virtual.Clipmap.LastLevel is to control the maximum level of the virtual shadow map clipmap system in Unreal Engine’s rendering pipeline. This setting is crucial for managing the trade-off between shadow quality, performance, and memory usage in the virtual shadow mapping system.

This setting variable is primarily used in the Renderer module of Unreal Engine, specifically within the Virtual Shadow Maps subsystem. It’s referenced in the VirtualShadowMapClipmap.cpp file, which handles the implementation of virtual shadow map clipmaps.

The value of this variable is set through a console variable (CVarVirtualShadowMapClipmapLastLevel) with a default value of 22. It can be adjusted at runtime or through configuration files.

This variable interacts closely with other shadow mapping related variables, particularly CVarVirtualShadowMapClipmapFirstCoarseLevel and CVarVirtualShadowMapClipmapLastCoarseLevel. These variables together determine the range and detail of the virtual shadow map clipmap.

Developers must be aware that increasing this value will extend the maximum range that the clipmap can cover, but it may also increase the page count, potentially impacting performance and memory usage. Each additional level doubles the maximum range of the clipmap.

Best practices when using this variable include:

  1. Balancing it with the first level of the clipmap to achieve desired shadow quality and performance.
  2. Considering the target hardware capabilities when setting this value.
  3. Testing thoroughly to ensure that increasing this value provides noticeable quality improvements without unacceptable performance costs.

Regarding the associated variable CVarVirtualShadowMapClipmapLastLevel:

This is the actual console variable that controls the r.Shadow.Virtual.Clipmap.LastLevel setting. It’s defined as a TAutoConsoleVariable, which means it’s an integer value that can be changed at runtime through the console or configuration files.

The purpose of this variable is the same as r.Shadow.Virtual.Clipmap.LastLevel - to control the last level of the virtual shadow map clipmap.

It’s used in the Renderer module, specifically in the Virtual Shadow Maps system. The value of this variable is accessed in multiple places within the VirtualShadowMapClipmap.cpp file to determine the extent of the clipmap and to calculate various shadow mapping parameters.

This variable is set with a default value of 22, but can be changed at runtime or through configuration files.

It interacts with other shadow mapping variables, particularly those controlling the first level and coarse levels of the clipmap.

Developers should be aware that changes to this variable will directly affect the shadow mapping system’s behavior and performance. It should be adjusted carefully, with consideration for the target hardware and desired shadow quality.

Best practices include using this variable in conjunction with other shadow mapping settings to achieve the optimal balance between shadow quality and performance for your specific use case.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VirtualShadowMaps/VirtualShadowMapClipmap.cpp:43

Scope: file

Source code excerpt:

);
static TAutoConsoleVariable<int32> CVarVirtualShadowMapClipmapLastLevel(
	TEXT( "r.Shadow.Virtual.Clipmap.LastLevel" ),
	22,
	TEXT( "Last level of the virtual clipmap. Indirectly determines radius the clipmap can cover. Each extra level doubles the maximum range, but may increase page count." ),
	ECVF_Scalability | ECVF_RenderThreadSafe
);

TAutoConsoleVariable<int32> CVarVirtualShadowMapClipmapFirstCoarseLevel(

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VirtualShadowMaps/VirtualShadowMapClipmap.cpp:42

Scope: file

Source code excerpt:

	ECVF_Scalability | ECVF_RenderThreadSafe
);
static TAutoConsoleVariable<int32> CVarVirtualShadowMapClipmapLastLevel(
	TEXT( "r.Shadow.Virtual.Clipmap.LastLevel" ),
	22,
	TEXT( "Last level of the virtual clipmap. Indirectly determines radius the clipmap can cover. Each extra level doubles the maximum range, but may increase page count." ),
	ECVF_Scalability | ECVF_RenderThreadSafe
);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VirtualShadowMaps/VirtualShadowMapClipmap.cpp:222

Scope (from outer to inner):

file
function     FVirtualShadowMapClipmap::FVirtualShadowMapClipmap

Source code excerpt:


	FirstLevel = GetFirstLevel();
	int32 LastLevel = CVarVirtualShadowMapClipmapLastLevel.GetValueOnRenderThread();	
	if (bIsOrthographicCamera && CVarOrthoVSMEstimateClipmapLevels.GetValueOnRenderThread())
	{
		/**
		* For Ortho projections, this branch bases the first level VSM on the set OrthoWidth. This reduces the number of clipmaps generated
		* and also scales the precision of the clipmaps depending on the scene.
		* 

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VirtualShadowMaps/VirtualShadowMapClipmap.cpp:461

Scope (from outer to inner):

file
function     uint32 FVirtualShadowMapClipmap::GetCoarsePageClipmapIndexMask

Source code excerpt:


	const int FirstLevel = GetFirstLevel();
	const int LastLevel  = FMath::Max(FirstLevel, CVarVirtualShadowMapClipmapLastLevel.GetValueOnRenderThread());	
	int FirstCoarseIndex = CVarVirtualShadowMapClipmapFirstCoarseLevel.GetValueOnRenderThread() - FirstLevel;
	int LastCoarseIndex  = CVarVirtualShadowMapClipmapLastCoarseLevel.GetValueOnRenderThread() - FirstLevel;	

	ensureMsgf((LastLevel - FirstLevel) < 32, TEXT("Too many clipmap levels for coarse page bitmask."));

	FirstCoarseIndex = FMath::Max(0, FirstCoarseIndex);