r.RayTracing.Shadows.EnableHairVoxel

r.RayTracing.Shadows.EnableHairVoxel

#Overview

name: r.RayTracing.Shadows.EnableHairVoxel

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.RayTracing.Shadows.EnableHairVoxel is to control the use of hair voxel data for ray-traced shadow calculations in Unreal Engine 5’s rendering system. This setting variable is specifically related to the ray tracing subsystem and its interaction with hair rendering.

The Unreal Engine subsystem that relies on this setting variable is the Ray Tracing module, specifically the part responsible for shadow calculations. It is used in the RayTracingShadows.cpp file, which is part of the Renderer module.

The value of this variable is set using a console variable (CVarRayTracingShadowsEnableHairVoxel) with a default value of 1, meaning it’s enabled by default. It can be changed at runtime through console commands or programmatically.

This variable interacts with other hair rendering-related variables, specifically those controlling hair deep shadows. The code checks both this variable and the hair deep shadow setting to determine how to render hair shadows.

Developers must be aware that this variable affects the performance and quality of ray-traced shadows for hair. Enabling it (value > 0) allows the use of hair voxel data for shadow calculations, which can potentially improve the accuracy of hair shadows at the cost of performance.

Best practices when using this variable include:

  1. Testing performance with and without hair voxel shadows enabled to find the best balance for your specific use case.
  2. Considering disabling it for lower-end hardware configurations to improve performance.
  3. Using it in conjunction with other hair rendering settings for the best visual results.

Regarding the associated variable CVarRayTracingShadowsEnableHairVoxel:

This is the actual console variable that controls the r.RayTracing.Shadows.EnableHairVoxel setting. It’s defined as a TAutoConsoleVariable, which means it’s an integer value that can be changed at runtime.

The purpose of CVarRayTracingShadowsEnableHairVoxel is to provide a way to toggle the hair voxel shadow feature on and off dynamically, without requiring a engine restart or recompilation.

This variable is used directly in the ray tracing shadow code to determine whether to use hair voxel data. It’s checked using the GetValueOnRenderThread() method, ensuring thread-safe access to its value.

Developers should be aware that changes to this variable will take effect immediately on the render thread. They should also note that the variable is marked as ECVF_RenderThreadSafe, meaning it’s safe to modify from any thread, but the changes will only be applied on the render thread.

Best practices for using CVarRayTracingShadowsEnableHairVoxel include:

  1. Using it for debugging or performance testing scenarios where you need to toggle hair voxel shadows on and off quickly.
  2. Considering exposing it as a user-configurable option in graphics settings menus for advanced users.
  3. Monitoring its performance impact in various scenarios to make informed decisions about when to enable or disable it.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarRayTracingShadowsEnableHairVoxel(
	TEXT("r.RayTracing.Shadows.EnableHairVoxel"),
	1,
	TEXT("Enables use of hair voxel data for tracing shadow (default = 1)"),
	ECVF_RenderThreadSafe
);

static TAutoConsoleVariable<int32> CVarRayTracingShadowsLODTransitionStart(

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/RayTracing/RayTracingShadows.cpp:81

Scope: file

Source code excerpt:

);

static TAutoConsoleVariable<int32> CVarRayTracingShadowsEnableHairVoxel(
	TEXT("r.RayTracing.Shadows.EnableHairVoxel"),
	1,
	TEXT("Enables use of hair voxel data for tracing shadow (default = 1)"),
	ECVF_RenderThreadSafe
);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/RayTracing/RayTracingShadows.cpp:433

Scope: file

Source code excerpt:

		if (bUseHairLighting)
		{
			const bool bUseHairVoxel = CVarRayTracingShadowsEnableHairVoxel.GetValueOnRenderThread() > 0;
			CommonPassParameters->bUseHairVoxel = !bUseHairDeepShadow && bUseHairVoxel ? 1 : 0;
			CommonPassParameters->HairLightChannelMaskTexture = View.HairStrandsViewData.VisibilityData.LightChannelMaskTexture;
			CommonPassParameters->HairStrands = HairStrands::BindHairStrandsViewUniformParameters(View);
			CommonPassParameters->VirtualVoxel = HairStrands::BindHairStrandsVoxelUniformParameters(View);

			if (ShaderPrint::IsValid(View.ShaderPrintData))