r.Shadow.FarShadowStaticMeshLODBias

r.Shadow.FarShadowStaticMeshLODBias

#Overview

name: r.Shadow.FarShadowStaticMeshLODBias

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.FarShadowStaticMeshLODBias is to control the Level of Detail (LOD) bias for static meshes and landscapes in far shadow calculations within Unreal Engine’s rendering system.

This setting variable is primarily used by the rendering system, specifically in the shadow rendering subsystem. It affects how detailed static meshes and landscapes are rendered in far shadow cascades.

The value of this variable is set through the console variable system, as indicated by the FAutoConsoleVariableRef declaration. It can be modified at runtime using console commands or through configuration files.

The associated variable GFarShadowStaticMeshLODBias interacts directly with r.Shadow.FarShadowStaticMeshLODBias. They share the same value, with GFarShadowStaticMeshLODBias being the actual int32 variable used in the engine code.

Developers must be aware that:

  1. This setting only affects selected geometry types (static meshes and landscapes).
  2. It’s marked as scalability and render thread safe, meaning it can be adjusted for performance reasons and is safe to modify from the render thread.
  3. The bias is applied specifically to far shadow cascades, not all shadow calculations.

Best practices when using this variable include:

  1. Use it to balance between shadow quality and performance, especially for distant objects.
  2. Be cautious when adjusting it, as it can affect the visual quality of shadows for static meshes and landscapes.
  3. Consider the impact on different hardware configurations, as higher LOD bias values may affect performance on lower-end systems.

Regarding the associated variable GFarShadowStaticMeshLODBias:

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/DirectionalLightComponent.cpp:67

Scope: file

Source code excerpt:

ENGINE_API int32 GFarShadowStaticMeshLODBias = 0;
FAutoConsoleVariableRef CVarFarShadowStaticMeshLODBias(
	TEXT("r.Shadow.FarShadowStaticMeshLODBias"),
	GFarShadowStaticMeshLODBias,
	TEXT("Notice: only selected geometry types (static meshes and landscapes) respect this value."),
	ECVF_Scalability | ECVF_RenderThreadSafe
);

static TAutoConsoleVariable<float> CVarFarShadowDistanceOverride(

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/DirectionalLightComponent.cpp:65

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe | ECVF_Scalability );

ENGINE_API int32 GFarShadowStaticMeshLODBias = 0;
FAutoConsoleVariableRef CVarFarShadowStaticMeshLODBias(
	TEXT("r.Shadow.FarShadowStaticMeshLODBias"),
	GFarShadowStaticMeshLODBias,
	TEXT("Notice: only selected geometry types (static meshes and landscapes) respect this value."),
	ECVF_Scalability | ECVF_RenderThreadSafe
);

static TAutoConsoleVariable<float> CVarFarShadowDistanceOverride(
	TEXT("r.Shadow.FarShadowDistanceOverride"),

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:1940

Scope (from outer to inner):

file
function     void FViewInfo::SetupUniformBufferParameters

Source code excerpt:

	if (DrawDynamicFlags & EDrawDynamicFlags::FarShadowCascade)
	{
		extern ENGINE_API int32 GFarShadowStaticMeshLODBias;
		ViewUniformShaderParameters.FarShadowStaticMeshLODBias = GFarShadowStaticMeshLODBias;
	}
	else
	{
		ViewUniformShaderParameters.FarShadowStaticMeshLODBias = 0;
	}

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowSetup.cpp:1729

Scope (from outer to inner):

file
function     FLODMask FProjectedShadowInfo::CalcAndUpdateLODToRender

Source code excerpt:

		if (!ShadowLODToRender.IsLODRange()) // todo: GPU LOD doesn't support this bias.
		{
			extern ENGINE_API int32 GFarShadowStaticMeshLODBias;
			int8 LODToRenderScan = ShadowLODToRender.LODIndex0 + GFarShadowStaticMeshLODBias;

			for (int32 Index = PrimitiveSceneInfo->StaticMeshRelevances.Num() - 1; Index >= 0; Index--)
			{
				if (LODToRenderScan == PrimitiveSceneInfo->StaticMeshRelevances[Index].GetLODIndex())
				{
					ShadowLODToRender.SetLOD(LODToRenderScan);