r.SSProfilesSamplingChannelSelection

r.SSProfilesSamplingChannelSelection

#Overview

name: r.SSProfilesSamplingChannelSelection

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.SSProfilesSamplingChannelSelection is to control the sampling channel selection method for subsurface scattering profiles in Unreal Engine’s rendering system. It specifically affects how the engine chooses the sampling channel for subsurface scattering calculations.

This setting variable is primarily used in the rendering subsystem of Unreal Engine, particularly in the subsurface scattering profile functionality. Based on the callsites, it’s implemented in the Engine module, specifically in the SubsurfaceProfile.cpp file.

The value of this variable is set through a console variable (CVarSSProfilesSamplingChannelSelection) with a default value of 1. It can be changed at runtime using console commands or through code.

The associated variable CVarSSProfilesSamplingChannelSelection directly interacts with r.SSProfilesSamplingChannelSelection. They share the same value and purpose.

Developers must be aware that this variable affects the performance and visual quality of subsurface scattering effects. It has two possible values: 0: Selects the sampling channel based on maximum Diffuse Mean Free Path (DMFP) 1: Selects the sampling channel based on maximum Mean Free Path (MFP)

Best practices when using this variable include:

  1. Understanding the visual differences between the two sampling methods and choosing the one that best suits the project’s needs.
  2. Considering performance implications, as the calculation method may affect render times.
  3. Testing both options in various lighting conditions to ensure consistent quality across different scenarios.

Regarding the associated variable CVarSSProfilesSamplingChannelSelection:

The purpose of CVarSSProfilesSamplingChannelSelection is to provide a programmatic way to access and modify the r.SSProfilesSamplingChannelSelection setting within the engine’s C++ code.

This variable is used in the Engine module, specifically in the subsurface scattering profile calculations.

The value of CVarSSProfilesSamplingChannelSelection is set when the engine initializes the console variable system. It can be modified at runtime using console commands or through C++ code.

CVarSSProfilesSamplingChannelSelection directly interacts with r.SSProfilesSamplingChannelSelection, as they represent the same setting.

Developers should be aware that changes to CVarSSProfilesSamplingChannelSelection will immediately affect the subsurface scattering calculations in the render thread.

Best practices for using CVarSSProfilesSamplingChannelSelection include:

  1. Using GetValueOnAnyThread() when accessing the value, as shown in the provided code snippet.
  2. Clamping the value between 0 and 1 when using it in calculations to ensure valid input.
  3. Consider caching the value if it’s accessed frequently, to avoid potential performance overhead from repeated console variable lookups.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Rendering/SubsurfaceProfile.cpp:21

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarSSProfilesSamplingChannelSelection(
	TEXT("r.SSProfilesSamplingChannelSelection"),
	1,
	TEXT("0. Select the sampling channel based on max DMFP.\n")
	TEXT("1. based on max MFP."),
	ECVF_RenderThreadSafe
);

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Rendering/SubsurfaceProfile.cpp:20

Scope: file

Source code excerpt:

);

static TAutoConsoleVariable<int32> CVarSSProfilesSamplingChannelSelection(
	TEXT("r.SSProfilesSamplingChannelSelection"),
	1,
	TEXT("0. Select the sampling channel based on max DMFP.\n")
	TEXT("1. based on max MFP."),
	ECVF_RenderThreadSafe
);

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Rendering/SubsurfaceProfile.cpp:407

Scope (from outer to inner):

file
function     void SetupSurfaceAlbedoAndDiffuseMeanFreePath

Source code excerpt:

void SetupSurfaceAlbedoAndDiffuseMeanFreePath(FLinearColor& SurfaceAlbedo, FLinearColor& Dmfp)
{
	int32 SamplingSelectionMethod = FMath::Clamp(CVarSSProfilesSamplingChannelSelection.GetValueOnAnyThread(), 0, 1);
	FLinearColor Distance = SamplingSelectionMethod == 0 ?
		Dmfp															// 0: by max diffuse mean free path
		: GetMeanFreePathFromDiffuseMeanFreePath(SurfaceAlbedo, Dmfp);	// 1: by max mean free path
	//Store the value that corresponds to the largest Dmfp (diffuse mean free path) channel to A channel.
	//This is an optimization to shift finding the max correspondence workload
	//to CPU.