r.FastVRam.ScreenSpaceShadowMask

r.FastVRam.ScreenSpaceShadowMask

#Overview

name: r.FastVRam.ScreenSpaceShadowMask

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

It is referenced in 9 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.FastVRam.ScreenSpaceShadowMask is to control the memory allocation strategy for the screen space shadow mask texture in Unreal Engine’s rendering system. This setting is part of the FastVRAM configuration, which aims to optimize the use of video memory for various rendering features.

This setting variable is primarily used in the Renderer module of Unreal Engine. It affects how the engine allocates memory for screen space shadow masks, which are crucial for efficient rendering of shadows in the scene.

The value of this variable is set through a console variable (CVar) system, as evidenced by the FASTVRAM_CVAR macro used in the SceneRendering.cpp file. It’s initialized with a default value of 1, indicating that by default, the engine will attempt to allocate the screen space shadow mask texture in fast VRAM.

The r.FastVRam.ScreenSpaceShadowMask variable interacts closely with the ScreenSpaceShadowMask variable, which represents the actual texture create flags used when allocating the shadow mask texture. The FFastVramConfig::Update function in SceneRendering.cpp shows how the CVar value is used to update the texture creation flags.

Developers should be aware that changing this setting can affect rendering performance and memory usage. Setting it to 1 (enabled) may improve rendering speed but could increase VRAM usage, while setting it to 0 (disabled) might save VRAM at the cost of potentially slower access to the shadow mask texture.

Best practices when using this variable include:

  1. Profiling the application to determine if enabling fast VRAM for screen space shadow masks provides a noticeable performance benefit.
  2. Considering the target hardware specifications, as the effectiveness of this setting may vary depending on the available VRAM and its speed.
  3. Balancing this setting with other FastVRAM settings to optimize overall rendering performance and memory usage.

Regarding the associated variable ScreenSpaceShadowMask:

The purpose of ScreenSpaceShadowMask is to represent the actual texture for storing screen space shadow information. It’s used in various parts of the rendering pipeline, particularly in the base pass rendering and forward shadow projections.

This variable is used in the Renderer module, specifically in functions related to base pass rendering and light rendering.

The ScreenSpaceShadowMask texture is typically created during the rendering process, as seen in the RenderForwardShadowProjections and RenderLights functions.

It interacts with other rendering-related variables and textures, such as SceneDepth and ScreenSpaceAO.

Developers should be aware that this texture is crucial for efficient shadow rendering, especially in forward rendering scenarios. Its resolution and format can affect both rendering quality and performance.

Best practices for using ScreenSpaceShadowMask include:

  1. Ensuring it’s properly resolved and accessible when needed in custom shaders.
  2. Considering its impact on memory usage, especially on platforms with limited VRAM.
  3. Optimizing its usage in conjunction with other shadow rendering techniques for the best balance of quality and performance.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:

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);
FASTVRAM_CVAR(SSR, 0);
FASTVRAM_CVAR(DBufferA, 0);

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/BasePassRendering.cpp:777

Scope (from outer to inner):

file
function     TRDGUniformBufferRef<FOpaqueBasePassUniformParameters> CreateOpaqueBasePassUniformBuffer

Source code excerpt:

		BasePassParameters.ResolvedSceneDepthTexture = SystemTextures.White;

		if (ForwardBasePassTextures.ScreenSpaceShadowMask)
		{
			BasePassParameters.UseForwardScreenSpaceShadowMask = 1;
			BasePassParameters.ForwardScreenSpaceShadowMaskTexture = ForwardBasePassTextures.ScreenSpaceShadowMask;
		}

		if (HasBeenProduced(ForwardBasePassTextures.ScreenSpaceAO))
		{
			BasePassParameters.IndirectOcclusionTexture = ForwardBasePassTextures.ScreenSpaceAO;
		}

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/BasePassRendering.cpp:1157

Scope (from outer to inner):

file
function     void FDeferredShadingSceneRenderer::RenderBasePass

