r.HairStrands.VelocityMagnitudeScale

r.HairStrands.VelocityMagnitudeScale

#Overview

name: r.HairStrands.VelocityMagnitudeScale

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.VelocityMagnitudeScale is to control the velocity magnitude at which a hair will reach its peak velocity-rasterization-scale under motion to reduce aliasing in hair rendering. This setting is part of Unreal Engine 5’s hair strands rendering system.

This setting variable is primarily used in the Renderer module, specifically within the HairStrands subsystem. It’s referenced in the HairStrandsVisibility.cpp file, which is responsible for handling the visibility of hair strands during rendering.

The value of this variable is set through a console variable (CVarHairVelocityMagnitudeScale) with a default value of 100. This value can be changed at runtime through console commands or programmatically.

The associated variable CVarHairVelocityMagnitudeScale interacts directly with r.HairStrands.VelocityMagnitudeScale, as they share the same value. This console variable is used to retrieve the current value of the setting in the C++ code.

Developers should be aware that this variable affects the visual quality of hair rendering, particularly during motion. The value represents the velocity magnitude in pixels at which a hair strand will reach its peak velocity-rasterization-scale. A higher value may result in less aliasing but could potentially impact performance.

Best practices when using this variable include:

  1. Tuning the value based on the specific requirements of your game or application.
  2. Testing with different motion intensities to find the optimal balance between visual quality and performance.
  3. Considering the target hardware capabilities when adjusting this value.

Regarding the associated variable CVarHairVelocityMagnitudeScale:

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/HairStrands/HairStrandsVisibility.cpp:47

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarHairVelocityMagnitudeScale(
	TEXT("r.HairStrands.VelocityMagnitudeScale"),
	100,  // Tuned by eye, based on heavy motion (strong head shack)
	TEXT("Velocity magnitude (in pixel) at which a hair will reach its pic velocity-rasterization-scale under motion to reduce aliasing. Default is 100."));

static int32 GHairVelocityType = 1; // default is 
static FAutoConsoleVariableRef CVarHairVelocityType(TEXT("r.HairStrands.VelocityType"), GHairVelocityType, TEXT("Type of velocity filtering (0:avg, 1:closest, 2:max). Default is 1."));

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/HairStrands/HairStrandsVisibility.cpp:46

Scope: file

Source code excerpt:

static FAutoConsoleVariableRef CVarHairClearVisibilityBuffer(TEXT("r.HairStrands.Visibility.Clear"), GHairClearVisibilityBuffer, TEXT("Clear hair strands visibility buffer"));

static TAutoConsoleVariable<int32> CVarHairVelocityMagnitudeScale(
	TEXT("r.HairStrands.VelocityMagnitudeScale"),
	100,  // Tuned by eye, based on heavy motion (strong head shack)
	TEXT("Velocity magnitude (in pixel) at which a hair will reach its pic velocity-rasterization-scale under motion to reduce aliasing. Default is 100."));

static int32 GHairVelocityType = 1; // default is 
static FAutoConsoleVariableRef CVarHairVelocityType(TEXT("r.HairStrands.VelocityType"), GHairVelocityType, TEXT("Type of velocity filtering (0:avg, 1:closest, 2:max). Default is 1."));

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/HairStrands/HairStrandsVisibility.cpp:296

Scope (from outer to inner):

file
function     void SetUpViewHairRenderInfo

Source code excerpt:

{
	FVector2f PixelVelocity(1.f / (ViewInfo.ViewRect.Width() * 2), 1.f / (ViewInfo.ViewRect.Height() * 2));
	const float VelocityMagnitudeScale = FMath::Clamp(CVarHairVelocityMagnitudeScale.GetValueOnAnyThread(), 0, 512) * FMath::Min(PixelVelocity.X, PixelVelocity.Y);

	// In the case we render coverage, we need to override some view uniform shader parameters to account for the change in MSAA sample count.
	const uint32 HairVisibilitySampleCount = bEnableMSAA ? GetMaxSamplePerPixel(ViewInfo.GetShaderPlatform()) : 1;	// The coverage pass does not use MSAA
	const float RasterizationScaleOverride = 0.0f;	// no override
	FMinHairRadiusAtDepth1 MinHairRadius = ComputeMinStrandRadiusAtDepth1(
		FIntPoint(ViewInfo.UnconstrainedViewRect.Width(), ViewInfo.UnconstrainedViewRect.Height()), ViewInfo.FOV, HairVisibilitySampleCount, RasterizationScaleOverride, ViewInfo.ViewMatrices.GetOrthoDimensions().X);