r.Shadow.EnableModulatedSelfShadow
r.Shadow.EnableModulatedSelfShadow
#Overview
name: r.Shadow.EnableModulatedSelfShadow
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Allows modulated shadows to affect the shadow caster. (mobile only)
It is referenced in 4
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.Shadow.EnableModulatedSelfShadow is to control whether modulated shadows can affect the shadow caster in mobile rendering. This setting is specifically designed for the shadow rendering system in Unreal Engine 5.
This setting variable is primarily used by the Renderer module, specifically in the shadow rendering and setup components. It’s referenced in ShadowRendering.cpp and ShadowSetup.cpp, which are core files for shadow implementation in Unreal Engine.
The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 0, meaning that by default, modulated self-shadowing is disabled for mobile platforms.
This variable interacts closely with its associated variable CVarEnableModulatedSelfShadow. They share the same value and are used interchangeably in the code.
Developers must be aware that this setting is specific to mobile rendering. It won’t affect shadow behavior on other platforms. Also, enabling this feature may have performance implications on mobile devices, so it should be used judiciously.
Best practices when using this variable include:
- Only enable it when necessary for visual quality on mobile platforms.
- Test thoroughly on target mobile devices to ensure performance is not significantly impacted.
- Consider providing an in-game option to toggle this feature, allowing users to optimize for their specific device’s capabilities.
Regarding the associated variable CVarEnableModulatedSelfShadow:
The purpose of CVarEnableModulatedSelfShadow is identical to r.Shadow.EnableModulatedSelfShadow. It’s an auto console variable that controls the same functionality.
This variable is used in the Renderer module, specifically in the shadow rendering system. It’s defined and used in ShadowRendering.cpp.
The value is set through the console variable system, with a default value of 0. It can be changed at runtime through console commands.
CVarEnableModulatedSelfShadow directly interacts with r.Shadow.EnableModulatedSelfShadow, as they represent the same setting.
Developers should be aware that this is the actual variable used in the code checks. When the value needs to be retrieved, it’s typically done through CVarEnableModulatedSelfShadow.GetValueOnRenderThread().
Best practices for using this variable are the same as for r.Shadow.EnableModulatedSelfShadow. Additionally, developers should use this variable name when they need to directly access or modify the setting in C++ code.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:152
Scope: file
Source code excerpt:
// General
static TAutoConsoleVariable<int32> CVarEnableModulatedSelfShadow(
TEXT("r.Shadow.EnableModulatedSelfShadow"),
0,
TEXT("Allows modulated shadows to affect the shadow caster. (mobile only)"),
ECVF_RenderThreadSafe);
static int GStencilOptimization = 1;
static FAutoConsoleVariableRef CVarStencilOptimization(
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowSetup.cpp:2534
Scope (from outer to inner):
file
function void FProjectedShadowInfo::SetupMeshDrawCommandsForProjectionStenciling
Source code excerpt:
const EShadingPath ShadingPath = GetFeatureLevelShadingPath(Renderer.FeatureLevel);
static const auto EnableModulatedSelfShadowCVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Shadow.EnableModulatedSelfShadow"));
const bool bMobileModulatedShadowsAllowSelfShadow = !bSelfShadowOnly && (ShadingPath == EShadingPath::Mobile && !EnableModulatedSelfShadowCVar->GetValueOnRenderThread() && LightSceneInfo->Proxy && LightSceneInfo->Proxy->CastsModulatedShadows());
if (bPreShadow || bSelfShadowOnly || bMobileModulatedShadowsAllowSelfShadow)
{
ProjectionStencilingPasses.Empty(Renderer.Views.Num());
for (int32 ViewIndex = 0; ViewIndex < Renderer.Views.Num(); ViewIndex++)
#Associated Variable and Callsites
This variable is associated with another variable named CVarEnableModulatedSelfShadow
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:151
Scope: file
Source code excerpt:
///////////////////////////////////////////////////////////////////////////////////////////////////
// General
static TAutoConsoleVariable<int32> CVarEnableModulatedSelfShadow(
TEXT("r.Shadow.EnableModulatedSelfShadow"),
0,
TEXT("Allows modulated shadows to affect the shadow caster. (mobile only)"),
ECVF_RenderThreadSafe);
static int GStencilOptimization = 1;
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:1078
Scope: file
Source code excerpt:
// if rendering modulated shadows mask out subject mesh elements to prevent self shadowing.
if (bMobileModulatedProjections && !CVarEnableModulatedSelfShadow.GetValueOnRenderThread())
{
if (ViewIndex < ProjectionStencilingPasses.Num())
{
ProjectionStencilingPasses[ViewIndex]->SubmitDraw(RHICmdList, InstanceCullingDrawParams);
}
}