r.VolumetricCloud.EnableLocalLightsSampling

r.VolumetricCloud.EnableLocalLightsSampling

#Overview

name: r.VolumetricCloud.EnableLocalLightsSampling

This variable is created as a Console Variable (cvar).

It is referenced in 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.VolumetricCloud.EnableLocalLightsSampling is to control the contribution of local lights on volumetric clouds in Unreal Engine 5’s rendering system. This setting is specifically designed for the volumetric cloud rendering subsystem.

The Unreal Engine subsystem that relies on this setting variable is the Renderer module, particularly the volumetric cloud rendering component. This can be seen from the file location where the variable is defined and used: Engine/Source/Runtime/Renderer/Private/VolumetricCloudRendering.cpp.

The value of this variable is set as a console variable using TAutoConsoleVariable. It is initialized with a default value of 0, meaning it’s disabled by default. Developers can change this value at runtime through the console or configuration files.

This variable interacts closely with other volumetric cloud rendering settings, particularly CVarVolumetricCloudLocalLightsShadowSampleCount, which determines the shadow sample count for local lights when evaluating their contribution to clouds.

Developers must be aware that this feature is marked as EXPERIMENTAL and is described as expensive in terms of performance. The comment suggests it should be used for cinematics if needed, implying it’s not suitable for general real-time rendering scenarios.

Best practices when using this variable include:

  1. Only enable it when necessary, particularly for high-quality cinematic renders.
  2. Be aware of the performance impact and test thoroughly in your specific use case.
  3. Consider adjusting related settings like CVarVolumetricCloudLocalLightsShadowSampleCount for optimal results.
  4. Use in conjunction with other volumetric cloud settings for the best visual outcome.

Regarding the associated variable CVarVolumetricCloudEnableLocalLightsSampling:

This is the actual console variable that controls the setting. It’s an integer variable that determines whether local lights sampling for volumetric clouds is enabled (when set to a value greater than 0) or disabled (when set to 0).

The purpose of this variable is to provide a runtime-configurable way to toggle the local lights sampling feature for volumetric clouds. It’s used in functions like VolumetricCloudWantsToSampleLocalLights to determine if the feature should be active.

This variable is crucial for the renderer to decide whether to perform the expensive local light sampling calculations for volumetric clouds. It’s checked in the main cloud rendering function (RenderVolumetricCloudsInternal) to determine if the feature should be applied during the rendering process.

Developers should be cautious when enabling this feature due to its performance impact. It’s recommended to use it judiciously, primarily for high-quality offline renders or carefully optimized cinematic scenes where the visual improvement justifies the performance cost.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarVolumetricCloudEnableLocalLightsSampling(
	TEXT("r.VolumetricCloud.EnableLocalLightsSampling"), 0,
	TEXT("[EXPERIMENTAL] Enable/disable local lights contribution on clouds. Expenssive! Use for cinematics if needed."),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<float> CVarVolumetricCloudLocalLightsShadowSampleCount(
	TEXT("r.VolumetricCloud.LocalLights.ShadowSampleCount"), 12,
	TEXT("[EXPERIMENTAL] Set the volumetric shadow sample count when evaluating local lights. Expenssive! Use for cinematics if needed."),

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarVolumetricCloudEnableLocalLightsSampling(
	TEXT("r.VolumetricCloud.EnableLocalLightsSampling"), 0,
	TEXT("[EXPERIMENTAL] Enable/disable local lights contribution on clouds. Expenssive! Use for cinematics if needed."),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<float> CVarVolumetricCloudLocalLightsShadowSampleCount(
	TEXT("r.VolumetricCloud.LocalLights.ShadowSampleCount"), 12,

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

Scope (from outer to inner):

file
function     bool VolumetricCloudWantsToSampleLocalLights

Source code excerpt:

bool VolumetricCloudWantsToSampleLocalLights(const FScene* Scene, const FEngineShowFlags& EngineShowFlags)
{
	return ShouldRenderVolumetricCloud(Scene, EngineShowFlags) && CVarVolumetricCloudEnableLocalLightsSampling.GetValueOnRenderThread();
}

static bool ShouldRenderCloudShadowmap(const FLightSceneProxy* AtmosphericLight)
{
	return CVarVolumetricCloudShadowMap.GetValueOnRenderThread() > 0 && AtmosphericLight && AtmosphericLight->GetCastCloudShadows();
}

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

Scope (from outer to inner):

file
function     void FSceneRenderer::RenderVolumetricCloudsInternal

Source code excerpt:

	TRDGUniformBufferRef<FRenderVolumetricCloudGlobalParameters> CloudPassUniformBuffer = CreateCloudPassUniformBuffer(GraphBuilder, CloudRC);

	const bool bCloudEnableLocalLightSampling = CVarVolumetricCloudEnableLocalLightsSampling.GetValueOnRenderThread() > 0;
	if (ShouldUseComputeForCloudTracing(Scene->GetFeatureLevel()))
	{
		//
		// Cloud empty space skipping
		// TODO: add support for reflection rendering without breaking compute work item overlap for each faces.
		//