r.Shading.EnergyConservation.Format

r.Shading.EnergyConservation.Format

#Overview

name: r.Shading.EnergyConservation.Format

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

It is referenced in 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.Shading.EnergyConservation.Format is to control the format of the energy conservation table used in the shading system of Unreal Engine 5. It determines whether the table uses 16-bit or 32-bit precision for storing energy conservation data.

This setting variable is primarily used in the rendering system, specifically in the shading and energy conservation subsystem. Based on the callsites, it’s part of the Renderer module of Unreal Engine 5.

The value of this variable is set through a console variable (CVar) system. It’s defined with a default value of 1, which corresponds to 32-bit precision. Users can change this value at runtime using console commands.

The associated variable CVarShadingFurnaceTest_TableFormat directly interacts with r.Shading.EnergyConservation.Format. They share the same value and are used interchangeably in the code.

Developers must be aware that changing this variable affects the precision of energy conservation calculations in shading. Using 16-bit precision (value 0) may result in less accurate but potentially faster calculations, while 32-bit precision (value 1) provides higher accuracy at the cost of increased memory usage and potentially slower performance.

Best practices when using this variable include:

  1. Consider the trade-off between precision and performance when choosing between 16-bit and 32-bit formats.
  2. Test the visual impact of changing this setting in different lighting scenarios.
  3. Be aware that changing this value may require regeneration of the energy conservation tables, which could impact runtime performance during the update.

Regarding the associated variable CVarShadingFurnaceTest_TableFormat:

The purpose of CVarShadingFurnaceTest_TableFormat is identical to r.Shading.EnergyConservation.Format, as they are essentially the same variable.

This variable is used in the Renderer module, specifically in the shading energy conservation system.

Its value is set through the same console variable system as r.Shading.EnergyConservation.Format.

It directly interacts with r.Shading.EnergyConservation.Format, sharing the same value and purpose.

Developers should be aware that this variable is used internally in the code to determine the format of the energy conservation tables. It affects the creation and usage of textures for specular energy conservation in the GGX BSDF model.

Best practices for using CVarShadingFurnaceTest_TableFormat are the same as those for r.Shading.EnergyConservation.Format, as they are functionally equivalent.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadingEnergyConservation.cpp:41

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarShadingFurnaceTest_TableFormat(
	TEXT("r.Shading.EnergyConservation.Format"),
	1,
	TEXT("Energy conservation table format 0: 16bits, 1: 32bits."),
	ECVF_RenderThreadSafe);

// Transition render settings that will disapear when Substrate gets enabled

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadingEnergyConservationData.h:7

Scope: file

Source code excerpt:


// How to update those tables?
//  1- Set r.Shading.EnergyConservation.Format to 0
//	2- Open the texture asset in renderdoc and click "Open the texture content in a raw buffer viewer"
//  3- Set the format as "ushort2 pixels[32];" and hit the apply button.
//  4- Export CSV and you then get the data to copy paste. Note: you might need to format then a bit like adding commad at the end of lines.

// Specular directional albedo for GGX BSDF (2D)
// 2x16bits (unorm) (FG decomposition)

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadingEnergyConservation.cpp:40

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarShadingFurnaceTest_TableFormat(
	TEXT("r.Shading.EnergyConservation.Format"),
	1,
	TEXT("Energy conservation table format 0: 16bits, 1: 32bits."),
	ECVF_RenderThreadSafe);

// Transition render settings that will disapear when Substrate gets enabled

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadingEnergyConservation.cpp:234

Scope (from outer to inner):

file
function     namespace ShadingEnergyConservation { bool IsEnable
function     void Init

Source code excerpt:


		const int Size = SHADING_ENERGY_CONSERVATION_TABLE_RESOLUTION;
		const EPixelFormat SpecFormat = bRuntimeGeneration && CVarShadingFurnaceTest_TableFormat.GetValueOnRenderThread() > 0 ? PF_G32R32F : PF_G16R16;
		const EPixelFormat DiffFormat = PF_G16;
		const bool bBuildTable = 
			View.ViewState->ShadingEnergyConservationData.Format != SpecFormat ||
			View.ViewState->ShadingEnergyConservationData.GGXSpecEnergyTexture == nullptr ||
			View.ViewState->ShadingEnergyConservationData.GGXGlassEnergyTexture == nullptr ||
			View.ViewState->ShadingEnergyConservationData.ClothEnergyTexture ==  nullptr ||