r.Mobile.EnableNoPrecomputedLightingCSMShader

r.Mobile.EnableNoPrecomputedLightingCSMShader

#Overview

name: r.Mobile.EnableNoPrecomputedLightingCSMShader

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.Mobile.EnableNoPrecomputedLightingCSMShader is to control the generation of Cascaded Shadow Map (CSM) shaders for mobile platforms in scenes without precomputed lighting.

This setting variable is primarily used in the rendering system of Unreal Engine 5, specifically for mobile platforms. It affects the shader compilation and rendering of directional light shadows in mobile games.

The Unreal Engine subsystems that rely on this variable are the mobile rendering module and the shader compilation system. It’s particularly relevant for the LightMapRendering module, as seen in the FMobileDirectionalLightAndCSMPolicy class.

The value of this variable is set through the console variable system. It’s defined as a TAutoConsoleVariable with a default value of 0, meaning CSM shaders for scenes without precomputed lighting are not generated by default unless r.AllowStaticLighting is 0.

This variable interacts with the r.AllowStaticLighting variable. When r.Mobile.EnableNoPrecomputedLightingCSMShader is set to 1, it overrides the behavior controlled by r.AllowStaticLighting for mobile CSM shader generation.

Developers should be aware that enabling this variable (setting it to 1) will always generate CSM shaders for scenes without precomputed lighting on mobile platforms. This can increase shader compilation time and potentially impact performance, but it allows for dynamic shadows in scenes without static lighting.

Best practices when using this variable include:

  1. Keep it disabled (0) by default to optimize performance and compilation time.
  2. Enable it (1) only when you need dynamic directional shadows in mobile scenes without precomputed lighting.
  3. Consider the performance implications, especially on lower-end mobile devices.

The associated variable CVarMobileEnableNoPrecomputedLightingCSMShader is the internal representation of the console variable. It’s used in the engine’s code to access the current value of the setting. This variable is typically used in conditional statements to determine whether to compile certain shader permutations or enable specific rendering features.

When working with CVarMobileEnableNoPrecomputedLightingCSMShader, developers should:

  1. Use it to check the current state of the setting in C++ code.
  2. Be aware that it’s marked as read-only and render thread safe, meaning it shouldn’t be modified during runtime.
  3. Consider caching its value for performance-critical sections of code, as seen in the FReadOnlyCVARCache class.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Core/Private/HAL/ConsoleManager.cpp:3501

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarMobileEnableNoPrecomputedLightingCSMShader(
	TEXT("r.Mobile.EnableNoPrecomputedLightingCSMShader"),
	0,
	TEXT("0: CSM shaders for scenes without any precomputed lighting are not generated unless r.AllowStaticLighting is 0. (default)\n")
	TEXT("1: CSM shaders for scenes without any precomputed lighting are always generated."),
	ECVF_RenderThreadSafe | ECVF_ReadOnly);

