r.shadow.ShadowMapsRenderEarly
r.shadow.ShadowMapsRenderEarly
#Overview
name: r.shadow.ShadowMapsRenderEarly
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
If enabled, shadows will render earlier in the frame. This can help async compute scheduling on some platforms\nNote: This is not compatible with VSMs\n
It is referenced in 4
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.shadow.ShadowMapsRenderEarly is to control the timing of shadow rendering in the Unreal Engine 5 rendering pipeline. It allows shadows to be rendered earlier in the frame, which can potentially improve async compute scheduling on certain platforms.
This setting variable is primarily used in the rendering system, specifically within the deferred shading renderer. It is part of the shadow rendering subsystem in Unreal Engine 5.
The value of this variable is set through a console variable (CVarShadowMapsRenderEarly) defined in the DeferredShadingRenderer.cpp file. It is initialized with a default value of 0, meaning the feature is disabled by default.
The main interaction with this variable occurs in the FDeferredShadingSceneRenderer::Render function. When enabled, it triggers the shadow depth maps to be rendered earlier in the frame than they would be normally.
Developers must be aware of the following when using this variable:
- It is not compatible with Virtual Shadow Maps (VSMs).
- Enabling this feature may affect the rendering pipeline’s order of operations.
- It is intended to help with async compute scheduling, but its effectiveness may vary depending on the platform.
Best practices when using this variable include:
- Only enable it if you’re experiencing issues with async compute scheduling on specific platforms.
- Test thoroughly after enabling to ensure it doesn’t negatively impact your game’s performance or visual quality.
- Be cautious when using it in conjunction with other shadow-related settings, especially Virtual Shadow Maps.
Regarding the associated variable CVarShadowMapsRenderEarly:
This is the actual console variable that controls the r.shadow.ShadowMapsRenderEarly setting. It is defined as a TAutoConsoleVariable
The purpose of CVarShadowMapsRenderEarly is to provide a way to toggle the early shadow rendering feature on and off dynamically. It is used directly in the rendering code to determine whether to render shadows early.
This variable is set in the same file (DeferredShadingRenderer.cpp) and is accessed using the GetValueOnRenderThread() method to ensure thread-safe access during rendering.
Developers should be aware that changing this variable at runtime will immediately affect the rendering pipeline. It’s important to consider the potential performance implications and visual changes that may occur when toggling this setting.
Best practices for using CVarShadowMapsRenderEarly include:
- Use it for debugging and performance testing purposes.
- Consider exposing it as a user-configurable setting if it proves beneficial for a wide range of hardware configurations.
- Monitor its impact on frame times and overall rendering performance when enabled.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DeferredShadingRenderer.cpp:214
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarShadowMapsRenderEarly(
TEXT("r.shadow.ShadowMapsRenderEarly"), 0,
TEXT("If enabled, shadows will render earlier in the frame. This can help async compute scheduling on some platforms\n")
TEXT("Note: This is not compatible with VSMs\n"),
ECVF_RenderThreadSafe);
static TAutoConsoleVariable<int32> CVarTranslucencyVelocity(
TEXT("r.Translucency.Velocity"), 1,
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DeferredShadingRenderer.cpp:2602
Scope (from outer to inner):
file
function void FDeferredShadingSceneRenderer::Render
Source code excerpt:
AsyncLumenIndirectLightingOutputs);
// If we haven't already rendered shadow maps, render them now (due to forward shading or r.shadow.ShadowMapsRenderEarly)
if (!bShadowMapsRenderedEarly)
{
if (VirtualShadowMapArray.IsEnabled())
{
// TODO: actually move this inside RenderShadowDepthMaps instead of this extra scope to make it 1:1 with profiling captures/traces
RDG_GPU_STAT_SCOPE(GraphBuilder, ShadowDepths);
#Associated Variable and Callsites
This variable is associated with another variable named CVarShadowMapsRenderEarly
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DeferredShadingRenderer.cpp:213
Scope: file
Source code excerpt:
ECVF_RenderThreadSafe);
static TAutoConsoleVariable<int32> CVarShadowMapsRenderEarly(
TEXT("r.shadow.ShadowMapsRenderEarly"), 0,
TEXT("If enabled, shadows will render earlier in the frame. This can help async compute scheduling on some platforms\n")
TEXT("Note: This is not compatible with VSMs\n"),
ECVF_RenderThreadSafe);
static TAutoConsoleVariable<int32> CVarTranslucencyVelocity(
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DeferredShadingRenderer.cpp:2370
Scope (from outer to inner):
file
function void FDeferredShadingSceneRenderer::Render
Source code excerpt:
ComputeVolumetricFog(GraphBuilder, SceneTextures);
}
else if ( CVarShadowMapsRenderEarly.GetValueOnRenderThread() )
{
// Disable early shadows if VSM is enabled, but warn
ensureMsgf(!VirtualShadowMapArray.IsEnabled(), TEXT("Virtual shadow maps are not supported with r.shadow.ShadowMapsRenderEarly. Early shadows will be disabled"));
if (!VirtualShadowMapArray.IsEnabled())
{
RenderShadowDepthMaps(GraphBuilder, InitViewTaskDatas.DynamicShadows, InstanceCullingManager, ExternalAccessQueue);