r.CapsuleShadowFadeAngleFromVertical

r.CapsuleShadowFadeAngleFromVertical

#Overview

name: r.CapsuleShadowFadeAngleFromVertical

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

It is referenced in 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.CapsuleShadowFadeAngleFromVertical is to control the angle from vertical up at which indirect capsule shadows start to fade out, primarily to avoid self-shadowing artifacts in the rendering system.

This setting variable is primarily used in the Renderer module of Unreal Engine, specifically in the capsule shadow rendering subsystem. It’s referenced in the CapsuleShadowRendering.cpp file, which is part of the engine’s rendering pipeline.

The value of this variable is set using an FAutoConsoleVariableRef, which means it can be adjusted at runtime through console commands or configuration files. It’s initialized with a default value of PI / 3 (60 degrees).

The associated variable GCapsuleShadowFadeAngleFromVertical directly interacts with r.CapsuleShadowFadeAngleFromVertical. They share the same value, with GCapsuleShadowFadeAngleFromVertical being the actual global variable used in the code.

Developers must be aware that this variable affects the visual quality and performance of capsule shadows. Adjusting this value can help reduce self-shadowing artifacts, but may also affect the overall shadow appearance and potentially impact performance.

Best practices when using this variable include:

  1. Carefully testing different values to find the right balance between visual quality and performance.
  2. Considering the impact on different types of scenes and lighting conditions.
  3. Using it in conjunction with other shadow-related settings for optimal results.

Regarding the associated variable GCapsuleShadowFadeAngleFromVertical:

The purpose of GCapsuleShadowFadeAngleFromVertical is to store the actual value used in the rendering calculations for the capsule shadow fade angle.

This variable is used directly in the rendering code, specifically in the IndirectCapsuleShadowsResources function and when setting up parameters for capsule shadow rendering.

The value of this variable is set by the r.CapsuleShadowFadeAngleFromVertical console variable.

It interacts with other parts of the capsule shadow rendering system, such as being used to calculate the cosine of the fade start angle, which is then used in the rendering parameters.

Developers should be aware that modifying this variable directly in code is not recommended, as it’s intended to be controlled through the console variable system.

Best practices for using this variable include accessing it only for reading within rendering code and relying on the console variable system for any modifications to its value.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/CapsuleShadowRendering.cpp:82

Scope: file

Source code excerpt:

float GCapsuleShadowFadeAngleFromVertical = PI / 3;
FAutoConsoleVariableRef CVarCapsuleShadowFadeAngleFromVertical(
	TEXT("r.CapsuleShadowFadeAngleFromVertical"),
	GCapsuleShadowFadeAngleFromVertical,
	TEXT("Angle from vertical up to start fading out the indirect shadow, to avoid self shadowing artifacts."),
	ECVF_Scalability | ECVF_RenderThreadSafe
	);

float GCapsuleIndirectConeAngle = PI / 8;

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/CapsuleShadowRendering.cpp:80

Scope: file

Source code excerpt:

	);

float GCapsuleShadowFadeAngleFromVertical = PI / 3;
FAutoConsoleVariableRef CVarCapsuleShadowFadeAngleFromVertical(
	TEXT("r.CapsuleShadowFadeAngleFromVertical"),
	GCapsuleShadowFadeAngleFromVertical,
	TEXT("Angle from vertical up to start fading out the indirect shadow, to avoid self shadowing artifacts."),
	ECVF_Scalability | ECVF_RenderThreadSafe
	);

float GCapsuleIndirectConeAngle = PI / 8;
FAutoConsoleVariableRef CVarCapsuleIndirectConeAngle(

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/CapsuleShadowRendering.cpp:456

Scope: file

Source code excerpt:

	Parameters.LightDirectionData = LightDirectionDataSRV;

	const float CosFadeStartAngleValue = FMath::Cos(GCapsuleShadowFadeAngleFromVertical);
	Parameters.CosFadeStartAngle = FVector2f(CosFadeStartAngleValue, 1.0f / (1.0f - CosFadeStartAngleValue));

	Parameters.DFObjectBufferParameters = DistanceField::SetupObjectBufferParameters(GraphBuilder, Scene->DistanceFieldSceneData);
	Parameters.DFAtlasParameters = DistanceField::SetupAtlasParameters(GraphBuilder, Scene->DistanceFieldSceneData);
}

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/CapsuleShadowRendering.cpp:755

Scope (from outer to inner):

file
function     static IndirectCapsuleShadowsResources CreateIndirectCapsuleShadowsResources

Source code excerpt:

	Output.IndirectShadowLightDirectionSRV = nullptr;

	const float CosFadeStartAngle = FMath::Cos(GCapsuleShadowFadeAngleFromVertical);
	const FSkyLightSceneProxy* SkyLight = Scene ? Scene->SkyLight : NULL;

	static TArray<FCapsuleShape3f> CapsuleShapeData;
	static TArray<FVector4f> CapsuleLightSourceData;
	static TArray<int32, TInlineAllocator<1>> MeshDistanceFieldCasterIndices;
	static TArray<FVector4f> DistanceFieldCasterLightSourceData;