r.Mobile.SkyLightPermutation

r.Mobile.SkyLightPermutation

#Overview

name: r.Mobile.SkyLightPermutation

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

It is referenced in 8 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.Mobile.SkyLightPermutation is to control the generation of shader permutations for mobile skylight in Unreal Engine 5. It is specifically used for the mobile rendering system to optimize shader compilation and runtime performance.

This setting variable is primarily used by the mobile rendering subsystem in Unreal Engine 5. It affects shader compilation and material rendering on mobile platforms.

The value of this variable is set through a console variable (CVar) system. It can be set programmatically or through configuration files. The default value is 0, which generates both skylight and non-skylight permutations.

The associated variable CVarMobileSkyLightPermutation interacts directly with r.Mobile.SkyLightPermutation, sharing the same value and purpose.

Developers must be aware that this variable has three possible values: 0: Generate both skylight and non-skylight permutations (default) 1: Generate only non-skylight permutations 2: Generate only skylight permutations

When using this variable, developers should consider the following best practices:

  1. Use the default value (0) unless there’s a specific need to optimize for either skylight or non-skylight scenarios.
  2. When targeting mobile platforms with limited resources, consider using value 1 or 2 to reduce shader permutations and save memory.
  3. Be aware that changing this value may require recompiling shaders, which can impact build times.
  4. Test thoroughly after changing this value to ensure desired lighting effects are preserved.

Regarding the associated variable CVarMobileSkyLightPermutation:

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

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarMobileSkyLightPermutation(
	TEXT("r.Mobile.SkyLightPermutation"),
	0,
	TEXT("0: Generate both sky-light and non-skylight permutations. (default)\n"
		 "1: Generate only non-skylight permutations.\n"
		 "2: Generate only skylight permutations"),
	ECVF_RenderThreadSafe | ECVF_ReadOnly);

#Loc: <Workspace>/Engine/Source/Editor/MaterialEditor/Private/MaterialStatsCommon.cpp:398

Scope (from outer to inner):

file
function     void FMaterialStatsUtils::GetRepresentativeShaderTypesAndDescriptions

Source code excerpt:

		else
		{			
			static auto* CVarMobileSkyLightPermutation = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.SkyLightPermutation"));
			const bool bOnlySkyPermutation = CVarMobileSkyLightPermutation->GetValueOnAnyThread() == 2;
						
			if (IsStaticLightingAllowed() && TargetMaterial->IsUsedWithStaticLighting())
			{
				static auto* CVarAllowDistanceFieldShadows = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.AllowDistanceFieldShadows"));
				const bool bAllowDistanceFieldShadows = CVarAllowDistanceFieldShadows->GetValueOnAnyThread() != 0;

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

Scope (from outer to inner):

file
function     void FReadOnlyCVARCache::Initialize

Source code excerpt:

	const auto CVarMobileEnableMovableLightCSMShaderCulling = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.EnableMovableLightCSMShaderCulling"));
	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;

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/MobileBasePassRendering.h:365

Scope (from outer to inner):

file
class        class TMobileBasePassPS : public TMobileBasePassPSBaseType<LightMapPolicyType>
function     static bool ShouldCompilePermutation

Source code excerpt:

	{		
		// We compile the point light shader combinations based on the project settings
		static auto* MobileSkyLightPermutationCVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.SkyLightPermutation"));
		const int32 MobileSkyLightPermutationOptions = MobileSkyLightPermutationCVar->GetValueOnAnyThread();
		const bool bIsLit = Parameters.MaterialParameters.ShadingModels.IsLit();
		// Only compile skylight version for lit materials
		const bool bShouldCacheBySkylight = !bEnableSkyLight || bIsLit;
		// Only compile skylight permutations when they are enabled
		if (bIsLit && !MobileBasePass::UseSkylightPermutation(bEnableSkyLight, MobileSkyLightPermutationOptions))

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Editor/MaterialEditor/Private/MaterialStatsCommon.cpp:398

Scope (from outer to inner):

file
function     void FMaterialStatsUtils::GetRepresentativeShaderTypesAndDescriptions

Source code excerpt:

		else
		{			
			static auto* CVarMobileSkyLightPermutation = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.SkyLightPermutation"));
			const bool bOnlySkyPermutation = CVarMobileSkyLightPermutation->GetValueOnAnyThread() == 2;
						
			if (IsStaticLightingAllowed() && TargetMaterial->IsUsedWithStaticLighting())
			{
				static auto* CVarAllowDistanceFieldShadows = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.AllowDistanceFieldShadows"));
				const bool bAllowDistanceFieldShadows = CVarAllowDistanceFieldShadows->GetValueOnAnyThread() != 0;

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

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe | ECVF_ReadOnly);

static TAutoConsoleVariable<int32> CVarMobileSkyLightPermutation(
	TEXT("r.Mobile.SkyLightPermutation"),
	0,
	TEXT("0: Generate both sky-light and non-skylight permutations. (default)\n"
		 "1: Generate only non-skylight permutations.\n"
		 "2: Generate only skylight permutations"),
	ECVF_RenderThreadSafe | ECVF_ReadOnly);

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

Scope (from outer to inner):

file
function     void FReadOnlyCVARCache::Initialize

Source code excerpt:

	const auto CVarMobileEnableMovableLightCSMShaderCulling = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.EnableMovableLightCSMShaderCulling"));
	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;

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

Scope (from outer to inner):

file
function     void FReadOnlyCVARCache::Initialize

Source code excerpt:

	bMobileEnableStaticAndCSMShadowReceivers = CVarMobileEnableStaticAndCSMShadowReceivers->GetValueOnAnyThread() != 0;
	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;