r.Shadow.Virtual.ResolutionLodBiasDirectionalMoving

r.Shadow.Virtual.ResolutionLodBiasDirectionalMoving

#Overview

name: r.Shadow.Virtual.ResolutionLodBiasDirectionalMoving

The value of this variable can be defined or overridden in .ini config files. 5 .ini config files referencing this setting variable.

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.ResolutionLodBiasDirectionalMoving is to apply a bias to LOD calculations for directional lights that are moving in Unreal Engine 5’s virtual shadow map system. This setting is part of the rendering system, specifically the shadow rendering subsystem.

This setting variable is primarily used by the Renderer module, particularly in the virtual shadow map implementation. It’s referenced in the VirtualShadowMapClipmap.cpp file, which is part of the virtual shadow map system.

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

This variable interacts with CVarVirtualShadowMapResolutionLodBiasDirectional. The bias transitions smoothly between these two values as the light transitions between moving and non-moving states. The transition is controlled by the ‘r.Shadow.Scene.LightActiveFrameCount’ setting.

Developers should be aware that:

  1. A negative value increases resolution (e.g., -1.0 doubles it), while a positive value decreases resolution (e.g., 1.0 halves it).
  2. This setting affects performance and visual quality, so it should be adjusted carefully.
  3. The effect is specific to moving directional lights, not static ones.

Best practices when using this variable include:

  1. Fine-tuning the value based on the specific needs of your game, balancing between performance and visual quality.
  2. Testing the setting with various light movement scenarios to ensure optimal results.
  3. Considering the interaction with other shadow-related settings, especially ‘r.Shadow.Virtual.ResolutionLodBiasDirectional’ and ‘r.Shadow.Scene.LightActiveFrameCount’.

Regarding the associated variable CVarVirtualShadowMapResolutionLodBiasDirectionalMoving:

This is the actual console variable that stores the value of r.Shadow.Virtual.ResolutionLodBiasDirectionalMoving. It’s defined using TAutoConsoleVariable, which allows it to be easily accessed and modified through the console or code.

The variable is used in the FVirtualShadowMapClipmap constructor to calculate the ResolutionLodBias. It’s interpolated with CVarVirtualShadowMapResolutionLodBiasDirectional based on the light’s mobility factor.

Developers should note that this variable is marked with ECVF_Scalability and ECVF_RenderThreadSafe flags, indicating that it affects scalability and is safe to modify on the render thread. When adjusting this value, consider its impact on performance across different hardware configurations.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/BaseScalability.ini:143, section: [ShadowQuality@0]

Location: <Workspace>/Engine/Config/BaseScalability.ini:167, section: [ShadowQuality@1]

Location: <Workspace>/Engine/Config/BaseScalability.ini:194, section: [ShadowQuality@2]

Location: <Workspace>/Engine/Config/BaseScalability.ini:221, section: [ShadowQuality@3]

Location: <Workspace>/Engine/Config/BaseScalability.ini:248, section: [ShadowQuality@Cine]

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

Scope: file

Source code excerpt:


static TAutoConsoleVariable<float> CVarVirtualShadowMapResolutionLodBiasDirectionalMoving(
	TEXT( "r.Shadow.Virtual.ResolutionLodBiasDirectionalMoving" ),
	0.5f,
	TEXT( "Bias applied to LOD calculations for directional lights that are moving. -1.0 doubles resolution, 1.0 halves it and so on.\n" )
	TEXT( "The bias transitions smoothly back to ResolutionLodBiasDirectional as the light transitions to non-moving, see 'r.Shadow.Scene.LightActiveFrameCount'." ),
	ECVF_Scalability | ECVF_RenderThreadSafe
);

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

);

static TAutoConsoleVariable<float> CVarVirtualShadowMapResolutionLodBiasDirectionalMoving(
	TEXT( "r.Shadow.Virtual.ResolutionLodBiasDirectionalMoving" ),
	0.5f,
	TEXT( "Bias applied to LOD calculations for directional lights that are moving. -1.0 doubles resolution, 1.0 halves it and so on.\n" )
	TEXT( "The bias transitions smoothly back to ResolutionLodBiasDirectional as the light transitions to non-moving, see 'r.Shadow.Scene.LightActiveFrameCount'." ),
	ECVF_Scalability | ECVF_RenderThreadSafe
);

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

Scope (from outer to inner):

file
function     FVirtualShadowMapClipmap::FVirtualShadowMapClipmap

Source code excerpt:

	// just resizing the virtual shadow maps for each clipmap, but convenient for now. This means we need to additionally bias
	// which levels are present.
	ResolutionLodBias = FVirtualShadowMapArray::InterpolateResolutionBias(CVarVirtualShadowMapResolutionLodBiasDirectional.GetValueOnRenderThread(), CVarVirtualShadowMapResolutionLodBiasDirectionalMoving.GetValueOnRenderThread(), LightMobilityFactor) + FMath::Log2(LodScale);
	ResolutionLodBias += GetLightSceneInfo().Proxy->GetVSMResolutionLodBias();
	// Clamp negative absolute resolution biases as they would exceed the maximum resolution/ranges allocated
	ResolutionLodBias = FMath::Max(0.0f, ResolutionLodBias);

	WorldOrigin = CameraViewMatrices.GetViewOrigin();
	CameraToViewTarget = FVector::ZeroVector;