r.GeneralPurposeTweak

r.GeneralPurposeTweak

#Overview

name: r.GeneralPurposeTweak

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.GeneralPurposeTweak is to provide a quick and flexible way for low-level shader development without requiring C++ code changes. It serves as a general-purpose variable that can be used for various tweaking and debugging purposes in the rendering system.

This setting variable is primarily used in the Renderer module of Unreal Engine, specifically within the scene rendering subsystem. It’s designed to be accessible within shaders, mapping to Frame.GeneralPurposeTweak.

The value of this variable is set through the console variable system. It’s initialized with a default value of 1.0f and can be changed at runtime using console commands.

The r.GeneralPurposeTweak variable interacts directly with its associated C++ variable CVarGeneralPurposeTweak. They share the same value, and CVarGeneralPurposeTweak is used to retrieve the current value of r.GeneralPurposeTweak within the C++ code.

Developers must be aware of several important aspects when using this variable:

  1. It’s only available in non-shipping and non-test builds, as it’s compiled out in these configurations to make cheating more difficult.
  2. It’s intended for quick iteration and experimentation, not for final, checked-in code.
  3. The variable is render thread safe, meaning it can be safely accessed from the render thread.

Best practices for using this variable include:

  1. Use it only for temporary tweaks and experiments during development.
  2. Don’t rely on it for any permanent game features or checked-in code.
  3. Be cautious when modifying its value, as it could potentially affect various aspects of shader behavior.
  4. Document any usage of this variable in your development process to ensure it’s removed or replaced with proper implementation before shipping.

Regarding the associated variable CVarGeneralPurposeTweak:

The purpose of CVarGeneralPurposeTweak is to provide C++ code access to the r.GeneralPurposeTweak console variable. It’s the actual TAutoConsoleVariable object that represents r.GeneralPurposeTweak in the engine’s code.

This variable is used within the Renderer module, specifically in the scene rendering process. It’s accessed in the FViewInfo::SetupUniformBufferParameters function to set the GeneralPurposeTweak parameter in the view’s uniform shader parameters.

The value of CVarGeneralPurposeTweak is set when r.GeneralPurposeTweak is modified through console commands. It can be retrieved in C++ code using the GetValueOnRenderThread() method.

CVarGeneralPurposeTweak interacts directly with r.GeneralPurposeTweak, serving as its C++ representation. It also interacts with the ViewUniformShaderParameters struct, where its value is assigned to the GeneralPurposeTweak member.

Developers should be aware that:

  1. This variable is only available in development builds.
  2. It’s accessed on the render thread, so any modifications should be thread-safe.
  3. Changes to this variable will affect shader behavior in potentially wide-ranging ways.

Best practices for using CVarGeneralPurposeTweak include:

  1. Only use it for development and debugging purposes.
  2. Ensure any usage is removed or properly implemented before shipping.
  3. Be cautious when modifying its value, as it could affect rendering behavior significantly.
  4. Use the GetValueOnRenderThread() method when accessing its value to ensure thread safety.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:280

Scope: file

Source code excerpt:

#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
static TAutoConsoleVariable<float> CVarGeneralPurposeTweak(
	TEXT("r.GeneralPurposeTweak"),
	1.0f,
	TEXT("Useful for low level shader development to get quick iteration time without having to change any c++ code.\n")
	TEXT("Value maps to Frame.GeneralPurposeTweak inside the shaders.\n")
	TEXT("Example usage: Multiplier on some value to tweak, toggle to switch between different algorithms (Default: 1.0)\n")
	TEXT("DON'T USE THIS FOR ANYTHING THAT IS CHECKED IN. Compiled out in SHIPPING to make cheating a bit harder."),
	ECVF_RenderThreadSafe);

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:279

Scope: file

Source code excerpt:


#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
static TAutoConsoleVariable<float> CVarGeneralPurposeTweak(
	TEXT("r.GeneralPurposeTweak"),
	1.0f,
	TEXT("Useful for low level shader development to get quick iteration time without having to change any c++ code.\n")
	TEXT("Value maps to Frame.GeneralPurposeTweak inside the shaders.\n")
	TEXT("Example usage: Multiplier on some value to tweak, toggle to switch between different algorithms (Default: 1.0)\n")
	TEXT("DON'T USE THIS FOR ANYTHING THAT IS CHECKED IN. Compiled out in SHIPPING to make cheating a bit harder."),

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:1772

Scope (from outer to inner):

file
function     void FViewInfo::SetupUniformBufferParameters

Source code excerpt:

		// Compiled out in SHIPPING to make cheating a bit harder.
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
		Value = CVarGeneralPurposeTweak.GetValueOnRenderThread();
		Value2 = CVarGeneralPurposeTweak2.GetValueOnRenderThread();
#endif

		ViewUniformShaderParameters.GeneralPurposeTweak = Value;
		ViewUniformShaderParameters.GeneralPurposeTweak2 = Value2;
	}