r.Shadow.CSMScissorOptim

r.Shadow.CSMScissorOptim

#Overview

name: r.Shadow.CSMScissorOptim

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.CSMScissorOptim is to optimize the rendering of Cascaded Shadow Maps (CSM) by computing an optimized scissor rectangle size to exclude portions of the CSM slices that fall outside the view frustum.

This setting variable is primarily used in the rendering system, specifically for shadow rendering optimization. Based on the callsites, it is utilized in the Renderer module of Unreal Engine.

The value of this variable is set through a console variable (CVar) named CVarCSMScissorOptim. It is defined as a boolean value, defaulting to false.

The associated variable CVarCSMScissorOptim directly interacts with r.Shadow.CSMScissorOptim. They share the same value and purpose.

Developers must be aware that:

  1. This optimization is disabled by default.
  2. It only applies to directional lights with whole scene shadows.
  3. It does not work with one-pass point light shadows or ray-traced distance field shadows.

Best practices when using this variable include:

  1. Enable it when you want to optimize CSM rendering performance, especially in scenes with large open areas where parts of the shadow maps might fall outside the view frustum.
  2. Test thoroughly to ensure it doesn’t introduce any visual artifacts in your specific use case.
  3. Consider the trade-off between the potential performance gain and the cost of computing the optimized scissor rectangles.

Regarding the associated variable CVarCSMScissorOptim:

Developers should treat CVarCSMScissorOptim as the internal implementation of r.Shadow.CSMScissorOptim and generally interact with the latter when adjusting this setting.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowSetup.cpp:382

Scope: file

Source code excerpt:


static TAutoConsoleVariable<bool> CVarCSMScissorOptim(
	TEXT("r.Shadow.CSMScissorOptim"),
	false,
	TEXT("Compute optimized scissor rect size to exclude portions of the CSM slices outside the view frustum"),
	ECVF_RenderThreadSafe
);

/**

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowSetup.cpp:381

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<bool> CVarCSMScissorOptim(
	TEXT("r.Shadow.CSMScissorOptim"),
	false,
	TEXT("Compute optimized scissor rect size to exclude portions of the CSM slices outside the view frustum"),
	ECVF_RenderThreadSafe
);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowSetup.cpp:1747

Scope (from outer to inner):

file
function     bool FProjectedShadowInfo::ShouldUseCSMScissorOptim

Source code excerpt:

bool FProjectedShadowInfo::ShouldUseCSMScissorOptim() const
{
	return CVarCSMScissorOptim.GetValueOnRenderThread() != 0 && bWholeSceneShadow && bDirectionalLight && !bOnePassPointLightShadow && !bRayTracedDistanceField;
}

FORCEINLINE bool FProjectedShadowInfo::ShouldDrawStaticMesh(const FStaticMeshBatchRelevance& StaticMeshRelevance, const FLODMask& ShadowLODToRender, bool& bOutDrawingStaticMeshes) const
{
	if ((StaticMeshRelevance.CastShadow || (bSelfShadowOnly && StaticMeshRelevance.bUseForDepthPass)) && ShadowLODToRender.ContainsLOD(StaticMeshRelevance.GetLODIndex()))
	{