r.Shadow.Virtual.SubsurfaceShadowMinSourceAngle

r.Shadow.Virtual.SubsurfaceShadowMinSourceAngle

#Overview

name: r.Shadow.Virtual.SubsurfaceShadowMinSourceAngle

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.SubsurfaceShadowMinSourceAngle is to control the minimum source angle used for shadows and transmittance of subsurface materials with directional lights in the Virtual Shadow Map (VSM) system. This setting is part of Unreal Engine 5’s rendering system, specifically focusing on shadow rendering and subsurface scattering effects.

This setting variable is primarily used in the Renderer module of Unreal Engine 5, particularly within the Virtual Shadow Maps subsystem. It’s defined and utilized in the VirtualShadowMapProjection.cpp file, which is responsible for handling virtual shadow map projections.

The value of this variable is set through a console variable (CVar) system, allowing it to be adjusted at runtime. It’s initialized with a default value of 5 degrees but can be changed dynamically.

The associated variable CVarSubsurfaceShadowMinSourceAngle interacts directly with r.Shadow.Virtual.SubsurfaceShadowMinSourceAngle. They share the same value and purpose.

Developers must be aware that this variable affects the appearance of shadows for subsurface materials, particularly with directional lights. A higher value will result in more diffuse shadowing, which can be used to emulate light diffusion in subsurface materials.

Best practices when using this variable include:

  1. Adjusting it carefully to balance between realistic light diffusion and performance.
  2. Testing different values to find the optimal setting for your specific scene and materials.
  3. Being mindful of its impact on the overall visual quality and performance of shadow rendering.

Regarding the associated variable CVarSubsurfaceShadowMinSourceAngle:

Its purpose is identical to r.Shadow.Virtual.SubsurfaceShadowMinSourceAngle, serving as the actual console variable that controls the minimum source angle for subsurface shadows in virtual shadow maps.

This variable is used in the same Renderer module and Virtual Shadow Maps subsystem. It’s defined and used in the VirtualShadowMapProjection.cpp file.

The value is set when the console variable is created, with a default of 5 degrees. It can be changed at runtime through console commands.

CVarSubsurfaceShadowMinSourceAngle directly interacts with the rendering code. For example, it’s used to calculate the SubsurfaceMinSourceRadius parameter in the RenderVirtualShadowMapProjectionCommon function.

Developers should be aware that changes to this variable will immediately affect the rendering of subsurface shadows. It’s thread-safe and can be adjusted on the render thread.

Best practices include:

  1. Using the console to experiment with different values in real-time to find the optimal setting.
  2. Documenting the chosen value for consistency across development and production environments.
  3. Considering the impact on both visual quality and performance when adjusting this value.

#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:155

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarSubsurfaceShadowMinSourceAngle(
	TEXT("r.Shadow.Virtual.SubsurfaceShadowMinSourceAngle"),
	5,
	TEXT("Minimum source angle (in degrees) used for shadow & transmittance of sub-surface materials with directional lights.\n")
	TEXT("To emulate light diffusion with sub-surface materials, VSM can increase the light source radius depending on the material opacity.\n")
	TEXT("The higher this value, the more diffuse the shadowing with these materials will appear."),
	ECVF_RenderThreadSafe
);

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

);

static TAutoConsoleVariable<int32> CVarSubsurfaceShadowMinSourceAngle(
	TEXT("r.Shadow.Virtual.SubsurfaceShadowMinSourceAngle"),
	5,
	TEXT("Minimum source angle (in degrees) used for shadow & transmittance of sub-surface materials with directional lights.\n")
	TEXT("To emulate light diffusion with sub-surface materials, VSM can increase the light source radius depending on the material opacity.\n")
	TEXT("The higher this value, the more diffuse the shadowing with these materials will appear."),
	ECVF_RenderThreadSafe

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

Scope (from outer to inner):

file
function     static void RenderVirtualShadowMapProjectionCommon

Source code excerpt:

	PassParameters->ProjectionRect = FIntVector4(ProjectionRect.Min.X, ProjectionRect.Min.Y, ProjectionRect.Max.X, ProjectionRect.Max.Y);
	PassParameters->NormalBias = GetNormalBiasForShader();
	PassParameters->SubsurfaceMinSourceRadius = FMath::Sin(0.5f * FMath::DegreesToRadians(CVarSubsurfaceShadowMinSourceAngle.GetValueOnRenderThread()));
	PassParameters->InputType = uint32(InputType);
	PassParameters->bCullBackfacingPixels = VirtualShadowMapArray.ShouldCullBackfacingPixels() ? 1 : 0;
	PassParameters->Substrate = Substrate::BindSubstrateGlobalUniformParameters(View);
	if (bUseTileList)
	{
		PassParameters->TileListData = TiledVSMProjection->TileListDataBufferSRV;