r.FastVRam.DistanceFieldShadows

r.FastVRam.DistanceFieldShadows

#Overview

name: r.FastVRam.DistanceFieldShadows

This variable is created as a Console Variable (cvar).

It is referenced in 15 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.FastVRam.DistanceFieldShadows is to control the texture creation flags for distance field shadows in Unreal Engine 5’s rendering system. This setting is part of the FastVRAM configuration, which optimizes texture memory usage for various rendering features.

The Unreal Engine subsystem that primarily relies on this setting variable is the Renderer module, specifically the components dealing with distance field shadows and scene rendering.

The value of this variable is set using the FASTVRAM_CVAR macro in the SceneRendering.cpp file. It is initialized with a default value of 1, indicating that distance field shadow textures should use fast VRAM by default.

This variable interacts with the DistanceFieldShadows associated variable, which is used to check if the target platform supports distance field shadows. The DistanceFieldShadows feature is part of the ETargetPlatformFeatures enum and is used in various platform-specific checks throughout the engine.

Developers must be aware that this setting affects the performance and memory usage of distance field shadows. When enabled (set to 1), it instructs the engine to use fast VRAM for distance field shadow textures, which can improve rendering performance but may increase memory usage on the GPU.

Best practices when using this variable include:

  1. Considering the target hardware capabilities when adjusting this setting.
  2. Balancing performance gains with memory usage, especially on platforms with limited VRAM.
  3. Testing the impact of enabling or disabling this setting on your specific project’s performance and visual quality.

Regarding the associated variable DistanceFieldShadows:

The purpose of DistanceFieldShadows is to indicate whether a target platform supports distance field shadows. It is used in various parts of the engine to determine if distance field shadow-related features should be enabled or disabled.

This variable is primarily used in the TargetPlatform module and is checked when determining platform capabilities, packaging content, and initializing rendering features.

The value of this variable is typically set by platform-specific implementations of the SupportsDistanceFieldShadows() function.

Developers should be aware that the availability of distance field shadows can significantly impact the visual quality and performance of their games on different platforms. They should:

  1. Check for platform support before enabling distance field shadow features in their games.
  2. Provide alternative shadow techniques for platforms that don’t support distance field shadows.
  3. Consider the performance implications of using distance field shadows, especially on lower-end devices.

Best practices include:

  1. Using the SupportsFeature() function to check for distance field shadow support before enabling related features.
  2. Implementing scalability options that allow users to enable or disable distance field shadows based on their hardware capabilities.
  3. Testing the game’s performance and visual quality both with and without distance field shadows on various target platforms.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:487

Scope: file

Source code excerpt:

FASTVRAM_CVAR(DistanceFieldAOBentNormal, 0); 
FASTVRAM_CVAR(DistanceFieldIrradiance, 0); 
FASTVRAM_CVAR(DistanceFieldShadows, 1);
FASTVRAM_CVAR(Distortion, 1);
FASTVRAM_CVAR(ScreenSpaceShadowMask, 1);
FASTVRAM_CVAR(VolumetricFog, 1);
FASTVRAM_CVAR(SeparateTranslucency, 0); 
FASTVRAM_CVAR(SeparateTranslucencyModulate, 0);
FASTVRAM_CVAR(ScreenSpaceAO,0);

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Developer/DeviceManager/Private/Widgets/Details/SDeviceDetails.cpp:147

Scope (from outer to inner):

file
function     BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION void SDeviceDetails::Construct
lambda-function

Source code excerpt:

				// platform features
				FeatureList.Add(MakeShareable(new FDeviceDetailsFeature(TEXT("AudioStreaming"), TargetPlatformSettings.SupportsFeature(ETargetPlatformFeatures::AudioStreaming))));
				FeatureList.Add(MakeShareable(new FDeviceDetailsFeature(TEXT("DistanceFieldShadows"), TargetPlatformSettings.SupportsFeature(ETargetPlatformFeatures::DistanceFieldShadows))));
				FeatureList.Add(MakeShareable(new FDeviceDetailsFeature(TEXT("DistanceFieldAO"), TargetPlatformSettings.SupportsFeature(ETargetPlatformFeatures::DistanceFieldAO))));
				FeatureList.Add(MakeShareable(new FDeviceDetailsFeature(TEXT("GrayscaleSRGB"), TargetPlatformSettings.SupportsFeature(ETargetPlatformFeatures::GrayscaleSRGB))));
				FeatureList.Add(MakeShareable(new FDeviceDetailsFeature(TEXT("HighQualityLightmaps"), TargetPlatformSettings.SupportsFeature(ETargetPlatformFeatures::HighQualityLightmaps))));
				FeatureList.Add(MakeShareable(new FDeviceDetailsFeature(TEXT("LowQualityLightmaps"), TargetPlatformSettings.SupportsFeature(ETargetPlatformFeatures::LowQualityLightmaps))));
				FeatureList.Add(MakeShareable(new FDeviceDetailsFeature(TEXT("MultipleGameInstances"), TargetPlatformSettings.SupportsFeature(ETargetPlatformFeatures::MultipleGameInstances))));
				FeatureList.Add(MakeShareable(new FDeviceDetailsFeature(TEXT("Packaging"), TargetPlatformSettings.SupportsFeature(ETargetPlatformFeatures::Packaging))));

