r.Shadow.DetectVertexShaderLayerAtRuntime

r.Shadow.DetectVertexShaderLayerAtRuntime

#Overview

name: r.Shadow.DetectVertexShaderLayerAtRuntime

The value of this variable can be defined or overridden in .ini config files. 2 .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.DetectVertexShaderLayerAtRuntime is to control the compilation and use of vertex shader layer functionality for shadow rendering, particularly for one-pass point light shadows.

This setting variable is primarily used by the Renderer module in Unreal Engine 5, specifically within the shadow depth rendering system. It interacts with the RenderCore module as well.

The value of this variable is set through a console variable (CVar) declaration in ShadowDepthRendering.cpp. It’s initialized with a default value of 0 but can be changed at runtime through console commands or configuration files.

This variable interacts with other systems and variables, notably:

  1. RHISupportsVertexShaderLayer
  2. GRHISupportsArrayIndexFromAnyShader

Developers should be aware of the following when using this variable:

  1. It forces the compilation of the vertex shader layer permutation even if the platform (RHI) doesn’t declare compile-time support through RHISupportsVertexShaderLayer.
  2. It’s enabled by default for Windows/SM5 as DirectX 11 almost universally supports this at runtime.
  3. It affects the compilation of shadow depth shaders, particularly for one-pass point light shadows.

Best practices when using this variable include:

  1. Consider platform-specific requirements and capabilities when adjusting this setting.
  2. Be aware that enabling this on platforms without runtime support for vertex shader layers may lead to performance issues or rendering errors.
  3. Use in conjunction with other shadow-related settings for optimal shadow rendering performance and quality.
  4. Test thoroughly on target platforms when modifying this setting to ensure compatibility and desired rendering results.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/Linux/LinuxEngine.ini:12, section: [SystemSettings]

Location: <Workspace>/Engine/Config/Windows/WindowsEngine.ini:22, section: [SystemSettings]

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowDepthRendering.cpp:296

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarDetectVertexShaderLayerAtRuntime(
	TEXT("r.Shadow.DetectVertexShaderLayerAtRuntime"),
	0,
	TEXT("Forces the compilation of the vslayer shader permutation even if the platform (RHI) does not declare compile-time support through RHISupportsVertexShaderLayer.")
	TEXT("Enabled by default for windows/SM5 as DX11 almost universally supports this at runtime."),
	ECVF_ReadOnly | ECVF_RenderThreadSafe);

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/RenderUtils.cpp:1451

Scope (from outer to inner):

file
function     bool DoesRuntimeSupportOnePassPointLightShadows

Source code excerpt:

RENDERCORE_API bool DoesRuntimeSupportOnePassPointLightShadows(EShaderPlatform Platform)
{
	static const auto CVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Shadow.DetectVertexShaderLayerAtRuntime"));

	return RHISupportsVertexShaderLayer(Platform)
		|| (CVar->GetValueOnAnyThread() != 0 && GRHISupportsArrayIndexFromAnyShader != 0);
}

bool IsForwardShadingEnabled(const FStaticShaderPlatform Platform)

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowDepthRendering.cpp:329

Scope (from outer to inner):

file
class        class TShadowDepthVS : public FShadowDepthVS
function     static bool ShouldCompilePermutation

Source code excerpt:


		// Compile VS layer permutation if RHI supports it unconditionally OR we have forced it on (default for DX11&12 at SM5)
		static FShaderPlatformCachedIniValue<bool> DetectVertexShaderLayerRuntimeIniValue(TEXT("r.Shadow.DetectVertexShaderLayerAtRuntime"));
		const bool bShouldCompileVSLayer = RHISupportsVertexShaderLayer(Platform) || DetectVertexShaderLayerRuntimeIniValue.Get(Platform) != 0;
		if (ShaderMode == VertexShadowDepth_OnePassPointLight && !bShouldCompileVSLayer)
		{
			return false;
		}