r.VolumetricCloud.SampleMinCount

r.VolumetricCloud.SampleMinCount

#Overview

name: r.VolumetricCloud.SampleMinCount

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.VolumetricCloud.SampleMinCount is to control the minimum number of samples taken along a ray when rendering volumetric clouds in Unreal Engine 5. This setting is part of the rendering system, specifically for volumetric cloud rendering.

This setting variable is used in the Renderer module of Unreal Engine 5, particularly in the volumetric cloud rendering subsystem. It’s defined and used in the VolumetricCloudRendering.cpp file.

The value of this variable is set using a console variable (CVar) system. It’s initialized with a default value of 2, but can be changed at runtime through console commands or project settings.

This variable interacts with other cloud rendering settings, particularly CVarVolumetricCloudViewRaySampleMaxCount, which sets the maximum number of samples. Together, these variables define the range of samples used in cloud rendering.

Developers must be aware that increasing this value can improve the quality of volumetric clouds, especially for volumes close to the camera. However, it should be kept relatively small because it’s applied to all tracing processes, which could impact performance if set too high.

Best practices when using this variable include:

  1. Keep the value relatively low to maintain performance.
  2. Adjust it in conjunction with other cloud rendering settings for optimal results.
  3. Consider using it to improve quality when using cloud layers as low-altitude fog.
  4. Test thoroughly to find the right balance between quality and performance for your specific use case.

Regarding the associated variable CVarVolumetricCloudSampleMinCount:

This is the actual console variable that controls the r.VolumetricCloud.SampleMinCount setting. It’s defined as a TAutoConsoleVariable, which means it’s an integer value that can be changed at runtime.

The purpose of this variable is the same as r.VolumetricCloud.SampleMinCount - to set the minimum number of samples for volumetric cloud rendering.

It’s used in the InitVolumetricCloudsForViews function to set the SampleCountMin parameter for cloud rendering. The value is clamped to be at least 0 using FMath::Max(0, CVarVolumetricCloudSampleMinCount.GetValueOnAnyThread()).

Developers should be aware that this variable can be accessed and modified from any thread, as indicated by the GetValueOnAnyThread() method. This means changes to this value can potentially affect rendering in real-time.

Best practices for using this variable include:

  1. Use it in conjunction with other cloud rendering settings for optimal results.
  2. Consider exposing it in your game’s graphics settings if you want to give users fine-grained control over cloud quality.
  3. Profile your game’s performance with different values to find the optimal setting for your specific use case.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VolumetricCloudRendering.cpp:45

Scope: file

Source code excerpt:


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."),
	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."),

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VolumetricCloudRendering.cpp:44

Scope: file

Source code excerpt:

	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."),
	ECVF_RenderThreadSafe | ECVF_Scalability);

static TAutoConsoleVariable<float> CVarVolumetricCloudViewRaySampleMaxCount(
	TEXT("r.VolumetricCloud.ViewRaySampleMaxCount"), 768,

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VolumetricCloudRendering.cpp:1612

Scope (from outer to inner):

file
function     void FSceneRenderer::InitVolumetricCloudsForViews

Source code excerpt:

			CloudGlobalShaderParams.TracingMaxDistanceMode				= CloudProxy.TracingMaxDistanceMode;

			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);