#Loc: <Workspace>/Engine/Source/Developer/TargetPlatform/Public/Common/TargetPlatformBase.h:453

Scope (from outer to inner):

file
class        class TTargetPlatformBase : public FTargetPlatformBase
function     virtual bool SupportsFeature

Source code excerpt:

			return TPlatformProperties::SupportsAudioStreaming();

		case ETargetPlatformFeatures::DistanceFieldShadows:
			return TPlatformProperties::SupportsDistanceFieldShadows();

		case ETargetPlatformFeatures::DistanceFieldAO:
			return TPlatformProperties::SupportsDistanceFieldAO();

		case ETargetPlatformFeatures::GrayscaleSRGB:

#Loc: <Workspace>/Engine/Source/Developer/TargetPlatform/Public/Common/TargetPlatformSettingsBase.h:85

Scope (from outer to inner):

file
class        class TTargetPlatformSettingsBase : public FTargetPlatformSettingsBase
function     virtual bool SupportsFeature

Source code excerpt:

			return TPlatformProperties::SupportsAudioStreaming();

		case ETargetPlatformFeatures::DistanceFieldShadows:
			return TPlatformProperties::SupportsDistanceFieldShadows();

		case ETargetPlatformFeatures::DistanceFieldAO:
			return TPlatformProperties::SupportsDistanceFieldAO();

		case ETargetPlatformFeatures::GrayscaleSRGB:

#Loc: <Workspace>/Engine/Source/Developer/TargetPlatform/Public/Interfaces/ITargetPlatformSettings.h:19

Scope: file

Source code excerpt:


	/** Distance field shadows. */
	DistanceFieldShadows,

	/** Distance field AO. */
	DistanceFieldAO,

	/** Gray scale SRGB texture formats support. */
	GrayscaleSRGB,

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/ShadowMap.cpp:550

Scope (from outer to inner):

file
function     void FShadowMap2D::Serialize

Source code excerpt:

	FShadowMap::Serialize(Ar);
	
	if( Ar.IsCooking() && !Ar.CookingTarget()->SupportsFeature(ETargetPlatformFeatures::DistanceFieldShadows) )
	{
		UShadowMapTexture2D* Dummy = NULL;
		Ar << Dummy;
	}
	else
	{

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistanceFieldShadowing.cpp:944

Scope (from outer to inner):

file
function     FRDGTextureRef FProjectedShadowInfo::RenderRayTracedDistanceFieldProjection

Source code excerpt:

				const FIntPoint BufferSize = GetBufferSizeForDFShadows(View);
				FRDGTextureDesc Desc(FRDGTextureDesc::Create2D(BufferSize, PF_G16R16F, FClearValueBinding::None, TexCreate_UAV | TexCreate_ShaderResource));
				Desc.Flags |= GFastVRamConfig.DistanceFieldShadows;
				SDFShadowViewGPUData.RayTracedShadowsTexture = GraphBuilder.CreateTexture(Desc, TEXT("RayTracedShadows"));
			}

			RayTraceShadows(
				GraphBuilder,
				bAsyncCompute,

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistanceFieldShadowing.cpp:1029

Scope (from outer to inner):

file
function     FRDGTextureRef FProjectedShadowInfo::RenderRayTracedDistanceFieldProjection

Source code excerpt:

			const FIntPoint BufferSize = GetBufferSizeForDFShadows(View);
			FRDGTextureDesc Desc(FRDGTextureDesc::Create2D(BufferSize, PF_G16R16F, FClearValueBinding::None, TexCreate_UAV | TexCreate_ShaderResource));
			Desc.Flags |= GFastVRamConfig.DistanceFieldShadows;
			SDFShadowViewGPUData.RayTracedShadowsTexture = GraphBuilder.CreateTexture(Desc, TEXT("RayTracedShadows"));
		}

		RayTraceShadows(
			GraphBuilder,
			bAsyncCompute,

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:487

Scope: file

Source code excerpt:

FASTVRAM_CVAR(DistanceFieldAOBentNormal, 0); 
FASTVRAM_CVAR(DistanceFieldIrradiance, 0); 
FASTVRAM_CVAR(DistanceFieldShadows, 1);
FASTVRAM_CVAR(Distortion, 1);
FASTVRAM_CVAR(ScreenSpaceShadowMask, 1);
FASTVRAM_CVAR(VolumetricFog, 1);
FASTVRAM_CVAR(SeparateTranslucency, 0); 
FASTVRAM_CVAR(SeparateTranslucencyModulate, 0);
FASTVRAM_CVAR(ScreenSpaceAO,0);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:687

Scope (from outer to inner):

file
function     void FFastVramConfig::Update

Source code excerpt:

	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_DistanceFieldAOBentNormal, DistanceFieldAOBentNormal);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_DistanceFieldIrradiance, DistanceFieldIrradiance);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_DistanceFieldShadows, DistanceFieldShadows);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_Distortion, Distortion);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_ScreenSpaceShadowMask, ScreenSpaceShadowMask);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_VolumetricFog, VolumetricFog);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_SeparateTranslucency, SeparateTranslucency);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_SeparateTranslucencyModulate, SeparateTranslucencyModulate);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_ScreenSpaceAO, ScreenSpaceAO);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.h:2835

