r.Shadow.Virtual.CullBackfacingPixels

r.Shadow.Virtual.CullBackfacingPixels

#Overview

name: r.Shadow.Virtual.CullBackfacingPixels

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.CullBackfacingPixels is to control whether shadow data is generated for pixels that are backfacing to the light in virtual shadow maps. This setting is part of the rendering system, specifically the virtual shadow mapping feature in Unreal Engine 5.

This setting variable is primarily used in the Renderer module of Unreal Engine, particularly in the virtual shadow map subsystem. Based on the callsites, it’s implemented in the VirtualShadowMapArray.cpp file, which is part of the virtual shadow mapping functionality.

The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 1 (enabled) but can be changed at runtime using console commands or through engine configuration files.

The associated variable CVarCullBackfacingPixels directly interacts with r.Shadow.Virtual.CullBackfacingPixels. They share the same value and purpose.

Developers should be aware that enabling this variable (which is the default behavior) will optimize shadow rendering by not generating shadow data for pixels that are backfacing to the light. This can improve performance but might affect the visual quality of shadows in certain edge cases.

Best practices when using this variable include:

  1. Keep it enabled (value 1) for better performance in most scenarios.
  2. If you notice any visual artifacts in shadows, especially for thin objects or in complex geometry setups, you might want to disable it (set to 0) and test the visual difference.
  3. Profile your game with this setting both enabled and disabled to understand its performance impact in your specific use case.

Regarding the associated variable CVarCullBackfacingPixels:

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VirtualShadowMaps/VirtualShadowMapArray.cpp:170

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarCullBackfacingPixels(
	TEXT("r.Shadow.Virtual.CullBackfacingPixels"),
	1,
	TEXT("When enabled does not generate shadow data for pixels that are backfacing to the light."),
	ECVF_RenderThreadSafe
);

int32 GEnableNonNaniteVSM = 1;

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VirtualShadowMaps/VirtualShadowMapArray.cpp:169

Scope: file

Source code excerpt:

);

static TAutoConsoleVariable<int32> CVarCullBackfacingPixels(
	TEXT("r.Shadow.Virtual.CullBackfacingPixels"),
	1,
	TEXT("When enabled does not generate shadow data for pixels that are backfacing to the light."),
	ECVF_RenderThreadSafe
);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VirtualShadowMaps/VirtualShadowMapArray.cpp:422

Scope (from outer to inner):

file
function     void FVirtualShadowMapArray::Initialize

Source code excerpt:

	CacheManager = InCacheManager;

	bCullBackfacingPixels = CVarCullBackfacingPixels.GetValueOnRenderThread() != 0;
	bUseHzbOcclusion = CVarShadowsVirtualUseHZB.GetValueOnRenderThread() != 0;
	bUseTwoPassHzbOcclusion = CVarShadowsVirtualUseHZB.GetValueOnRenderThread() == 2;

	UniformParameters.NumFullShadowMaps = 0;
	UniformParameters.NumSinglePageShadowMaps = 0;
	UniformParameters.NumShadowMapSlots = 0;