r.Shadow.Virtual.Clipmap.WPODisableDistance.LodBias

r.Shadow.Virtual.Clipmap.WPODisableDistance.LodBias

#Overview

name: r.Shadow.Virtual.Clipmap.WPODisableDistance.LodBias

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.Virtual.Clipmap.WPODisableDistance.LodBias is to control the number of clipmap levels beyond the distance at which an instance would be animated, allowing for shadow animation in virtual shadow maps. This setting is part of the rendering system, specifically the virtual shadow map subsystem.

This setting variable is used in the Renderer module of Unreal Engine 5, particularly in the VirtualShadowMaps subsystem. It’s defined and used within the VirtualShadowMapClipmap.cpp file, which handles the virtual shadow map clipmap functionality.

The value of this variable is set through a console variable (CVar) system, allowing it to be adjusted at runtime. It’s initialized with a default value of 3, but can be changed through console commands or project settings.

The associated variable CVarClipmapWPODisableDistanceLodBias directly interacts with this setting. They share the same value and are used together to calculate the WPO (World Position Offset) disable distance threshold for shadow animations.

Developers should be aware that this variable affects the trade-off between shadow animation quality and performance. A higher value will allow shadow animations to be visible at greater distances, potentially improving visual quality but at the cost of performance.

Best practices when using this variable include:

  1. Adjusting it based on the specific needs of your scene, particularly for scenes with low light angles and significant WPO movement.
  2. Testing different values (typically in the range of 2-4) to find the best balance between visual quality and performance for your specific use case.
  3. Considering the impact on performance, especially for lower-end hardware.

Regarding the associated variable CVarClipmapWPODisableDistanceLodBias:

The purpose of CVarClipmapWPODisableDistanceLodBias is to provide a programmatic way to access and modify the r.Shadow.Virtual.Clipmap.WPODisableDistance.LodBias setting within the C++ code.

This variable is used in the same Renderer module and VirtualShadowMaps subsystem as the original setting. It’s defined and used in the VirtualShadowMapClipmap.cpp file.

The value of CVarClipmapWPODisableDistanceLodBias is set and retrieved using the Unreal Engine’s console variable system. It’s used in the FVirtualShadowMapClipmap constructor to calculate the WPO distance disable threshold.

Developers should be aware that modifying CVarClipmapWPODisableDistanceLodBias directly in code will have the same effect as changing the r.Shadow.Virtual.Clipmap.WPODisableDistance.LodBias setting.

Best practices for using CVarClipmapWPODisableDistanceLodBias include:

  1. Using GetValueOnRenderThread() to retrieve its value, ensuring thread-safe access.
  2. Considering the performance implications when adjusting this value, especially in performance-critical sections of code.
  3. Documenting any code that modifies this variable, as it can have significant impacts on shadow rendering behavior.

#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:86

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarClipmapWPODisableDistanceLodBias(
	TEXT("r.Shadow.Virtual.Clipmap.WPODisableDistance.LodBias"),
	3,
	TEXT("The number of clipmap levels further than the distance that an instance would be animated to allow shadow animation.\n")
	TEXT("Typically 2-4 works well but may need to be adjusted for very low light angles with significant WPO movement."),
	ECVF_Scalability | ECVF_RenderThreadSafe
);

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

);

static TAutoConsoleVariable<int32> CVarClipmapWPODisableDistanceLodBias(
	TEXT("r.Shadow.Virtual.Clipmap.WPODisableDistance.LodBias"),
	3,
	TEXT("The number of clipmap levels further than the distance that an instance would be animated to allow shadow animation.\n")
	TEXT("Typically 2-4 works well but may need to be adjusted for very low light angles with significant WPO movement."),
	ECVF_Scalability | ECVF_RenderThreadSafe
);

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

Scope (from outer to inner):

file
function     FVirtualShadowMapClipmap::FVirtualShadowMapClipmap

Source code excerpt:

		if (CVarClipmapWPODisableDistance.GetValueOnRenderThread() > 0)
		{
			const int32 WPODisableDistanceLodBias = CVarClipmapWPODisableDistanceLodBias.GetValueOnRenderThread();
			double WPOThresholdCombinedLevel = FMath::CeilToDouble(static_cast<double>(AbsoluteLevel - WPODisableDistanceLodBias) - ResolutionLodBias);
			// NOTE: Squared
			Level.WPODistanceDisableThresholdSquared = FMath::Pow(2.0, 2.0 * WPOThresholdCombinedLevel);
		}
		else
		{