r.FastVRam.VelocityMax
r.FastVRam.VelocityMax
#Overview
name: r.FastVRam.VelocityMax
This variable is created as a Console Variable (cvar).
- type:
Var
- help: ``
It is referenced in 13
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.FastVRam.VelocityMax is to control the allocation of fast VRAM (video memory) for velocity maximum calculations in Unreal Engine’s rendering system. This setting is specifically related to motion blur and velocity-based rendering effects.
This variable is primarily used in the Renderer module of Unreal Engine. It’s referenced in the SceneRendering.cpp and SceneRendering.h files, which are core components of the rendering pipeline.
The value of this variable is set through the FASTVRAM_CVAR macro, which likely ties it to a console variable (CVar) that can be adjusted at runtime or through configuration files.
r.FastVRam.VelocityMax interacts with other FastVRam settings, such as VelocityFlat, MotionBlur, and others. These settings collectively control how different rendering components utilize fast VRAM.
Developers should be aware that this variable affects memory allocation for velocity calculations, which can impact performance and visual quality, especially in scenes with a lot of motion.
Best practices when using this variable include:
- Balancing it with other FastVRam settings to optimize overall rendering performance.
- Testing different values to find the right balance between visual quality and performance for your specific game or application.
- Considering the target hardware capabilities when adjusting this setting.
Regarding the associated variable VelocityMax:
The purpose of VelocityMax is to set the maximum velocity value used in various animation and rendering calculations, particularly for motion blur effects.
This variable is used in both the AnimGraphRuntime and Renderer modules. It’s referenced in functions related to velocity calculations from position history and in motion blur post-processing.
The value of VelocityMax is typically set as a parameter in function calls, often with a default value of 128.0f.
VelocityMax interacts closely with VelocityMin in normalization calculations. It’s also used in conjunction with viewport size to determine motion blur scatter requirements.
Developers should be aware that VelocityMax directly affects the intensity of motion blur and the range of detectable motion in animations. Setting it too low might result in clamped motion effects, while setting it too high might lead to exaggerated blur.
Best practices for using VelocityMax include:
- Adjusting it based on the scale and typical motion speed in your game world.
- Using it in conjunction with VelocityMin for proper normalization of velocity values.
- Testing different values to achieve the desired visual effect for motion blur and animation smoothness.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:478
Scope: file
Source code excerpt:
FASTVRAM_CVAR(HistogramReduce, 1);
FASTVRAM_CVAR(VelocityFlat, 1);
FASTVRAM_CVAR(VelocityMax, 1);
FASTVRAM_CVAR(MotionBlur, 1);
FASTVRAM_CVAR(Tonemap, 1);
FASTVRAM_CVAR(Upscale, 1);
FASTVRAM_CVAR(DistanceFieldNormal, 1);
FASTVRAM_CVAR(DistanceFieldAOHistory, 1);
FASTVRAM_CVAR(DistanceFieldAODownsampledBentNormal, 1);
#Associated Variable and Callsites
This variable is associated with another variable named VelocityMax
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/AnimGraphRuntime/Private/KismetAnimationLibrary.cpp:116
Scope (from outer to inner):
file
function float UKismetAnimationLibrary::K2_CalculateVelocityFromPositionHistory
Source code excerpt:
int32 NumberOfSamples,
float VelocityMin,
float VelocityMax
) {
NumberOfSamples = FMath::Max<uint32>(NumberOfSamples, 2);
if (DeltaSeconds <= 0.0f)
{
return 0.f;
}
#Loc: <Workspace>/Engine/Source/Runtime/AnimGraphRuntime/Private/KismetAnimationLibrary.cpp:176
Scope (from outer to inner):
file
function float UKismetAnimationLibrary::K2_CalculateVelocityFromPositionHistory
Source code excerpt:
LengthOfV /= float(History.Velocities.Num());
if (VelocityMin < 0.0f || VelocityMax < 0.0f || VelocityMax <= VelocityMin)
{
return LengthOfV;
}
// Avoids NaN due to the condition above.
return FMath::Clamp((LengthOfV - VelocityMin) / (VelocityMax - VelocityMin), 0.f, 1.f);
}
float UKismetAnimationLibrary::K2_CalculateVelocityFromSockets(
float DeltaSeconds,
USkeletalMeshComponent * Component,
const FName SocketOrBoneName,
#Loc: <Workspace>/Engine/Source/Runtime/AnimGraphRuntime/Private/KismetAnimationLibrary.cpp:195
Scope (from outer to inner):
file
function float UKismetAnimationLibrary::K2_CalculateVelocityFromSockets
Source code excerpt:
int32 NumberOfSamples,
float VelocityMin,
float VelocityMax,
EEasingFuncType EasingType,
const FRuntimeFloatCurve& CustomCurve
) {
if (Component && SocketOrBoneName != NAME_None)
{
FTransform SocketTransform = Component->GetSocketTransform(SocketOrBoneName, SocketSpace);
#Loc: <Workspace>/Engine/Source/Runtime/AnimGraphRuntime/Private/KismetAnimationLibrary.cpp:210
Scope (from outer to inner):
file
function float UKismetAnimationLibrary::K2_CalculateVelocityFromSockets
Source code excerpt:
FVector Position = SocketTransform.TransformPosition(OffsetInBoneSpace);
float Velocity = K2_CalculateVelocityFromPositionHistory(DeltaSeconds, Position, History, NumberOfSamples, VelocityMin, VelocityMax);
return CommonAnimationLibrary::ScalarEasing(Velocity, CustomCurve, EasingType);
}
return VelocityMin;
}
#Loc: <Workspace>/Engine/Source/Runtime/AnimGraphRuntime/Public/KismetAnimationLibrary.h:153
Scope (from outer to inner):
file
class class UKismetAnimationLibrary : public UBlueprintFunctionLibrary
Source code excerpt:
* @param NumberOfSamples The number of samples to use for the history. The higher the number of samples - the smoother the velocity changes.
* @param VelocityMin The minimum velocity to use for normalization (if both min and max are set to 0, normalization is turned off)
* @param VelocityMax The maximum velocity to use for normalization (if both min and max are set to 0, normalization is turned off)
*/
UFUNCTION(BlueprintCallable, Category = "Animation|Utilities", meta = (DisplayName = "Calculate Velocity From Position History", ScriptName = "CalculateVelocityFromPositionHistory", NumberOfSamples = "16", VelocityMin = "0.f", VelocityMax = "128.f"))
static ANIMGRAPHRUNTIME_API float K2_CalculateVelocityFromPositionHistory(
float DeltaSeconds,
FVector Position,
UPARAM(ref) FPositionHistory& History,
int32 NumberOfSamples,
float VelocityMin,
float VelocityMax
);
/**
* This function calculates the velocity of an offset position on a bone / socket over time.
* The bone's / socket's motion can be expressed within a reference frame (another bone / socket).
* You need to hook up a valid PositionHistory variable to this for storage.
*
#Loc: <Workspace>/Engine/Source/Runtime/AnimGraphRuntime/Public/KismetAnimationLibrary.h:179
Scope (from outer to inner):
file
class class UKismetAnimationLibrary : public UBlueprintFunctionLibrary
Source code excerpt:
* @param NumberOfSamples The number of samples to use for the history. The higher the number of samples - the smoother the velocity changes.
* @param VelocityMin The minimum velocity to use for normalization (if both min and max are set to 0, normalization is turned off)
* @param VelocityMax The maximum velocity to use for normalization (if both min and max are set to 0, normalization is turned off)
* @param EasingType The easing function to use
* @param CustomCurve The curve to use if the easing type is "Custom"
*/
UFUNCTION(BlueprintCallable, Category = "Animation|Utilities", meta = (NotBlueprintThreadSafe, DisplayName = "Calculate Velocity From Sockets", ScriptName = "CalculateVelocityFromSockets", NumberOfSamples = "16", VelocityMin = "0.f", VelocityMax = "128.f"))
static ANIMGRAPHRUNTIME_API float K2_CalculateVelocityFromSockets(
float DeltaSeconds,
USkeletalMeshComponent * Component,
const FName SocketOrBoneName,
const FName ReferenceSocketOrBone,
ERelativeTransformSpace SocketSpace,
FVector OffsetInBoneSpace,
UPARAM(ref) FPositionHistory& History,
int32 NumberOfSamples,
float VelocityMin,
float VelocityMax,
EEasingFuncType EasingType,
const FRuntimeFloatCurve& CustomCurve
);
/**
* This function starts measuring the time for a profiling bracket
*/
UFUNCTION(BlueprintCallable, Category = "Animation|Utilities", meta = (DisplayName = "Start Profiling Timer"))
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessMotionBlur.cpp:133
Scope (from outer to inner):
file
function bool IsMotionBlurScatterRequired
Source code excerpt:
// Normalize percentage value.
const float VelocityMax = View.FinalPostProcessSettings.MotionBlurMax / 100.0f;
// Scale by 0.5 due to blur samples going both ways and convert to tiles.
const float VelocityMaxInTiles = VelocityMax * ViewportWidth * (0.5f / 16.0f);
// Compute path only supports the immediate neighborhood of tiles.
const float TileDistanceMaxGathered = 3.0f;
// Scatter is used when maximum velocity exceeds the distance supported by the gather approach.
const bool bIsScatterRequiredByVelocityLength = VelocityMaxInTiles > TileDistanceMaxGathered;
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessMotionBlur.cpp:586
Scope (from outer to inner):
file
class class FMotionBlurVelocityFlattenCS : public FMotionBlurShader
Source code excerpt:
VelocityFlattenParameters.VelocityScale.X = SceneViewportSizeX * 0.5f * VelocityScale;
VelocityFlattenParameters.VelocityScale.Y = -SceneViewportSizeY * 0.5f * VelocityScale;
VelocityFlattenParameters.VelocityMax = SceneViewportSizeX * 0.5f * UVVelocityMax;
return VelocityFlattenParameters;
}
void AddMotionBlurVelocityPass(
FRDGBuilder& GraphBuilder,
const FViewInfo& View,
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessMotionBlur.h:47
Scope: file
Source code excerpt:
BEGIN_SHADER_PARAMETER_STRUCT(FVelocityFlattenParameters, )
SHADER_PARAMETER(FVector2f, VelocityScale)
SHADER_PARAMETER(float, VelocityMax)
END_SHADER_PARAMETER_STRUCT()
FVelocityFlattenParameters GetVelocityFlattenParameters(const FViewInfo& View);
// Textures generated by the velocity flattening pass.
struct FVelocityFlattenTextures
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:478
Scope: file
Source code excerpt:
FASTVRAM_CVAR(HistogramReduce, 1);
FASTVRAM_CVAR(VelocityFlat, 1);
FASTVRAM_CVAR(VelocityMax, 1);
FASTVRAM_CVAR(MotionBlur, 1);
FASTVRAM_CVAR(Tonemap, 1);
FASTVRAM_CVAR(Upscale, 1);
FASTVRAM_CVAR(DistanceFieldNormal, 1);
FASTVRAM_CVAR(DistanceFieldAOHistory, 1);
FASTVRAM_CVAR(DistanceFieldAODownsampledBentNormal, 1);
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:678
Scope (from outer to inner):
file
function void FFastVramConfig::Update
Source code excerpt:
bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_HistogramReduce, HistogramReduce);
bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_VelocityFlat, VelocityFlat);
bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_VelocityMax, VelocityMax);
bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_MotionBlur, MotionBlur);
bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_Tonemap, Tonemap);
bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_Upscale, Upscale);
bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_DistanceFieldNormal, DistanceFieldNormal);
bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_DistanceFieldAOHistory, DistanceFieldAOHistory);
bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_DistanceFieldAODownsampledBentNormal, DistanceFieldAODownsampledBentNormal);
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.h:2827
Scope: file
Source code excerpt:
ETextureCreateFlags HistogramReduce;
ETextureCreateFlags VelocityFlat;
ETextureCreateFlags VelocityMax;
ETextureCreateFlags MotionBlur;
ETextureCreateFlags Tonemap;
ETextureCreateFlags Upscale;
ETextureCreateFlags DistanceFieldNormal;
ETextureCreateFlags DistanceFieldAOHistory;
ETextureCreateFlags DistanceFieldAOBentNormal;