sg.ShadingQuality

sg.ShadingQuality

#Overview

name: sg.ShadingQuality

The value of this variable can be defined or overridden in .ini config files. 1 .ini config file referencing this setting variable.

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

It is referenced in 10 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of sg.ShadingQuality is to control the quality level of shading in the Unreal Engine 5 rendering system. This setting is part of the scalability system, which allows developers to adjust various quality settings to optimize performance across different hardware configurations.

The Unreal Engine subsystem that primarily relies on this setting variable is the rendering system, specifically the scalability system. It’s also used in the MovieRenderPipeline plugin for high-quality rendering in cinematics.

The value of this variable is set through several methods:

  1. It can be set via console commands or ini files, as indicated by the ECVF_ScalabilityGroup flag.
  2. It’s loaded from and saved to configuration files in the Scalability namespace functions LoadState and SaveState.
  3. It can be set programmatically through the SetQualityLevels function in the Scalability namespace.
  4. In the Lyra project, it can be set based on device profiles.

The sg.ShadingQuality variable interacts with other scalability settings like EffectsQuality, FoliageQuality, and LandscapeQuality. They are often set and adjusted together as part of the overall quality settings.

Developers should be aware that:

  1. The variable uses integer values from 0 to 4, representing low, medium, high, epic, and cinematic quality levels respectively.
  2. Changes to this variable trigger a callback (OnChangeShadingQuality) which likely updates the rendering system.
  3. In some cases, like in the MovieRenderPipeline, it might be forcibly set to the highest quality (4) for cinematic rendering.

Best practices when using this variable include:

  1. Consider the target hardware when setting this value, as higher quality shading can be performance-intensive.
  2. Use it in conjunction with other scalability settings for a balanced approach to performance and visual quality.
  3. Test thoroughly across different hardware configurations to ensure a good balance between visual quality and performance.

Regarding the associated variable CVarShadingQuality:

CVarShadingQuality is the actual console variable that controls the sg.ShadingQuality setting. It’s defined using TAutoConsoleVariable, which allows it to be easily accessed and modified through the console or code.

The purpose of CVarShadingQuality is the same as sg.ShadingQuality - to control the shading quality level. It’s used internally by the engine to actually implement the functionality of sg.ShadingQuality.

CVarShadingQuality is used in the Scalability namespace functions to get and set the shading quality level. It has an OnChangedCallback set up, which likely triggers the necessary updates in the rendering system when the value changes.

When working with shading quality, developers can interact with either sg.ShadingQuality or CVarShadingQuality, depending on whether they’re working through the console/config files or directly in C++ code.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/BaseDeviceProfiles.ini:892, section: [Android_Vulkan_SM5 DeviceProfile]

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Scalability.cpp:101

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarShadingQuality(
	TEXT("sg.ShadingQuality"),
	Scalability::DefaultQualityLevel,
	TEXT("Scalability quality state (internally used by scalability system, ini load/save or using SCALABILITY console command)\n")
	TEXT(" 0:low, 1:med, 2:high, 3:epic, 4:cinematic, default: 3"),
	ECVF_ScalabilityGroup | ECVF_Preview);