static TAutoConsoleVariable<int32> CVarMobileUseCSMShaderBranch(

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/ReadOnlyCVARCache.cpp:76

Scope (from outer to inner):

file
function     void FReadOnlyCVARCache::Initialize

Source code excerpt:

	const auto CVarMobileAllowDistanceFieldShadows = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.AllowDistanceFieldShadows"));
	const auto CVarMobileSkyLightPermutation = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.SkyLightPermutation"));
	const auto CVarMobileEnableNoPrecomputedLightingCSMShader = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.EnableNoPrecomputedLightingCSMShader"));
	const auto CVarMobileSupportGPUScene = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.SupportGPUScene"));
	
	const bool bForceAllPermutations = CVarSupportAllShaderPermutations && CVarSupportAllShaderPermutations->GetValueOnAnyThread() != 0;

	bEnableStationarySkylight = !CVarSupportStationarySkylight || CVarSupportStationarySkylight->GetValueOnAnyThread() != 0 || bForceAllPermutations;
	bEnablePointLightShadows = !CVarSupportPointLightWholeSceneShadows || CVarSupportPointLightWholeSceneShadows->GetValueOnAnyThread() != 0 || bForceAllPermutations;

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/LightMapRendering.cpp:165

Scope (from outer to inner):

file
function     bool FMobileDirectionalLightAndCSMPolicy::ShouldCompilePermutation

Source code excerpt:

	}

	static auto* CVarEnableNoPrecomputedLightingCSMShader = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.EnableNoPrecomputedLightingCSMShader"));
	const bool bEnableNoPrecomputedLightingCSMShader = CVarEnableNoPrecomputedLightingCSMShader && CVarEnableNoPrecomputedLightingCSMShader->GetValueOnAnyThread() != 0;

	return (!IsStaticLightingAllowed() || bEnableNoPrecomputedLightingCSMShader) &&
		Parameters.MaterialParameters.ShadingModels.IsLit() &&
		!IsTranslucentBlendMode(Parameters.MaterialParameters);
}

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Core/Private/HAL/ConsoleManager.cpp:3500

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe | ECVF_ReadOnly);

static TAutoConsoleVariable<int32> CVarMobileEnableNoPrecomputedLightingCSMShader(
	TEXT("r.Mobile.EnableNoPrecomputedLightingCSMShader"),
	0,
	TEXT("0: CSM shaders for scenes without any precomputed lighting are not generated unless r.AllowStaticLighting is 0. (default)\n")
	TEXT("1: CSM shaders for scenes without any precomputed lighting are always generated."),
	ECVF_RenderThreadSafe | ECVF_ReadOnly);

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/ReadOnlyCVARCache.cpp:76

Scope (from outer to inner):

file
function     void FReadOnlyCVARCache::Initialize

Source code excerpt:

	const auto CVarMobileAllowDistanceFieldShadows = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.AllowDistanceFieldShadows"));
	const auto CVarMobileSkyLightPermutation = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.SkyLightPermutation"));
	const auto CVarMobileEnableNoPrecomputedLightingCSMShader = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.EnableNoPrecomputedLightingCSMShader"));
	const auto CVarMobileSupportGPUScene = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.SupportGPUScene"));
	
	const bool bForceAllPermutations = CVarSupportAllShaderPermutations && CVarSupportAllShaderPermutations->GetValueOnAnyThread() != 0;

	bEnableStationarySkylight = !CVarSupportStationarySkylight || CVarSupportStationarySkylight->GetValueOnAnyThread() != 0 || bForceAllPermutations;
	bEnablePointLightShadows = !CVarSupportPointLightWholeSceneShadows || CVarSupportPointLightWholeSceneShadows->GetValueOnAnyThread() != 0 || bForceAllPermutations;

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/ReadOnlyCVARCache.cpp:94

Scope (from outer to inner):

file
function     void FReadOnlyCVARCache::Initialize

Source code excerpt:

	bMobileEnableMovableLightCSMShaderCulling = CVarMobileEnableMovableLightCSMShaderCulling->GetValueOnAnyThread() != 0;
	MobileSkyLightPermutationValue = CVarMobileSkyLightPermutation->GetValueOnAnyThread();
	bMobileEnableNoPrecomputedLightingCSMShader = CVarMobileEnableNoPrecomputedLightingCSMShader->GetValueOnAnyThread() != 0;
	MobileEarlyZPassValue = MobileEarlyZPassIniValue(GMaxRHIShaderPlatform);
	MobileForwardLocalLightsValue = MobileForwardLocalLightsIniValue(GMaxRHIShaderPlatform);
	bMobileDeferredShadingValue = MobileDeferredShadingIniValue(GMaxRHIShaderPlatform);
	bMobileEnableMovableSpotlightsShadowValue = MobileEnableMovableSpotlightsShadowIniValue(GMaxRHIShaderPlatform);
	bMobileSupportsGPUScene = CVarMobileSupportGPUScene->GetValueOnAnyThread() != 0;