r.HairStrands.Shadow.CastShadowWhenNonVisible

r.HairStrands.Shadow.CastShadowWhenNonVisible

#Overview

name: r.HairStrands.Shadow.CastShadowWhenNonVisible

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.Shadow.CastShadowWhenNonVisible is to control shadow casting for hair strands in the Unreal Engine 5 rendering system, specifically when the hair strands are culled out from the primary view.

This setting variable is primarily used in the hair strands rendering subsystem within Unreal Engine 5. It’s part of the advanced rendering features for realistic hair simulation and rendering.

The value of this variable is set through a console variable (CVar) system in Unreal Engine. It’s initialized with a default value of 1, meaning shadow casting for non-visible hair strands is enabled by default.

This variable interacts closely with another variable named CVarHairStrandsNonVisibleShadowCasting_CullDistance, which sets the distance at which shadow casting starts to be disabled for non-visible hair strands instances.

Developers should be aware that this variable can significantly impact rendering performance, especially in scenes with many hair strand instances. Enabling shadow casting for non-visible hair strands can increase shadow map complexity and rendering time.

Best practices when using this variable include:

  1. Carefully balancing visual quality and performance.
  2. Considering disabling this feature for lower-end hardware or mobile platforms.
  3. Adjusting the cull distance (using the associated CullDistance variable) to optimize performance while maintaining visual quality.

Regarding the associated variable CVarHairStrandsNonVisibleShadowCasting:

The purpose of CVarHairStrandsNonVisibleShadowCasting is to serve as the internal representation of the r.HairStrands.Shadow.CastShadowWhenNonVisible setting within the engine’s code.

This variable is used directly in the rendering subsystem to determine whether non-visible hair strands should cast shadows. It’s referenced in the IsHairStrandsNonVisibleShadowCastingEnable() function, which likely controls the behavior of the shadow casting system for hair strands.

The value of this variable is set through the console variable system, just like r.HairStrands.Shadow.CastShadowWhenNonVisible.

It interacts with other hair strand rendering variables, particularly those related to culling and visibility.

Developers should be aware that this is the actual variable used in the code logic, so any runtime changes to r.HairStrands.Shadow.CastShadowWhenNonVisible will affect this variable.

Best practices include using the provided functions (like IsHairStrandsNonVisibleShadowCastingEnable()) to check the state of this setting rather than accessing the variable directly, as this allows for better encapsulation and potential future optimizations.

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

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarHairStrandsNonVisibleShadowCasting(
	TEXT("r.HairStrands.Shadow.CastShadowWhenNonVisible"), 1,
	TEXT("Enable shadow casting for hair strands even when culled out from the primary view"),
	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."),

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe | ECVF_Scalability);

static TAutoConsoleVariable<int32> CVarHairStrandsNonVisibleShadowCasting(
	TEXT("r.HairStrands.Shadow.CastShadowWhenNonVisible"), 1,
	TEXT("Enable shadow casting for hair strands even when culled out from the primary view"),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<float> CVarHairStrandsNonVisibleShadowCasting_CullDistance(
	TEXT("r.HairStrands.Visibility.NonVisibleShadowCasting.CullDistance"), 2000,

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

Scope (from outer to inner):

file
function     bool IsHairStrandsNonVisibleShadowCastingEnable

Source code excerpt:

bool IsHairStrandsNonVisibleShadowCastingEnable()
{
	return CVarHairStrandsNonVisibleShadowCasting.GetValueOnAnyThread() > 0;
}

bool IsHairStrandsVisibleInShadows(const FViewInfo& View, const FHairStrandsInstance& Instance)
{
	const bool bDebugEnable = CVarHairStrandsNonVisibleShadowCasting_Debug.GetValueOnRenderThread() > 0;
	FHairStrandsDebugData::FCullData* CullingData = nullptr;