static TAutoConsoleVariable<int32> CVarLandscapeQuality(

#Loc: <Workspace>/Engine/Plugins/MovieScene/MovieRenderPipeline/Source/MovieRenderPipelineCore/Private/Graph/Nodes/MovieGraphGlobalGameOverrides.cpp:39

Scope (from outer to inner):

file
function     void UMovieGraphGlobalGameOverridesNode::BuildNewProcessCommandLineArgsImpl

Source code excerpt:

		InOutDeviceProfileCvars.Add(FString::Format(TEXT("sg.EffectsQuality={0}"), {QualityLevels.EffectsQuality}));
		InOutDeviceProfileCvars.Add(FString::Format(TEXT("sg.FoliageQuality={0}"), {QualityLevels.FoliageQuality}));
		InOutDeviceProfileCvars.Add(FString::Format(TEXT("sg.ShadingQuality={0}"), {QualityLevels.ShadingQuality}));
		InOutDeviceProfileCvars.Add(FString::Format(TEXT("sg.LandscapeQuality={0}"), {QualityLevels.LandscapeQuality}));
	}

	if (bDisableTextureStreaming)
	{
		InOutDeviceProfileCvars.Add(TEXT("r.TextureStreaming=0"));

#Loc: <Workspace>/Engine/Plugins/MovieScene/MovieRenderPipeline/Source/MovieRenderPipelineCore/Private/MoviePipelineGameOverrideSetting.cpp:171

Scope (from outer to inner):

file
function     void UMoviePipelineGameOverrideSetting::BuildNewProcessCommandLineArgsImpl

Source code excerpt:

		InOutDeviceProfileCvars.Add(TEXT("sg.EffectsQuality=4"));
		InOutDeviceProfileCvars.Add(TEXT("sg.FoliageQuality=4"));
		InOutDeviceProfileCvars.Add(TEXT("sg.ShadingQuality=4"));
	}

	switch (TextureStreaming)
	{
	case EMoviePipelineTextureStreamingMethod::FullyLoad:
		InOutDeviceProfileCvars.Add(TEXT("r.Streaming.FramesForFullUpdate=0"));

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Scalability.cpp:1137

Scope (from outer to inner):

file
namespace    Scalability
function     void LoadState

Source code excerpt:

	GConfig->GetInt(Section, TEXT("sg.EffectsQuality"), State.EffectsQuality, IniName);
	GConfig->GetInt(Section, TEXT("sg.FoliageQuality"), State.FoliageQuality, IniName);
	GConfig->GetInt(Section, TEXT("sg.ShadingQuality"), State.ShadingQuality, IniName);
	GConfig->GetInt(Section, TEXT("sg.LandscapeQuality"), State.LandscapeQuality, IniName);

	// If possible apply immediately, else store in backup so we can re-apply later
	if (!GScalabilityUsingTemporaryQualityLevels)
	{
		SetQualityLevels(State);

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Scalability.cpp:1171

Scope (from outer to inner):

file
namespace    Scalability
function     void SaveState

Source code excerpt:

	GConfig->SetInt(Section, TEXT("sg.EffectsQuality"), State.EffectsQuality, IniName);
	GConfig->SetInt(Section, TEXT("sg.FoliageQuality"), State.FoliageQuality, IniName);
	GConfig->SetInt(Section, TEXT("sg.ShadingQuality"), State.ShadingQuality, IniName);
	GConfig->SetInt(Section, TEXT("sg.LandscapeQuality"), State.LandscapeQuality, IniName);
}

void RecordQualityLevelsAnalytics(bool bAutoApplied)
{
	if( FEngineAnalytics::IsAvailable() )

#Loc: <Workspace>/Projects/Lyra/Source/LyraGame/Settings/LyraSettingsLocal.cpp:277

Scope (from outer to inner):

file
namespace    LyraSettingsHelpers
function     void FillScalabilitySettingsFromDeviceProfile

Source code excerpt:

		Mode.bHasOverrides |= UDeviceProfileManager::GetScalabilityCVar(FString::Printf(TEXT("sg.EffectsQuality%s"), *Suffix), Mode.Qualities.EffectsQuality);
		Mode.bHasOverrides |= UDeviceProfileManager::GetScalabilityCVar(FString::Printf(TEXT("sg.FoliageQuality%s"), *Suffix), Mode.Qualities.FoliageQuality);
		Mode.bHasOverrides |= UDeviceProfileManager::GetScalabilityCVar(FString::Printf(TEXT("sg.ShadingQuality%s"), *Suffix), Mode.Qualities.ShadingQuality);
	}

	TMobileQualityWrapper<int32> OverallQualityLimits(-1, CVarMobileQualityLimits);
	TMobileQualityWrapper<float> ResolutionQualityLimits(100.0f, CVarMobileResolutionQualityLimits);
	TMobileQualityWrapper<float> ResolutionQualityRecommendations(75.0f, CVarMobileResolutionQualityRecommendation);

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Scalability.cpp:100

Scope: file

Source code excerpt:

	ECVF_ScalabilityGroup | ECVF_Preview);

static TAutoConsoleVariable<int32> CVarShadingQuality(
	TEXT("sg.ShadingQuality"),
	Scalability::DefaultQualityLevel,
	TEXT("Scalability quality state (internally used by scalability system, ini load/save or using SCALABILITY console command)\n")
	TEXT(" 0:low, 1:med, 2:high, 3:epic, 4:cinematic, default: 3"),
	ECVF_ScalabilityGroup | ECVF_Preview);

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Scalability.cpp:594

Scope (from outer to inner):

file
namespace    Scalability
function     void InitScalabilitySystem

Source code excerpt:

	CVarEffectsQuality.AsVariable()->SetOnChangedCallback(FConsoleVariableDelegate::CreateStatic(&OnChangeEffectsQuality));
	CVarFoliageQuality.AsVariable()->SetOnChangedCallback(FConsoleVariableDelegate::CreateStatic(&OnChangeFoliageQuality));
	CVarShadingQuality.AsVariable()->SetOnChangedCallback(FConsoleVariableDelegate::CreateStatic(&OnChangeShadingQuality));
	CVarLandscapeQuality.AsVariable()->SetOnChangedCallback(FConsoleVariableDelegate::CreateStatic(&OnChangeLandscapeQuality));

#if WITH_EDITOR
	ScalabilityShaderPlatform = GMaxRHIShaderPlatform;
	bScalabilityShaderPlatformHasBeenChanged = false;
#endif

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Scalability.cpp:896

Scope (from outer to inner):

file
namespace    Scalability
function     void SetQualityLevels

Source code excerpt:

		SetQualityLevelCVar(CVarEffectsQuality, ClampedLevels.EffectsQuality, GScalabilityQualityLevelsOverride.EffectsQuality, bForce);
		SetQualityLevelCVar(CVarFoliageQuality, ClampedLevels.FoliageQuality, GScalabilityQualityLevelsOverride.FoliageQuality, bForce);
		SetQualityLevelCVar(CVarShadingQuality, ClampedLevels.ShadingQuality, GScalabilityQualityLevelsOverride.ShadingQuality, bForce);
		SetQualityLevelCVar(CVarLandscapeQuality, ClampedLevels.LandscapeQuality, GScalabilityQualityLevelsOverride.LandscapeQuality, bForce);

		OnScalabilitySettingsChanged.Broadcast(ClampedLevels);
	}

#if WITH_EDITOR

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Scalability.cpp:928

Scope (from outer to inner):

file
namespace    Scalability
function     FQualityLevels GetQualityLevels

Source code excerpt:

		Ret.EffectsQuality = CVarEffectsQuality.GetValueOnGameThread();
		Ret.FoliageQuality = CVarFoliageQuality.GetValueOnGameThread();
		Ret.ShadingQuality = CVarShadingQuality.GetValueOnGameThread();
		Ret.LandscapeQuality = CVarLandscapeQuality.GetValueOnGameThread();
	}
	else
	{
		Ret = GScalabilityBackupQualityLevels;
	}