r.VolumetricCloud.ViewRaySampleMaxCount
r.VolumetricCloud.ViewRaySampleMaxCount
#Overview
name: r.VolumetricCloud.ViewRaySampleMaxCount
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
The maximum number of samples taken while ray marching view primary rays.
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.VolumetricCloud.ViewRaySampleMaxCount is to control the maximum number of samples taken while ray marching view primary rays in volumetric cloud rendering. This setting is crucial for the rendering system, specifically for the volumetric cloud rendering feature in Unreal Engine 5.
The Unreal Engine subsystem that relies on this setting variable is the Renderer module, as evidenced by its location in the VolumetricCloudRendering.cpp file within the Runtime/Renderer/Private directory.
The value of this variable is set using a TAutoConsoleVariable, which means it can be adjusted at runtime through console commands. The default value is set to 768 samples.
This variable interacts with other variables in the volumetric cloud rendering system. For example, it’s used in conjunction with UVolumetricCloudComponent::BaseViewRaySampleCount and CloudProxy.ViewSampleCountScale to determine the final sample count.
Developers must be aware that this variable directly impacts the quality and performance of volumetric cloud rendering. A higher value will result in better quality but at the cost of performance, while a lower value will improve performance but may reduce visual quality.
Best practices when using this variable include:
- Balancing between visual quality and performance based on the target hardware.
- Adjusting it in conjunction with other related variables for optimal results.
- Testing different values to find the sweet spot for your specific scene and performance requirements.
Regarding the associated variable CVarVolumetricCloudViewRaySampleMaxCount:
This is the actual ConsoleVariable object that stores and manages the r.VolumetricCloud.ViewRaySampleMaxCount setting. It’s defined using TAutoConsoleVariable, which allows for runtime adjustments.
The purpose of this variable is the same as r.VolumetricCloud.ViewRaySampleMaxCount, as it’s the underlying implementation.
It’s used within the Renderer module, specifically in the InitVolumetricCloudsForViews function, to set the SampleCountMax parameter for volumetric cloud rendering.
The value is typically accessed using the GetValueOnAnyThread() method, which allows it to be read from any thread safely.
Developers should be aware that changes to this variable will take effect immediately, potentially causing visual changes during runtime.
Best practices include using this variable for real-time adjustments during development and performance tuning, and considering exposing it as a user-adjustable setting for different quality presets in the final game.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VolumetricCloudRendering.cpp:50
Scope: file
Source code excerpt:
static TAutoConsoleVariable<float> CVarVolumetricCloudViewRaySampleMaxCount(
TEXT("r.VolumetricCloud.ViewRaySampleMaxCount"), 768,
TEXT("The maximum number of samples taken while ray marching view primary rays."),
ECVF_RenderThreadSafe | ECVF_Scalability);
static TAutoConsoleVariable<float> CVarVolumetricCloudReflectionRaySampleMaxCount(
TEXT("r.VolumetricCloud.ReflectionRaySampleMaxCount"), 80,
TEXT("The maximum number of samples taken while ray marching primary rays in reflections."),
#Associated Variable and Callsites
This variable is associated with another variable named CVarVolumetricCloudViewRaySampleMaxCount
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VolumetricCloudRendering.cpp:49
Scope: file
Source code excerpt:
ECVF_RenderThreadSafe | ECVF_Scalability);
static TAutoConsoleVariable<float> CVarVolumetricCloudViewRaySampleMaxCount(
TEXT("r.VolumetricCloud.ViewRaySampleMaxCount"), 768,
TEXT("The maximum number of samples taken while ray marching view primary rays."),
ECVF_RenderThreadSafe | ECVF_Scalability);
static TAutoConsoleVariable<float> CVarVolumetricCloudReflectionRaySampleMaxCount(
TEXT("r.VolumetricCloud.ReflectionRaySampleMaxCount"), 80,
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VolumetricCloudRendering.cpp:1613
Scope (from outer to inner):
file
function void FSceneRenderer::InitVolumetricCloudsForViews
Source code excerpt:
CloudGlobalShaderParams.SampleCountMin = FMath::Max(0, CVarVolumetricCloudSampleMinCount.GetValueOnAnyThread());
CloudGlobalShaderParams.SampleCountMax = FMath::Max(2.0f, FMath::Min(UVolumetricCloudComponent::BaseViewRaySampleCount * CloudProxy.ViewSampleCountScale, CVarVolumetricCloudViewRaySampleMaxCount.GetValueOnAnyThread()));
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)