r.Shadow.Virtual.OnePassProjection.SkipScreenShadowMask

r.Shadow.Virtual.OnePassProjection.SkipScreenShadowMask

#Overview

name: r.Shadow.Virtual.OnePassProjection.SkipScreenShadowMask

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.Virtual.OnePassProjection.SkipScreenShadowMask is to optimize the rendering of virtual shadow maps by allowing the engine to skip the generation of the screen space shadow mask under certain conditions. This setting is part of Unreal Engine 5’s rendering system, specifically related to the shadow rendering pipeline.

This setting variable is primarily used in the Renderer module of Unreal Engine 5, as evidenced by its implementation in the LightRendering.cpp file within the Runtime/Renderer/Private directory.

The value of this variable is set using a TAutoConsoleVariable, which means it can be adjusted at runtime through console commands. By default, it is set to 1 (enabled).

The associated variable CVarOnePassProjectionSkipScreenShadowMask directly interacts with r.Shadow.Virtual.OnePassProjection.SkipScreenShadowMask. They share the same value and are used interchangeably in the code.

Developers must be aware that enabling this variable (which is the default behavior) can impact the rendering of shadows, particularly in scenarios where only virtual shadow maps are used. While it generally improves performance, it may affect the visual quality of shadows in certain edge cases.

Best practices when using this variable include:

  1. Keep it enabled (set to 1) for optimal performance in most scenarios.
  2. Disable it (set to 0) only when debugging shadow-related issues or when higher precision shadow masks are required at the cost of performance.
  3. Test thoroughly when changing this setting to ensure it doesn’t negatively impact the visual quality of your game’s shadows.

Regarding the associated variable CVarOnePassProjectionSkipScreenShadowMask:

The purpose of CVarOnePassProjectionSkipScreenShadowMask is to provide a programmatic way to access and modify the r.Shadow.Virtual.OnePassProjection.SkipScreenShadowMask setting within the C++ code of the engine.

This variable is used in the Renderer module, specifically in the light rendering process. It’s accessed in the RenderLights function of the FDeferredShadingSceneRenderer class.

The value of this variable is set and retrieved using the TAutoConsoleVariable interface, which allows for runtime modifications.

CVarOnePassProjectionSkipScreenShadowMask directly interacts with r.Shadow.Virtual.OnePassProjection.SkipScreenShadowMask, as they represent the same setting.

Developers should be aware that this variable is used in conditional statements to determine whether to elide (skip) the screen shadow mask generation. It’s part of a larger condition that considers other factors like the use of packed shadow mask bits, occlusion type, and the presence of virtual shadow maps.

Best practices for using CVarOnePassProjectionSkipScreenShadowMask include:

  1. Use GetValueOnRenderThread() when accessing its value in render thread operations.
  2. Consider the implications of changing this value on both performance and visual quality.
  3. Use it in conjunction with other shadow-related settings for a comprehensive approach to shadow optimization.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/LightRendering.cpp:140

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarOnePassProjectionSkipScreenShadowMask(
	TEXT("r.Shadow.Virtual.OnePassProjection.SkipScreenShadowMask"),
	1,
	TEXT("Allows skipping the screen space shadow mask entirely when only a virtual shadow map would write into it.\n")
	TEXT("Should generally be left enabled outside of debugging."),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<float> CVarContactShadowsOverrideLength(

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/LightRendering.cpp:139

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarOnePassProjectionSkipScreenShadowMask(
	TEXT("r.Shadow.Virtual.OnePassProjection.SkipScreenShadowMask"),
	1,
	TEXT("Allows skipping the screen space shadow mask entirely when only a virtual shadow map would write into it.\n")
	TEXT("Should generally be left enabled outside of debugging."),
	ECVF_RenderThreadSafe);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/LightRendering.cpp:1573

Scope (from outer to inner):

file
function     void FDeferredShadingSceneRenderer::RenderLights

Source code excerpt:

					// with no light functions, as in that case we can directly sample the shadow mask bits in the lighting shader.
					bElideScreenShadowMask = 
						CVarOnePassProjectionSkipScreenShadowMask.GetValueOnRenderThread() != 0 &&
						ShadowSceneRenderer->UsePackedShadowMaskBits() &&
						OcclusionType == FLightOcclusionType::Shadowmap &&
						!(bDirectLighting && bDrawLightFunction) &&
						!bDrawPreviewIndicator &&
						SortedLightInfo.SortKey.Fields.LightType != LightType_Directional &&
						VisibleLightInfo.VirtualShadowMapId != INDEX_NONE &&	// Not a directional light, so no per-view clipmaps