r.Material.RoughDiffuse
r.Material.RoughDiffuse
#Overview
name: r.Material.RoughDiffuse
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Enable rough diffuse material.
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.Material.RoughDiffuse is to enable rough diffuse material in Unreal Engine’s rendering system. This setting variable controls whether the engine should use a more physically accurate model for diffuse lighting that takes surface roughness into account.
Key points about r.Material.RoughDiffuse:
-
It is part of the material and lighting subsystem in Unreal Engine.
-
The value is set through a console variable (CVar), allowing runtime modification.
-
It affects shader compilation, as evidenced by its use in shader key generation (ShaderMapAppendKeyString function).
-
When enabled, it adds the “_MATRDIFF” suffix to the shader key string, likely triggering the compilation of shader variants that include rough diffuse calculations.
-
In the shader code, it sets the MATERIAL_ROUGHDIFFUSE define, but only if Substrate (a newer material system) is not enabled or if Substrate’s own rough diffuse setting is disabled.
-
The variable interacts with the Substrate system, showing a transition between older and newer rendering techniques.
Developers should be aware that:
- Enabling this feature may increase rendering cost but provide more accurate lighting results.
- It may not have an effect if the Substrate system is enabled and configured differently.
- Changing this setting at runtime will likely require shader recompilation, which could cause a performance hitch.
Best practices:
- Consider the performance implications before enabling this feature, especially on lower-end hardware.
- Test the visual impact in various lighting conditions to determine if the quality improvement justifies the performance cost.
- If using the Substrate system, be aware of how it interacts with this setting to avoid conflicts or unexpected behavior.
- When making changes to this setting, plan for potential shader recompilation time, especially in development builds.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/RenderUtils.cpp:1783
Scope: file
Source code excerpt:
// Transition render settings that will disappear when Substrate gets enabled
static TAutoConsoleVariable<int32> CVarMaterialRoughDiffuse(
TEXT("r.Material.RoughDiffuse"),
0,
TEXT("Enable rough diffuse material."),
ECVF_ReadOnly | ECVF_RenderThreadSafe);
static TAutoConsoleVariable<int32> CVarSubstrateRoughDiffuse(
TEXT("r.Substrate.RoughDiffuse"),
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/ShaderCompiler/ShaderCompiler.cpp:8552
Scope (from outer to inner):
file
function void GlobalBeginCompileShader
Source code excerpt:
{
static IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Material.RoughDiffuse"));
const bool bMaterialRoughDiffuse = CVar && CVar->GetInt() != 0;
const bool bSubstrateRoughDiffuse = Substrate::IsRoughDiffuseEnabled() && !Substrate::IsBackCompatibilityEnabled();
SET_SHADER_DEFINE(Input.Environment, MATERIAL_ROUGHDIFFUSE, (bSubstrate ? bSubstrateRoughDiffuse : bMaterialRoughDiffuse) ? 1 : 0);
}
{
#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/Shader.cpp:2099
Scope (from outer to inner):
file
function void ShaderMapAppendKeyString
Source code excerpt:
{
static const auto CVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Material.RoughDiffuse"));
if (CVar && CVar->GetValueOnAnyThread() > 0)
{
KeyString += FString::Printf(TEXT("_MATRDIFF"));
}
}