Source code excerpt:

		ForwardBasePassTextures.SceneDepthIfResolved = SceneTextures.Depth.IsSeparate() ? SceneTextures.Depth.Resolve : nullptr;
		ForwardBasePassTextures.ScreenSpaceAO = SceneTextures.ScreenSpaceAO;
		ForwardBasePassTextures.ScreenSpaceShadowMask = ForwardShadowMaskTexture;
	}
	else if (!ExclusiveDepthStencil.IsDepthWrite())
	{
		// If depth write is not enabled, we can bound the depth texture as read only
		ForwardBasePassTextures.SceneDepthIfResolved = SceneTextures.Depth.Resolve;
	}

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/BasePassRendering.h:70

Scope: file

Source code excerpt:

{
	FRDGTextureRef ScreenSpaceAO = nullptr;
	FRDGTextureRef ScreenSpaceShadowMask = nullptr;
	FRDGTextureRef SceneDepthIfResolved = nullptr;
	bool bIs24BitUnormDepthStencil = false;
};

BEGIN_GLOBAL_SHADER_PARAMETER_STRUCT(FSharedBasePassUniformParameters,)
	SHADER_PARAMETER_STRUCT(FForwardLightData, Forward)

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/LightGridInjection.cpp:1013

Scope (from outer to inner):

file
function     void FDeferredShadingSceneRenderer::RenderForwardShadowProjections

Source code excerpt:

			FRDGTextureDesc Desc(FRDGTextureDesc::Create2D(SceneTextures.Config.Extent, PF_B8G8R8A8, FClearValueBinding::White, TexCreate_RenderTargetable | TexCreate_ShaderResource));
			Desc.NumSamples = SceneDepthTexture->Desc.NumSamples;
			ForwardScreenSpaceShadowMask = CreateTextureMSAA(GraphBuilder, Desc, TEXT("ShadowMaskTextureMS"), TEXT("ShadowMaskTexture"), GFastVRamConfig.ScreenSpaceShadowMask);
			if (bIsHairEnable)
			{
				Desc.NumSamples = 1;
				ForwardScreenSpaceShadowMaskSubPixel = CreateTextureMSAA(GraphBuilder, Desc, TEXT("ShadowMaskSubPixelTextureMS"), TEXT("ShadowMaskSubPixelTexture"), GFastVRamConfig.ScreenSpaceShadowMask);
			}
		}

		RDG_EVENT_SCOPE(GraphBuilder, "ShadowProjectionOnOpaque");
		RDG_GPU_STAT_SCOPE(GraphBuilder, ShadowProjection);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/LightRendering.cpp:1585

Scope (from outer to inner):

file
function     void FDeferredShadingSceneRenderer::RenderLights

Source code excerpt:

					if (!SharedScreenShadowMaskTexture || !SharedScreenShadowMaskSubPixelTexture)
					{
						const FRDGTextureDesc SharedScreenShadowMaskTextureDesc(FRDGTextureDesc::Create2D(SceneTextures.Config.Extent, PF_B8G8R8A8, FClearValueBinding::White, TexCreate_RenderTargetable | TexCreate_ShaderResource | GFastVRamConfig.ScreenSpaceShadowMask));
						
						if (!SharedScreenShadowMaskTexture && !bElideScreenShadowMask)
						{
							SharedScreenShadowMaskTexture = GraphBuilder.CreateTexture(SharedScreenShadowMaskTextureDesc, TEXT("ShadowMaskTexture"));
						}
						if (!SharedScreenShadowMaskSubPixelTexture && bUseHairLighting && !bElideScreenShadowMaskSubPixel)

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

Scope: file

Source code excerpt:

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);
FASTVRAM_CVAR(SSR, 0);
FASTVRAM_CVAR(DBufferA, 0);

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

Scope (from outer to inner):

file
function     void FFastVramConfig::Update

Source code excerpt:

	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);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_SSR, SSR);
	bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_DBufferA, DBufferA);

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

Scope: file

Source code excerpt:

	ETextureCreateFlags DistanceFieldAOConfidence;
	ETextureCreateFlags Distortion;
	ETextureCreateFlags ScreenSpaceShadowMask;
	ETextureCreateFlags VolumetricFog;
	ETextureCreateFlags SeparateTranslucency;
	ETextureCreateFlags SeparateTranslucencyModulate;
	ETextureCreateFlags ScreenSpaceAO;
	ETextureCreateFlags SSR;
	ETextureCreateFlags DBufferA;