r.Substrate.RoughDiffuse

r.Substrate.RoughDiffuse

#Overview

name: r.Substrate.RoughDiffuse

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

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.Substrate.RoughDiffuse is to enable or disable the Substrate rough diffuse model in Unreal Engine’s rendering system. This setting is part of the Substrate rendering feature set, which is a new material model introduced in Unreal Engine 5.

This setting variable is primarily used by the rendering subsystem of Unreal Engine, specifically within the RenderCore module. It’s closely tied to the material system and affects how rough diffuse surfaces are rendered.

The value of this variable is set through a console variable (CVarSubstrateRoughDiffuse) in the RenderUtils.cpp file. It’s initialized with a default value of 1, meaning the feature is enabled by default.

The associated variable CVarSubstrateRoughDiffuse interacts directly with r.Substrate.RoughDiffuse. It’s used to query the current state of the setting within the engine code.

Developers must be aware that this setting only works if r.Material.RoughDiffuse is also enabled in the project settings. This interdependency is crucial for the feature to function correctly.

Best practices when using this variable include:

  1. Ensuring r.Material.RoughDiffuse is enabled in project settings if you want to use this feature.
  2. Being aware that this setting can be toggled at runtime, which allows for dynamic adjustments to rendering quality or performance.
  3. Understanding that enabling this feature may have performance implications, so it should be tested thoroughly in different scenarios.

Regarding the associated variable CVarSubstrateRoughDiffuse:

The purpose of CVarSubstrateRoughDiffuse is to provide a programmatic interface to control the r.Substrate.RoughDiffuse setting within the engine code.

This variable is used within the Substrate namespace in the RenderCore module. It’s primarily used in the IsRoughDiffuseEnabled() function, which checks if the Substrate rough diffuse model is currently enabled.

The value of CVarSubstrateRoughDiffuse is set when the r.Substrate.RoughDiffuse console variable is modified, either through code or via console commands.

CVarSubstrateRoughDiffuse interacts directly with the r.Substrate.RoughDiffuse setting, effectively serving as its in-code representation.

Developers should be aware that this variable is marked as ECVF_RenderThreadSafe, meaning it’s safe to access from the render thread.

Best practices for using CVarSubstrateRoughDiffuse include:

  1. Using the IsRoughDiffuseEnabled() function to check the current state, rather than accessing the variable directly.
  2. Being mindful of potential performance impacts when frequently querying or changing this value.
  3. Considering the thread-safety implications when accessing this variable from different parts of the engine code.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/Android/AndroidEngine.ini:96, section: [/Script/Engine.RendererSettings]

Location: <Workspace>/Engine/Config/IOS/BaseIOSEngine.ini:14, section: [/Script/Engine.RendererSettings]

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/RenderUtils.cpp:1789

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarSubstrateRoughDiffuse(
	TEXT("r.Substrate.RoughDiffuse"),
	1,
	TEXT("Enable Substrate rough diffuse model (works only if r.Material.RoughDiffuse is enabled in the project settings). Togglable at runtime"),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarSubstrateGlints(
	TEXT("r.Substrate.Glints"),

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/RenderUtils.cpp:1788

Scope: file

Source code excerpt:

	ECVF_ReadOnly | ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarSubstrateRoughDiffuse(
	TEXT("r.Substrate.RoughDiffuse"),
	1,
	TEXT("Enable Substrate rough diffuse model (works only if r.Material.RoughDiffuse is enabled in the project settings). Togglable at runtime"),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarSubstrateGlints(

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/RenderUtils.cpp:1921

Scope (from outer to inner):

file
namespace    Substrate
function     bool IsRoughDiffuseEnabled

Source code excerpt:

	bool IsRoughDiffuseEnabled()
	{
		return CVarSubstrateRoughDiffuse.GetValueOnAnyThread() > 0;
	}

	bool IsGlintEnabled()
	{
		return IsSubstrateEnabled() && CVarSubstrateGlints.GetValueOnAnyThread() > 0;
	}