r.FastVRam.DistanceFieldAOBentNormal
r.FastVRam.DistanceFieldAOBentNormal
#Overview
name: r.FastVRam.DistanceFieldAOBentNormal
This variable is created as a Console Variable (cvar).
- type:
Var
- help: ``
It is referenced in 15
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.FastVRam.DistanceFieldAOBentNormal is to control the memory allocation and usage for the Distance Field Ambient Occlusion (DFAO) bent normal texture in Unreal Engine’s rendering system. This setting is part of the Fast VRAM configuration, which allows for optimizing memory usage for various rendering components.
The r.FastVRam.DistanceFieldAOBentNormal variable is primarily used in the rendering subsystem, specifically in the Distance Field Ambient Occlusion module. It affects how the engine allocates memory for the bent normal texture used in DFAO calculations.
The value of this variable is set through a console variable (CVar) system, as seen in the FASTVRAM_CVAR macro usage. By default, it is set to 0, which means no special Fast VRAM flags are applied to the texture.
This variable interacts closely with other Distance Field-related variables, such as r.FastVRam.DistanceFieldAOHistory and r.FastVRam.DistanceFieldAODownsampledBentNormal. These variables work together to optimize memory usage for the entire DFAO system.
Developers should be aware that changing this variable can affect memory allocation and potentially impact performance. It’s important to profile and test any changes to ensure they provide the desired optimization without negatively affecting rendering quality or performance.
Best practices when using this variable include:
- Only modify it if you have a clear understanding of your project’s memory requirements and DFAO usage.
- Test thoroughly after making changes to ensure no visual artifacts or performance regressions occur.
- Consider the interaction with other Fast VRAM settings and DFAO-related variables.
- Monitor memory usage and performance metrics when adjusting this setting.
Regarding the associated variable DistanceFieldAOBentNormal, it is used throughout the codebase to reference the actual texture or render target for the DFAO bent normal data. This texture is crucial for storing and accessing the bent normal information used in DFAO calculations and final rendering.
The DistanceFieldAOBentNormal texture is created, accessed, and passed around in various rendering functions, particularly in the DistanceFieldAmbientOcclusion and DistanceFieldLightingPost modules. It’s used in conjunction with other DFAO-related textures and parameters to compute and apply ambient occlusion effects in the scene.
When working with DistanceFieldAOBentNormal, developers should:
- Ensure proper allocation and deallocation of the texture resource.
- Be mindful of its resolution and format, as it can impact both quality and performance.
- Consider how it interacts with other parts of the rendering pipeline, such as upsampling and history buffers for temporal stability.
- Optimize access patterns to this texture to maintain good performance, especially on different hardware configurations.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:485
Scope: file
Source code excerpt:
FASTVRAM_CVAR(DistanceFieldAOHistory, 1);
FASTVRAM_CVAR(DistanceFieldAODownsampledBentNormal, 1);
FASTVRAM_CVAR(DistanceFieldAOBentNormal, 0);
FASTVRAM_CVAR(DistanceFieldIrradiance, 0);
FASTVRAM_CVAR(DistanceFieldShadows, 1);
FASTVRAM_CVAR(Distortion, 1);
FASTVRAM_CVAR(ScreenSpaceShadowMask, 1);
FASTVRAM_CVAR(VolumetricFog, 1);
FASTVRAM_CVAR(SeparateTranslucency, 0);
#Associated Variable and Callsites
This variable is associated with another variable named DistanceFieldAOBentNormal
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistanceFieldAmbientOcclusion.cpp:277
Scope (from outer to inner):
file
function FDFAOUpsampleParameters DistanceField::SetupAOUpsampleParameters
Source code excerpt:
}
FDFAOUpsampleParameters DistanceField::SetupAOUpsampleParameters(const FViewInfo& View, FRDGTextureRef DistanceFieldAOBentNormal)
{
const float DistanceFadeScaleValue = 1.0f / ((1.0f - GAOViewFadeDistanceScale) * GetMaxAOViewDistance());
const FIntPoint AOBufferSize = GetBufferSizeForAO(View);
const FIntPoint AOViewSize = View.ViewRect.Size() / GAODownsampleFactor;
const FVector2f UVMax(
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistanceFieldAmbientOcclusion.cpp:288
Scope (from outer to inner):
file
function FDFAOUpsampleParameters DistanceField::SetupAOUpsampleParameters
Source code excerpt:
FDFAOUpsampleParameters ShaderParameters;
ShaderParameters.BentNormalAOTexture = DistanceFieldAOBentNormal;
ShaderParameters.BentNormalAOSampler = TStaticSamplerState<SF_Bilinear>::GetRHI();
ShaderParameters.AOBufferBilinearUVMax = UVMax;
ShaderParameters.DistanceFadeScale = DistanceFadeScaleValue;
ShaderParameters.AOMaxViewDistance = GetMaxAOViewDistance();
return ShaderParameters;
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistanceFieldAmbientOcclusion.h:98
Scope (from outer to inner):
file
namespace DistanceField
Source code excerpt:
{
FAOParameters SetupAOShaderParameters(const FDistanceFieldAOParameters& AOParameters);
FDFAOUpsampleParameters SetupAOUpsampleParameters(const FViewInfo& View, FRDGTextureRef DistanceFieldAOBentNormal);
};
extern void TrackGPUProgress(FRHICommandListImmediate& RHICmdList, uint32 DebugId);
extern bool ShouldRenderDeferredDynamicSkyLight(const FScene* Scene, const FSceneViewFamily& ViewFamily);
extern bool ShouldDoReflectionEnvironment(const FScene* Scene, const FSceneViewFamily& ViewFamily);
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistanceFieldLightingPost.cpp:86
Scope (from outer to inner):
file
function FGeometryAwareUpsampleParameters SetupGeometryAwareUpsampleParameters
Source code excerpt:
END_SHADER_PARAMETER_STRUCT()
FGeometryAwareUpsampleParameters SetupGeometryAwareUpsampleParameters(const FViewInfo& View, FRDGTextureRef DistanceFieldNormal, FRDGTextureRef DistanceFieldAOBentNormal)
{
extern FVector2f GetJitterOffset(const FViewInfo& View);
FVector2f const JitterOffsetValue = GetJitterOffset(View);
const FIntPoint DownsampledBufferSize = GetBufferSizeForAO(View);
const FVector2f BaseLevelTexelSizeValue(1.0f / DownsampledBufferSize.X, 1.0f / DownsampledBufferSize.Y);
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistanceFieldLightingPost.cpp:106
Scope (from outer to inner):
file
function FGeometryAwareUpsampleParameters SetupGeometryAwareUpsampleParameters
Source code excerpt:
ShaderParameters.DistanceFieldNormalTexture = DistanceFieldNormal;
ShaderParameters.DistanceFieldNormalSampler = TStaticSamplerState<SF_Point, AM_Clamp, AM_Clamp, AM_Clamp>::GetRHI();
ShaderParameters.BentNormalAOTexture = DistanceFieldAOBentNormal;
ShaderParameters.BentNormalAOSampler = TStaticSamplerState<SF_Bilinear, AM_Clamp, AM_Clamp, AM_Clamp>::GetRHI();
ShaderParameters.UVToScreenPos = FScreenTransform::ChangeTextureBasisFromTo(FScreenPassTextureViewport(DownsampledBufferSize, AOViewRect), FScreenTransform::ETextureBasis::TextureUV, FScreenTransform::ETextureBasis::ScreenPosition);
ShaderParameters.BentNormalBufferAndTexelSize = BentNormalBufferAndTexelSizeValue;
ShaderParameters.DistanceFieldGBufferTexelSize = BaseLevelTexelSizeValue;
ShaderParameters.DistanceFieldGBufferJitterOffset = BaseLevelTexelSizeValue * JitterOffsetValue;
ShaderParameters.JitterOffset = JitterOffsetValue;
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistanceFieldLightingPost.cpp:224
Scope (from outer to inner):
file
function void GeometryAwareUpsample
Source code excerpt:
}
void GeometryAwareUpsample(FRDGBuilder& GraphBuilder, const FViewInfo& View, FRDGTextureRef DistanceFieldAOBentNormal, FRDGTextureRef DistanceFieldNormal, FRDGTextureRef BentNormalInterpolation, const FDistanceFieldAOParameters& Parameters)
{
auto* PassParameters = GraphBuilder.AllocParameters<FGeometryAwareUpsamplePS::FParameters>();
PassParameters->View = View.ViewUniformBuffer;
PassParameters->AOParameters = DistanceField::SetupAOShaderParameters(Parameters);
PassParameters->GeometryAwareUpsampleParameters = SetupGeometryAwareUpsampleParameters(View, DistanceFieldNormal, BentNormalInterpolation);
PassParameters->RenderTargets[0] = FRenderTargetBinding(DistanceFieldAOBentNormal, ERenderTargetLoadAction::ELoad);
auto VertexShader = View.ShaderMap->GetShader<FPostProcessVS>();
auto PixelShader = View.ShaderMap->GetShader<FGeometryAwareUpsamplePS>();
ClearUnusedGraphResources(PixelShader, PassParameters);
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistanceFieldLightingPost.cpp:503
Scope (from outer to inner):
file
function void UpdateHistory
Source code excerpt:
{
// Use the current frame's upscaled mask for next frame's history
FRDGTextureRef DistanceFieldAOBentNormal = nullptr;
AllocateOrReuseAORenderTarget(GraphBuilder, View, DistanceFieldAOBentNormal, TEXT("PerViewDistanceFieldBentNormalAO"), PF_FloatRGBA, GFastVRamConfig.DistanceFieldAOHistory);
GeometryAwareUpsample(GraphBuilder, View, DistanceFieldAOBentNormal, DistanceFieldNormal, BentNormalInterpolation, Parameters);
GraphBuilder.QueueTextureExtraction(DistanceFieldAOBentNormal, BentNormalHistoryState);
BentNormalHistoryOutput = DistanceFieldAOBentNormal;
}
DistanceFieldAOHistoryViewRect->Min = FIntPoint::ZeroValue;
DistanceFieldAOHistoryViewRect->Max = View.ViewRect.Size() / FIntPoint(GAODownsampleFactor, GAODownsampleFactor);
}
else
{
// Temporal reprojection is disabled or there is no view state - just upscale
FRDGTextureRef DistanceFieldAOBentNormal = nullptr;
AllocateOrReuseAORenderTarget(GraphBuilder, View, DistanceFieldAOBentNormal, TEXT("PerViewDistanceFieldBentNormalAO"), PF_FloatRGBA, GFastVRamConfig.DistanceFieldAOHistory);
GeometryAwareUpsample(GraphBuilder, View, DistanceFieldAOBentNormal, DistanceFieldNormal, BentNormalInterpolation, Parameters);
BentNormalHistoryOutput = DistanceFieldAOBentNormal;
}
}
class FDistanceFieldAOUpsamplePS : public FGlobalShader
{
public:
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistanceFieldLightingPost.cpp:558
Scope (from outer to inner):
file
function void UpsampleBentNormalAO
Source code excerpt:
TRDGUniformBufferRef<FSceneTextureUniformParameters> SceneTexturesUniformBuffer,
FRDGTextureRef SceneColorTexture,
FRDGTextureRef DistanceFieldAOBentNormal,
bool bModulateSceneColor)
{
FScene* Scene = (FScene*)View.Family->Scene;
RDG_GPU_MASK_SCOPE(GraphBuilder, View.GPUMask);
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistanceFieldLightingPost.cpp:568
Scope (from outer to inner):
file
function void UpsampleBentNormalAO
Source code excerpt:
PassParameters->View = View.ViewUniformBuffer;
PassParameters->SceneTextures = SceneTexturesUniformBuffer;
PassParameters->DFAOUpsampleParameters = DistanceField::SetupAOUpsampleParameters(View, DistanceFieldAOBentNormal ? DistanceFieldAOBentNormal : GSystemTextures.GetWhiteDummy(GraphBuilder));
PassParameters->MinIndirectDiffuseOcclusion = Scene->SkyLight ? Scene->SkyLight->MinOcclusion : 0;
PassParameters->RenderTargets[0] = FRenderTargetBinding(SceneColorTexture, ERenderTargetLoadAction::ELoad);
PassParameters->DistanceFieldAOBentNormal = DistanceFieldAOBentNormal;
TShaderMapRef<FPostProcessVS> VertexShader(View.ShaderMap);
FDistanceFieldAOUpsamplePS::FPermutationDomain PermutationVector;
PermutationVector.Set<FDistanceFieldAOUpsamplePS::FModulateToSceneColorDim>(bModulateSceneColor);
TShaderMapRef<FDistanceFieldAOUpsamplePS> PixelShader(View.ShaderMap, PermutationVector);
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistanceFieldLightingPost.cpp:583
Scope (from outer to inner):
file
function void UpsampleBentNormalAO
lambda-function
Source code excerpt:
PassParameters,
ERDGPassFlags::Raster,
[VertexShader, PixelShader, PassParameters, &View, DistanceFieldAOBentNormal, bModulateSceneColor](FRHICommandList& RHICmdList)
{
RHICmdList.SetViewport(View.ViewRect.Min.X, View.ViewRect.Min.Y, 0.0f, View.ViewRect.Max.X, View.ViewRect.Max.Y, 1.0f);
FGraphicsPipelineStateInitializer GraphicsPSOInit;
RHICmdList.ApplyCachedRenderTargets(GraphicsPSOInit);
GraphicsPSOInit.RasterizerState = TStaticRasterizerState<FM_Solid, CM_None>::GetRHI();
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DistanceFieldLightingPost.h:33
Scope: file
Source code excerpt:
TRDGUniformBufferRef<FSceneTextureUniformParameters> SceneTexturesUniformBuffer,
FRDGTextureRef SceneColorTexture,
FRDGTextureRef DistanceFieldAOBentNormal,
bool bModulateSceneColor);
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:485
Scope: file
Source code excerpt:
FASTVRAM_CVAR(DistanceFieldAOHistory, 1);
FASTVRAM_CVAR(DistanceFieldAODownsampledBentNormal, 1);
FASTVRAM_CVAR(DistanceFieldAOBentNormal, 0);
FASTVRAM_CVAR(DistanceFieldIrradiance, 0);
FASTVRAM_CVAR(DistanceFieldShadows, 1);
FASTVRAM_CVAR(Distortion, 1);
FASTVRAM_CVAR(ScreenSpaceShadowMask, 1);
FASTVRAM_CVAR(VolumetricFog, 1);
FASTVRAM_CVAR(SeparateTranslucency, 0);
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:685
Scope (from outer to inner):
file
function void FFastVramConfig::Update
Source code excerpt:
bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_DistanceFieldAOHistory, DistanceFieldAOHistory);
bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_DistanceFieldAODownsampledBentNormal, DistanceFieldAODownsampledBentNormal);
bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_DistanceFieldAOBentNormal, DistanceFieldAOBentNormal);
bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_DistanceFieldIrradiance, DistanceFieldIrradiance);
bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_DistanceFieldShadows, DistanceFieldShadows);
bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_Distortion, Distortion);
bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_ScreenSpaceShadowMask, ScreenSpaceShadowMask);
bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_VolumetricFog, VolumetricFog);
bDirty |= UpdateTextureFlagFromCVar(CVarFastVRam_SeparateTranslucency, SeparateTranslucency);
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.h:2833
Scope: file
Source code excerpt:
ETextureCreateFlags DistanceFieldNormal;
ETextureCreateFlags DistanceFieldAOHistory;
ETextureCreateFlags DistanceFieldAOBentNormal;
ETextureCreateFlags DistanceFieldAODownsampledBentNormal;
ETextureCreateFlags DistanceFieldShadows;
ETextureCreateFlags DistanceFieldIrradiance;
ETextureCreateFlags DistanceFieldAOConfidence;
ETextureCreateFlags Distortion;
ETextureCreateFlags ScreenSpaceShadowMask;