r.Shadow.Virtual.SMRT.TexelDitherScaleDirectional

r.Shadow.Virtual.SMRT.TexelDitherScaleDirectional

#Overview

name: r.Shadow.Virtual.SMRT.TexelDitherScaleDirectional

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.SMRT.TexelDitherScaleDirectional is to apply a dither effect to shadow map ray casts for directional lights in order to help hide aliasing artifacts that may occur due to insufficient shadow resolution. This setting is part of the rendering system, specifically the virtual shadow map implementation in Unreal Engine 5.

This setting variable is primarily used in the Renderer module of Unreal Engine, specifically within the Virtual Shadow Maps subsystem. It’s referenced in the VirtualShadowMapProjection.cpp file, which handles the projection and rendering of virtual shadow maps.

The value of this variable is set through a console variable (CVarSMRTTexelDitherScaleDirectional) with a default value of 2.0f. It can be modified at runtime through console commands or programmatically.

The associated variable CVarSMRTTexelDitherScaleDirectional directly interacts with r.Shadow.Virtual.SMRT.TexelDitherScaleDirectional, as they share the same value. This console variable is used to retrieve the current value of the setting in the rendering code.

Developers must be aware that setting this value too high can cause shadow light leaks near occluders. This means that while increasing the value can help reduce aliasing artifacts, it may introduce other visual artifacts if set too aggressively.

Best practices when using this variable include:

  1. Start with the default value (2.0f) and adjust gradually.
  2. Test thoroughly in various lighting conditions and scenes to find the optimal balance between aliasing reduction and avoiding light leaks.
  3. Consider adjusting this value dynamically based on the scene complexity or distance from the camera.
  4. Use in conjunction with other shadow quality settings for best results.

Regarding the associated variable CVarSMRTTexelDitherScaleDirectional:

The purpose of CVarSMRTTexelDitherScaleDirectional is to provide a configurable interface for the r.Shadow.Virtual.SMRT.TexelDitherScaleDirectional setting. It allows the engine to access and modify the dither scale value at runtime.

This console variable is used within the Renderer module, specifically in the Virtual Shadow Maps implementation. It’s defined and used in the same file as the main setting (VirtualShadowMapProjection.cpp).

The value of CVarSMRTTexelDitherScaleDirectional is set when the console variable is initialized, but can be changed at runtime through console commands.

This variable directly interacts with r.Shadow.Virtual.SMRT.TexelDitherScaleDirectional, as they represent the same setting.

Developers should be aware that changes to CVarSMRTTexelDitherScaleDirectional will immediately affect the shadow rendering. It’s thread-safe and can be accessed from the render thread.

Best practices for using CVarSMRTTexelDitherScaleDirectional include:

  1. Use GetValueOnRenderThread() when accessing the value in render thread code.
  2. Consider exposing this setting in a user-friendly way in your game’s graphics options if shadow quality is important for your project.
  3. Monitor performance impact when adjusting this value, as it may affect rendering time.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VirtualShadowMaps/VirtualShadowMapProjection.cpp:107

Scope: file

Source code excerpt:


static TAutoConsoleVariable<float> CVarSMRTTexelDitherScaleDirectional(
	TEXT( "r.Shadow.Virtual.SMRT.TexelDitherScaleDirectional" ),
	2.0f,
	TEXT( "Applies a dither to the shadow map ray casts for directional lights to help hide aliasing due to insufficient shadow resolution.\n" )
	TEXT( "Setting this too high can cause shadows light leaks near occluders." ),
	ECVF_Scalability | ECVF_RenderThreadSafe
);

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VirtualShadowMaps/VirtualShadowMapProjection.cpp:106

Scope: file

Source code excerpt:

);

static TAutoConsoleVariable<float> CVarSMRTTexelDitherScaleDirectional(
	TEXT( "r.Shadow.Virtual.SMRT.TexelDitherScaleDirectional" ),
	2.0f,
	TEXT( "Applies a dither to the shadow map ray casts for directional lights to help hide aliasing due to insufficient shadow resolution.\n" )
	TEXT( "Setting this too high can cause shadows light leaks near occluders." ),
	ECVF_Scalability | ECVF_RenderThreadSafe
);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VirtualShadowMaps/VirtualShadowMapProjection.cpp:194

Scope (from outer to inner):

file
function     FVirtualShadowMapSMRTSettings GetVirtualShadowMapSMRTSettings

Source code excerpt:

		Out.SMRTRayLengthScale = CVarSMRTRayLengthScaleDirectional.GetValueOnRenderThread();
		Out.SMRTCotMaxRayAngleFromLight = 0.0f;	// unused in this path
		Out.SMRTTexelDitherScale = CVarSMRTTexelDitherScaleDirectional.GetValueOnRenderThread();
		Out.SMRTExtrapolateSlope = CVarSMRTExtrapolateMaxSlopeDirectional.GetValueOnRenderThread();
		Out.SMRTMaxSlopeBias = 0.0f; // unused in this path
	}
	else
	{
		Out.SMRTRayCount = CVarSMRTRayCountLocal.GetValueOnRenderThread();