r.HairStrands.Visibility.NonVisibleShadowCasting.CullDistance

r.HairStrands.Visibility.NonVisibleShadowCasting.CullDistance

#Overview

name: r.HairStrands.Visibility.NonVisibleShadowCasting.CullDistance

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.HairStrands.Visibility.NonVisibleShadowCasting.CullDistance is to control the cull distance at which shadow casting starts to be disabled for non-visible hair strands instances in Unreal Engine 5’s rendering system.

This setting variable is primarily used by the Hair Strands rendering subsystem within Unreal Engine 5’s renderer module. It specifically affects the visibility and shadow casting behavior of hair strands that are not directly visible to the camera.

The value of this variable is set using a console variable (CVar) system. It is initialized with a default value of 2000 units, but can be changed at runtime through console commands or programmatically.

The associated variable CVarHairStrandsNonVisibleShadowCasting_CullDistance interacts directly with this setting. It’s the actual TAutoConsoleVariable object that holds and manages the value of the r.HairStrands.Visibility.NonVisibleShadowCasting.CullDistance setting.

Developers must be aware that this variable affects performance and visual quality. A larger value will allow non-visible hair strands to cast shadows from further away, potentially increasing rendering cost but improving shadow consistency. A smaller value will cull shadow casting for non-visible hair strands earlier, potentially improving performance at the cost of some shadow detail.

Best practices when using this variable include:

  1. Adjusting it based on the specific needs of your scene and target hardware.
  2. Testing with various values to find the optimal balance between performance and visual quality.
  3. Considering the scale of your game world when setting this value.

Regarding the associated variable CVarHairStrandsNonVisibleShadowCasting_CullDistance:

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/HairStrands/HairStrandsInterface.cpp:58

Scope: file

Source code excerpt:


static TAutoConsoleVariable<float> CVarHairStrandsNonVisibleShadowCasting_CullDistance(
	TEXT("r.HairStrands.Visibility.NonVisibleShadowCasting.CullDistance"), 2000,
	TEXT("Cull distance at which shadow casting starts to be disabled for non-visible hair strands instances."),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarHairStrandsNonVisibleShadowCasting_Debug(
	TEXT("r.HairStrands.Visibility.NonVisibleShadowCasting.Debug"), 0,
	TEXT("Enable debug rendering for non-visible hair strands instance, casting shadow."),

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/HairStrands/HairStrandsInterface.cpp:57

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<float> CVarHairStrandsNonVisibleShadowCasting_CullDistance(
	TEXT("r.HairStrands.Visibility.NonVisibleShadowCasting.CullDistance"), 2000,
	TEXT("Cull distance at which shadow casting starts to be disabled for non-visible hair strands instances."),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarHairStrandsNonVisibleShadowCasting_Debug(
	TEXT("r.HairStrands.Visibility.NonVisibleShadowCasting.Debug"), 0,

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/HairStrands/HairStrandsInterface.cpp:270

Scope (from outer to inner):

file
function     bool IsHairStrandsVisibleInShadows

Source code excerpt:

			if (!bIsVisibleInShadow)
			{
				const float CullDistance = FMath::Max(0.f, CVarHairStrandsNonVisibleShadowCasting_CullDistance.GetValueOnAnyThread());
				for (const FHairStrandsViewData::FDirectionalLightCullData& CullData : View.HairStrandsViewData.VisibleShadowCastingDirectionalLights)
				{
					// Transform frustum into light space
					const FMatrix& WorldToLight = CullData.LightInfo->Proxy->GetWorldToLight();
					
					// Transform groom bound into light space, and extend it along the light direction