r.VolumetricCloud.DistanceToSampleMaxCount
r.VolumetricCloud.DistanceToSampleMaxCount
#Overview
name: r.VolumetricCloud.DistanceToSampleMaxCount
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Distance in kilometers over which the total number of ray samples will be evenly distributed. Before that, the number of ray samples will span 1 to SampleCountMax, for for tracing distance ranging from 0 to DistanceToSampleCountMax (kilometers).
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.VolumetricCloud.DistanceToSampleMaxCount is to control the sampling distribution for volumetric cloud rendering in Unreal Engine 5. It defines the distance over which the maximum number of ray samples will be evenly distributed when rendering volumetric clouds.
This setting variable is primarily used by the rendering system, specifically the volumetric cloud rendering subsystem. It is part of the Renderer module in Unreal Engine 5.
The value of this variable is set as a console variable with a default value of 15.0f, representing 15 kilometers. It can be adjusted at runtime through the console or configuration files.
This variable interacts closely with other volumetric cloud rendering settings, particularly CVarVolumetricCloudSampleMinCount and CVarVolumetricCloudShadowViewRaySampleMaxCount. Together, these variables control the sampling strategy for cloud rendering.
Developers should be aware that this variable affects the balance between rendering quality and performance. A larger value will distribute samples over a greater distance, potentially improving far-field cloud detail at the cost of performance.
Best practices when using this variable include:
- Adjusting it in conjunction with other cloud rendering settings for optimal results.
- Testing different values to find the right balance between visual quality and performance for your specific scene.
- Consider scaling this value based on the overall scale of your environment.
The associated variable CVarVolumetricCloudDistanceToSampleMaxCount is actually the same variable, just referenced in different parts of the code. It’s used to retrieve the value in the rendering process, specifically in the InitVolumetricCloudsForViews function. This function sets up various parameters for volumetric cloud rendering, including the inverse of the distance to sample max count, which is used in shader calculations.
When working with this variable, developers should consider its impact on the entire cloud rendering pipeline and adjust related variables accordingly to achieve the desired visual result and performance.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VolumetricCloudRendering.cpp:40
Scope: file
Source code excerpt:
static TAutoConsoleVariable<float> CVarVolumetricCloudDistanceToSampleMaxCount(
TEXT("r.VolumetricCloud.DistanceToSampleMaxCount"), 15.0f,
TEXT("Distance in kilometers over which the total number of ray samples will be evenly distributed. Before that, the number of ray samples will span 1 to SampleCountMax, for for tracing distance ranging from 0 to DistanceToSampleCountMax (kilometers)."),
ECVF_RenderThreadSafe | ECVF_Scalability);
static TAutoConsoleVariable<int32> CVarVolumetricCloudSampleMinCount(
TEXT("r.VolumetricCloud.SampleMinCount"), 2,
TEXT("The minimum number of samples to take along a ray. This can help with quality for volume close to the camera, e.g. if cloud layer is also used as low altitude fog. SampleMinCount should remain relatively small because it is applied to all tracing process."),
#Associated Variable and Callsites
This variable is associated with another variable named CVarVolumetricCloudDistanceToSampleMaxCount
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VolumetricCloudRendering.cpp:39
Scope: file
Source code excerpt:
ECVF_RenderThreadSafe | ECVF_Scalability);
static TAutoConsoleVariable<float> CVarVolumetricCloudDistanceToSampleMaxCount(
TEXT("r.VolumetricCloud.DistanceToSampleMaxCount"), 15.0f,
TEXT("Distance in kilometers over which the total number of ray samples will be evenly distributed. Before that, the number of ray samples will span 1 to SampleCountMax, for for tracing distance ranging from 0 to DistanceToSampleCountMax (kilometers)."),
ECVF_RenderThreadSafe | ECVF_Scalability);
static TAutoConsoleVariable<int32> CVarVolumetricCloudSampleMinCount(
TEXT("r.VolumetricCloud.SampleMinCount"), 2,
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VolumetricCloudRendering.cpp:1616
Scope (from outer to inner):
file
function void FSceneRenderer::InitVolumetricCloudsForViews
Source code excerpt:
CloudGlobalShaderParams.ShadowSampleCountMax = FMath::Max(2.0f, FMath::Min(UVolumetricCloudComponent::BaseShadowRaySampleCount * CloudProxy.ShadowViewSampleCountScale, CVarVolumetricCloudShadowViewRaySampleMaxCount.GetValueOnAnyThread()));
CloudGlobalShaderParams.ShadowTracingMaxDistance = KilometersToCentimeters * FMath::Max(0.1f, CloudProxy.ShadowTracingDistance);
CloudGlobalShaderParams.InvDistanceToSampleCountMax = 1.0f / FMath::Max(1.0f, KilometersToCentimeters * CVarVolumetricCloudDistanceToSampleMaxCount.GetValueOnAnyThread());
CloudGlobalShaderParams.StopTracingTransmittanceThreshold = FMath::Clamp(CloudProxy.StopTracingTransmittanceThreshold, 0.0f, 1.0f);
auto PrepareCloudShadowMapLightData = [&](FLightSceneProxy* AtmosphericLight, int LightIndex)
{
const float CloudShadowmapResolution = float(GetVolumetricCloudShadowMapResolution(AtmosphericLight));
const float CloudShadowmapResolutionInv = 1.0f / CloudShadowmapResolution;