r.VolumetricCloud.ShadowMap.SnapLength

r.VolumetricCloud.ShadowMap.SnapLength

#Overview

name: r.VolumetricCloud.ShadowMap.SnapLength

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.VolumetricCloud.ShadowMap.SnapLength is to control the snapping size of the cloud shadowmap position in the volumetric cloud rendering system. This setting is used to prevent flickering artifacts in the cloud shadows.

This setting variable is primarily used in the Volumetric Cloud Rendering subsystem of Unreal Engine 5’s rendering module. It’s specifically utilized in the shadow mapping process for volumetric clouds.

The value of this variable is set through the console variable system in Unreal Engine. It’s defined as a TAutoConsoleVariable with a default value of 20.0f, representing 20 kilometers.

The associated variable CVarVolumetricCloudShadowMapSnapLength directly interacts with r.VolumetricCloud.ShadowMap.SnapLength. They share the same value and purpose.

Developers must be aware that this variable affects the visual quality and performance of volumetric cloud shadows. A larger value will result in less frequent updates to the shadow map position, which can reduce flickering but may also reduce accuracy for fast-moving clouds or cameras.

Best practices when using this variable include:

  1. Adjusting it based on the scale of your game world and the typical movement speed of the camera or clouds.
  2. Testing different values to find the best balance between visual quality and performance for your specific use case.
  3. Consider exposing this setting to players in graphics options for scalability across different hardware capabilities.

Regarding the associated variable CVarVolumetricCloudShadowMapSnapLength:

The purpose of CVarVolumetricCloudShadowMapSnapLength is identical to r.VolumetricCloud.ShadowMap.SnapLength. It’s the C++ variable that directly controls the snapping behavior in the engine’s code.

This variable is used in the Volumetric Cloud Rendering system, specifically in the InitVolumetricCloudsForViews function.

The value is set when the engine initializes the console variable system, and it can be modified at runtime through console commands.

Developers should be aware that this variable is used directly in calculations for positioning the cloud shadowmap. It’s converted from kilometers to centimeters in the code, so the input value should always be in kilometers.

Best practices include:

  1. Using GetValueOnAnyThread() when accessing this variable, as shown in the code snippet.
  2. Being cautious when modifying this value at runtime, as it can cause sudden changes in shadow appearance.
  3. Considering the performance implications of very small values, which could cause frequent updates to the shadow map position.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VolumetricCloudRendering.cpp:143

Scope: file

Source code excerpt:


static TAutoConsoleVariable<float> CVarVolumetricCloudShadowMapSnapLength(
	TEXT("r.VolumetricCloud.ShadowMap.SnapLength"), 20.0f,
	TEXT("Snapping size in kilometers of the cloud shadowmap position to avoid flickering."),
	ECVF_RenderThreadSafe | ECVF_Scalability);

static TAutoConsoleVariable<float> CVarVolumetricCloudShadowMapRaySampleMaxCount(
	TEXT("r.VolumetricCloud.ShadowMap.RaySampleMaxCount"), 128.0f,
	TEXT("The maximum number of samples taken while ray marching shadow rays to evaluate the cloud shadow map."),

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VolumetricCloudRendering.cpp:142

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe | ECVF_Scalability);

static TAutoConsoleVariable<float> CVarVolumetricCloudShadowMapSnapLength(
	TEXT("r.VolumetricCloud.ShadowMap.SnapLength"), 20.0f,
	TEXT("Snapping size in kilometers of the cloud shadowmap position to avoid flickering."),
	ECVF_RenderThreadSafe | ECVF_Scalability);

static TAutoConsoleVariable<float> CVarVolumetricCloudShadowMapRaySampleMaxCount(
	TEXT("r.VolumetricCloud.ShadowMap.RaySampleMaxCount"), 128.0f,

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VolumetricCloudRendering.cpp:1680

Scope (from outer to inner):

file
function     void FSceneRenderer::InitVolumetricCloudsForViews
lambda-function

Source code excerpt:

						const FVector3f LightPosition = LookAtPosition - AtmopshericLightDirection * SphereRadius;

						float WorldSizeSnap = CVarVolumetricCloudShadowMapSnapLength.GetValueOnAnyThread() * KilometersToCentimeters;
						LookAtPosition.X = (FMath::FloorToFloat((LookAtPosition.X + 0.5f * WorldSizeSnap) / WorldSizeSnap)) * WorldSizeSnap; // offset by 0.5 to not snap around origin
						LookAtPosition.Y = (FMath::FloorToFloat((LookAtPosition.Y + 0.5f * WorldSizeSnap) / WorldSizeSnap)) * WorldSizeSnap;
						LookAtPosition.Z = (FMath::FloorToFloat((LookAtPosition.Z + 0.5f * WorldSizeSnap) / WorldSizeSnap)) * WorldSizeSnap;

						TranslatedWorldToWorld = FTranslationMatrix(-View.ViewMatrices.GetPreViewTranslation());
					}