r.Tonemapper.Sharpen

r.Tonemapper.Sharpen

#Overview

name: r.Tonemapper.Sharpen

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.Tonemapper.Sharpen is to control the sharpening effect in the tonemapper post-processing stage of Unreal Engine’s rendering pipeline. This setting is specifically for non-mobile platforms and affects the final image quality by enhancing edge contrast.

This setting variable is primarily used in the Renderer module of Unreal Engine, specifically in the post-processing and tonemapping subsystems. It’s referenced in the following files:

  1. PostProcessTonemap.cpp
  2. AutomationBlueprintFunctionLibrary.cpp
  3. VisualizeTemporalUpscaler.cpp

The value of this variable is set through the console variable system. It can be set programmatically or through the console, and it’s also possible to inherit the value from PostProcessVolume settings.

The associated variable CVarTonemapperSharpen interacts directly with r.Tonemapper.Sharpen. They share the same value and purpose, with CVarTonemapperSharpen being the actual console variable implementation.

Developers should be aware of the following when using this variable:

  1. The value is clamped between 0 and 10.
  2. Negative values (-1 by default) mean the setting will be inherited from PostProcessVolume settings.
  3. A value of 0 turns off the sharpening effect.
  4. Values between 0 and 1 represent fractional strength (e.g., 0.5 for half strength).
  5. Values above 1 increase the sharpening intensity.

Best practices for using this variable include:

  1. Use it judiciously, as excessive sharpening can introduce artifacts.
  2. Consider the target platform and performance impact when enabling this feature.
  3. Test different values to find the right balance between image sharpness and overall visual quality.
  4. Use PostProcessVolume settings for more fine-grained control in specific areas of your game world.

Regarding the associated variable CVarTonemapperSharpen: The purpose of CVarTonemapperSharpen is to provide a programmatic interface for controlling the tonemapper sharpening effect. It’s implemented as a TAutoConsoleVariable, which allows it to be adjusted at runtime through the console or code.

CVarTonemapperSharpen is used in the Renderer module, specifically in the tonemapping post-process pass. It’s defined and used in PostProcessTonemap.cpp.

The value of CVarTonemapperSharpen is set through the console variable system, either programmatically or via the console command “r.Tonemapper.Sharpen”.

CVarTonemapperSharpen interacts directly with the r.Tonemapper.Sharpen setting, as they represent the same value. The GetSharpenSetting function in PostProcessTonemap.cpp uses CVarTonemapperSharpen to determine the final sharpening value.

Developers should be aware that changes to CVarTonemapperSharpen will immediately affect the rendering output, and the same considerations apply as with r.Tonemapper.Sharpen.

Best practices for CVarTonemapperSharpen include using it for runtime adjustments of the sharpening effect, such as in response to player settings or for debugging purposes.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessTonemap.cpp:34

Scope (from outer to inner):

file
namespace    anonymous

Source code excerpt:

{
TAutoConsoleVariable<float> CVarTonemapperSharpen(
	TEXT("r.Tonemapper.Sharpen"),
	-1,
	TEXT("Sharpening in the tonemapper (not for mobile), actual implementation is work in progress, clamped at 10\n")
	TEXT("  <0: inherit from PostProcessVolume settings (default)\n")
	TEXT("   0: off\n")
	TEXT(" 0.5: half strength\n")
	TEXT("   1: full strength"),

#Loc: <Workspace>/Engine/Source/Developer/FunctionalTesting/Private/AutomationBlueprintFunctionLibrary.cpp:247

Scope (from outer to inner):

file
function     FAutomationTestScreenshotEnvSetup::FAutomationTestScreenshotEnvSetup

Source code excerpt:

	, ContactShadows(TEXT("r.ContactShadows"))
	, TonemapperGamma(TEXT("r.TonemapperGamma"))
	, TonemapperSharpen(TEXT("r.Tonemapper.Sharpen"))
	, ScreenPercentage(TEXT("r.ScreenPercentage"))
	, DynamicResTestScreenPercentage(TEXT("r.DynamicRes.TestScreenPercentage"))
	, DynamicResOperationMode(TEXT("r.DynamicRes.OperationMode"))
	, SecondaryScreenPercentage(TEXT("r.SecondaryScreenPercentage.GameViewport"))
{
}

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/VisualizeTemporalUpscaler.cpp:318

Scope (from outer to inner):

file
function     FScreenPassTexture AddVisualizeTemporalUpscalerPass
lambda-function

Source code excerpt:

			// Display if any additional sharpening is happening
			{
				static auto CVarSharpen = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Tonemapper.Sharpen"));
				check(CVarSharpen);
				float Sharpen = CVarSharpen->GetFloat();
				Sharpen = (Sharpen < 0) ? View.FinalPostProcessSettings.Sharpen : Sharpen;
				QuickDrawSummary(/* Location = */ 6, Sharpen > 0 ? FString::Printf(TEXT("Tonemapper Sharpen: %f"), Sharpen) : TEXT("Tonemapper Sharpen: Off"));
			}

		});

	}
	else
	{
		check(Inputs.TAAConfig == EMainTAAPassConfig::Disabled);
		AddDrawCanvasPass(GraphBuilder, RDG_EVENT_NAME("VisualizeTemporalUpscaler Text"), View, FScreenPassRenderTarget(Output, ERenderTargetLoadAction::ELoad),
			[&ViewRect = Output.ViewRect](FCanvas& Canvas)
			{
				const float DPIScale = Canvas.GetDPIScale();
				Canvas.SetBaseTransform(FMatrix(FScaleMatrix(DPIScale) * Canvas.CalcBaseTransform2D(Canvas.GetViewRect().Width(), Canvas.GetViewRect().Height())));

				FIntPoint LabelLocation(60, 60);
				Canvas.DrawShadowedString(LabelLocation.X / DPIScale, LabelLocation.Y / DPIScale, TEXT("No temporal upscaler used"), GetStatsFont(), FLinearColor::Red);
			});
	}

	return MoveTemp(Output);
}

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessTonemap.cpp:33

Scope (from outer to inner):

file
namespace    anonymous

Source code excerpt:

namespace
{
TAutoConsoleVariable<float> CVarTonemapperSharpen(
	TEXT("r.Tonemapper.Sharpen"),
	-1,
	TEXT("Sharpening in the tonemapper (not for mobile), actual implementation is work in progress, clamped at 10\n")
	TEXT("  <0: inherit from PostProcessVolume settings (default)\n")
	TEXT("   0: off\n")
	TEXT(" 0.5: half strength\n")

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessTonemap.cpp:122

Scope (from outer to inner):

file
namespace    anonymous
namespace    TonemapperPermutation
function     static float GetSharpenSetting

Source code excerpt:

static float GetSharpenSetting(const FPostProcessSettings& Settings)
{
	float CVarSharpen = CVarTonemapperSharpen.GetValueOnRenderThread();
	float Sharpen = CVarSharpen >= 0.0 ? CVarSharpen : Settings.Sharpen;
	return FMath::Clamp(Sharpen, 0.0f, 10.0f);
}

// Common conversion of engine settings into.
FCommonDomain BuildCommonPermutationDomain(const FViewInfo& View, bool bGammaOnly, bool bLocalExposure, bool bMetalMSAAHDRDecode)