r.SkyAtmosphere.SampleLightShadowmap

r.SkyAtmosphere.SampleLightShadowmap

#Overview

name: r.SkyAtmosphere.SampleLightShadowmap

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

It is referenced in 5 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.SkyAtmosphere.SampleLightShadowmap is to enable the sampling of atmospheric lights shadow maps to produce volumetric shadows in the sky atmosphere rendering system.

This setting variable is primarily used in the Unreal Engine’s rendering system, specifically in the sky atmosphere and directional light components. It is relied upon by the SkyAtmosphere module and the DirectionalLight component.

The value of this variable is set through a console variable (CVar) system. It is initialized with a default value of 1, meaning it is enabled by default.

The associated variable CVarSkyAtmosphereSampleLightShadowmap interacts directly with r.SkyAtmosphere.SampleLightShadowmap. They share the same value and are used interchangeably in the code.

Developers must be aware that this variable affects the visual quality and performance of atmospheric rendering. When enabled, it allows for more realistic sky rendering with volumetric shadows, but it may also have performance implications.

Best practices when using this variable include:

  1. Consider the performance impact when enabling this feature, especially on lower-end hardware.
  2. Use it in conjunction with other sky atmosphere settings for the best visual results.
  3. Test the impact of enabling/disabling this feature in different lighting scenarios.

Regarding the associated variable CVarSkyAtmosphereSampleLightShadowmap:

The purpose of CVarSkyAtmosphereSampleLightShadowmap is the same as r.SkyAtmosphere.SampleLightShadowmap - to control the sampling of atmospheric lights shadow maps for volumetric shadows.

It is used in the same subsystems as r.SkyAtmosphere.SampleLightShadowmap, primarily in the rendering system and directional light component.

The value is set and accessed through the console variable system, allowing for runtime modification.

This variable directly interacts with r.SkyAtmosphere.SampleLightShadowmap, essentially serving as its in-code representation.

Developers should be aware that this variable is used in performance-critical rendering code, and its value can affect both visual quality and rendering performance.

Best practices include using this variable for conditional logic in rendering code, considering its performance implications, and ensuring consistency with other related rendering settings.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SkyAtmosphereRendering.cpp:65

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarSkyAtmosphereSampleLightShadowmap(
	TEXT("r.SkyAtmosphere.SampleLightShadowmap"), 1,
	TEXT("Enable the sampling of atmospheric lights shadow map in order to produce volumetric shadows."),
	ECVF_RenderThreadSafe | ECVF_Scalability);

////////////////////////////////////////////////////////////////////////// Fast sky

static TAutoConsoleVariable<int32> CVarSkyAtmosphereFastSkyLUT(

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/DirectionalLightComponent.cpp:952

Scope (from outer to inner):

file
class        class FDirectionalLightSceneProxy : public FLightSceneProxy
function     virtual FSphere GetShadowSplitBounds

Source code excerpt:


		// TODO: Move this into a flag in some shadow-system cofiguration struct and set based on this cvar outside setup.
		static const auto CVarSkyAtmosphereSampleLightShadowmap = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.SkyAtmosphere.SampleLightShadowmap"));

		// If enabled & this is the last cascade, then override the near plane used to construct the bounds using the
		// near plane of the first cacade (AKA the near plane of the view), to ensure the last cascade is inclusive.
		// We don't set any of the near/far planes etc as that would conflict with the fading.
		bool bUseNearOverride = (bCastShadowsOnClouds || bCastShadowsOnAtmosphere) 
			&& (ShadowSplitIndex + 1U) == NumNearAndFarCascades 

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Components/DirectionalLightComponent.cpp:952

Scope (from outer to inner):

file
class        class FDirectionalLightSceneProxy : public FLightSceneProxy
function     virtual FSphere GetShadowSplitBounds

Source code excerpt:


		// TODO: Move this into a flag in some shadow-system cofiguration struct and set based on this cvar outside setup.
		static const auto CVarSkyAtmosphereSampleLightShadowmap = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.SkyAtmosphere.SampleLightShadowmap"));

		// If enabled & this is the last cascade, then override the near plane used to construct the bounds using the
		// near plane of the first cacade (AKA the near plane of the view), to ensure the last cascade is inclusive.
		// We don't set any of the near/far planes etc as that would conflict with the fading.
		bool bUseNearOverride = (bCastShadowsOnClouds || bCastShadowsOnAtmosphere) 
			&& (ShadowSplitIndex + 1U) == NumNearAndFarCascades 
			&& CVarSkyAtmosphereSampleLightShadowmap && CVarSkyAtmosphereSampleLightShadowmap->GetValueOnAnyThread() != 0;
		
		const float BoundsCalcNear = bUseNearOverride ? GetSplitDistance(View, 0, bPrecomputedLightingIsValid, bIsRayTracedCascade) : SplitNear;
		const FSphere CascadeSphere = FDirectionalLightSceneProxy::GetShadowSplitBoundsDepthRange(View, View.ViewMatrices.GetViewOrigin(), BoundsCalcNear, SplitFar, OutCascadeSettings);

		return CascadeSphere;
	}

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SkyAtmosphereRendering.cpp:64

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe | ECVF_Scalability);

static TAutoConsoleVariable<int32> CVarSkyAtmosphereSampleLightShadowmap(
	TEXT("r.SkyAtmosphere.SampleLightShadowmap"), 1,
	TEXT("Enable the sampling of atmospheric lights shadow map in order to produce volumetric shadows."),
	ECVF_RenderThreadSafe | ECVF_Scalability);

////////////////////////////////////////////////////////////////////////// Fast sky

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SkyAtmosphereRendering.cpp:332

Scope (from outer to inner):

file
function     bool ShouldSkySampleAtmosphereLightsOpaqueShadow

Source code excerpt:

	}

	return CVarSkyAtmosphereSampleLightShadowmap.GetValueOnRenderThread() > 0 &&
		(LightShadowData.ProjectedShadowInfo0 || LightShadowData.ProjectedShadowInfo1 ||
		LightShadowData.VirtualShadowMapId0 != INDEX_NONE || LightShadowData.VirtualShadowMapId1 != INDEX_NONE);
}
void GetSkyAtmosphereLightsUniformBuffers(
	FRDGBuilder& GraphBuilder,
	TRDGUniformBufferRef<FVolumeShadowingShaderParametersGlobal0>& OutLightShadowShaderParams0UniformBuffer,