Scope: file

Source code excerpt:

	ETextureCreateFlags DistanceFieldAOBentNormal;
	ETextureCreateFlags DistanceFieldAODownsampledBentNormal;
	ETextureCreateFlags DistanceFieldShadows;
	ETextureCreateFlags DistanceFieldIrradiance;
	ETextureCreateFlags DistanceFieldAOConfidence;
	ETextureCreateFlags Distortion;
	ETextureCreateFlags ScreenSpaceShadowMask;
	ETextureCreateFlags VolumetricFog;
	ETextureCreateFlags SeparateTranslucency;

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:2112

Scope (from outer to inner):

file
function     void FSceneRenderer::RenderShadowProjections

Source code excerpt:

	// Allocate arrays using the graph allocator so we can safely reference them in passes.
	using FProjectedShadowInfoArray = TArray<FProjectedShadowInfo*, SceneRenderingAllocator>;
	auto& DistanceFieldShadows = *GraphBuilder.AllocObject<FProjectedShadowInfoArray>();
	auto& NormalShadows = *GraphBuilder.AllocObject<FProjectedShadowInfoArray>();

	for (int32 ShadowIndex = 0; ShadowIndex < VisibleLightInfo.ShadowsToProject.Num(); ShadowIndex++)
	{
		FProjectedShadowInfo* ProjectedShadowInfo = VisibleLightInfo.ShadowsToProject[ShadowIndex];
		if (ProjectedShadowInfo->bRayTracedDistanceField)
		{
			DistanceFieldShadows.Add(ProjectedShadowInfo);
		}
		else if (ProjectedShadowInfo->HasVirtualShadowMap())
		{
			// Skip - handled elsewhere
		}
		else

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:2162

Scope (from outer to inner):

file
function     void FSceneRenderer::RenderShadowProjections

Source code excerpt:

	}

	if (DistanceFieldShadows.Num() > 0)
	{
		RDG_EVENT_SCOPE(GraphBuilder, "DistanceFieldShadows");

		// Distance field shadows need to be renderer last as they blend over far shadow cascades.
		for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
		{

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowRendering.cpp:2181

Scope (from outer to inner):

file
function     void FSceneRenderer::RenderShadowProjections

Source code excerpt:

			if (ScissorRect.Area() > 0)
			{
				for (int32 ShadowIndex = 0; ShadowIndex < DistanceFieldShadows.Num(); ShadowIndex++)
				{
					FProjectedShadowInfo* ProjectedShadowInfo = DistanceFieldShadows[ShadowIndex];

					if (Views.Num() == 1 || !ProjectedShadowInfo->DependentView || ProjectedShadowInfo->DependentView == &View || ProjectedShadowInfo->DependentView == View.GetPrimaryView())
					{
						ProjectedShadowInfo->RenderRayTracedDistanceFieldProjection(
							GraphBuilder,
							SceneTextures,

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SkyAtmosphereRendering.cpp:293

Scope (from outer to inner):

file
function     ESkyAtmospherePassLocation GetSkyAtmospherePassLocation

Source code excerpt:

		return ESkyAtmospherePassLocation::BeforePrePass;
	}
	// When SkyAtmLUT is running on graphics pipe, kickbefore BasePass to have a better overlap when DistanceFieldShadows is running async
	return ESkyAtmospherePassLocation::BeforeBasePass;
}

float GetValidAerialPerspectiveStartDepthInCm(const FViewInfo& View, const FSkyAtmosphereSceneProxy& SkyAtmosphereProxy)
{
	float AerialPerspectiveStartDepthKm = SkyAtmosphereProxy.GetAerialPerspectiveStartDepthKm();