r.VolumetricFog.DepthDistributionScale

r.VolumetricFog.DepthDistributionScale

#Overview

name: r.VolumetricFog.DepthDistributionScale

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.VolumetricFog.DepthDistributionScale is to control the scaling of the slice depth distribution in the volumetric fog rendering system. This setting variable is crucial for fine-tuning the visual quality and performance of volumetric fog effects in Unreal Engine 5.

This setting variable is primarily used in the Renderer module, specifically within the volumetric fog rendering subsystem. Based on the callsites, it’s clear that this variable is an integral part of the volumetric fog implementation in Unreal Engine 5.

The value of this variable is set through the console variable system, as evidenced by the FAutoConsoleVariableRef declaration. It’s initialized with a default value of 32.0f but can be modified at runtime through console commands or project settings.

The associated variable GVolumetricFogDepthDistributionScale directly interacts with r.VolumetricFog.DepthDistributionScale. They share the same value, with GVolumetricFogDepthDistributionScale being the actual float variable used in the rendering calculations.

Developers must be aware that this variable affects the distribution of depth slices in the volumetric fog rendering. Modifying this value will impact both the visual quality and performance of the volumetric fog effect. A higher value will result in a more even distribution of slices throughout the depth range, potentially improving quality at the cost of performance.

Best practices when using this variable include:

  1. Experimenting with different values to find the optimal balance between visual quality and performance for your specific scene.
  2. Consider adjusting this value dynamically based on the scene complexity or distance from the camera.
  3. Be mindful of its impact on performance, especially on lower-end hardware.

Regarding the associated variable GVolumetricFogDepthDistributionScale:

The purpose of GVolumetricFogDepthDistributionScale is to provide a direct, efficient way for the rendering code to access the depth distribution scale value without going through the console variable system every time.

This variable is used directly in the volumetric fog rendering calculations, as seen in the provided code excerpt. It’s used to compute the spacing of depth slices in the volumetric fog grid.

The value of GVolumetricFogDepthDistributionScale is set through the console variable system, mirroring the value of r.VolumetricFog.DepthDistributionScale.

GVolumetricFogDepthDistributionScale interacts closely with other volumetric fog parameters, such as the near plane, far plane, and grid size.

Developers should be aware that modifying GVolumetricFogDepthDistributionScale directly in code is not recommended, as it may lead to inconsistencies with the console variable system. Always use the r.VolumetricFog.DepthDistributionScale console variable to modify this value.

Best practices for GVolumetricFogDepthDistributionScale include:

  1. Treat it as a read-only variable in most cases, using it for calculations but not modifying it directly.
  2. If you need to modify the value, do so through the console variable system to ensure consistency.
  3. Consider caching the value if it’s used frequently in performance-critical sections of code, as accessing console variables can have a small performance cost.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VolumetricFog.cpp:49

Scope: file

Source code excerpt:

float GVolumetricFogDepthDistributionScale = 32.0f;
FAutoConsoleVariableRef CVarVolumetricFogDepthDistributionScale(
	TEXT("r.VolumetricFog.DepthDistributionScale"),
	GVolumetricFogDepthDistributionScale,
	TEXT("Scales the slice depth distribution."),
	ECVF_Scalability | ECVF_RenderThreadSafe
	);

int32 GVolumetricFogGridPixelSize = 16;

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

	);

float GVolumetricFogDepthDistributionScale = 32.0f;
FAutoConsoleVariableRef CVarVolumetricFogDepthDistributionScale(
	TEXT("r.VolumetricFog.DepthDistributionScale"),
	GVolumetricFogDepthDistributionScale,
	TEXT("Scales the slice depth distribution."),
	ECVF_Scalability | ECVF_RenderThreadSafe
	);

int32 GVolumetricFogGridPixelSize = 16;
FAutoConsoleVariableRef CVarVolumetricFogGridPixelSize(

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VolumetricFog.cpp:1118

Scope (from outer to inner):

file
function     BEGIN_SHADER_PARAMETER_STRUCT

Source code excerpt:

	double NearOffset = .095 * 100.0;
	// Space out the slices so they aren't all clustered at the near plane
	double S = GVolumetricFogDepthDistributionScale;

	double N = NearPlane + NearOffset;
	double F = FarPlane;

	double O = (F - N * FMath::Exp2((GridSizeZ - 1) / S)) / (F - N);
	double B = (1 - O) / N;