r.Mobile.CustomDepthForTranslucency

r.Mobile.CustomDepthForTranslucency

#Overview

name: r.Mobile.CustomDepthForTranslucency

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.Mobile.CustomDepthForTranslucency is to control whether custom depth/stencil should be rendered for translucency in mobile rendering scenarios. This setting is specifically designed for the mobile rendering system in Unreal Engine 5.

This setting variable is primarily used in the Renderer module of Unreal Engine, specifically in the mobile shading renderer subsystem. It’s referenced in the MobileShadingRenderer.cpp file, which is part of the mobile rendering pipeline.

The value of this variable is set through a console variable (CVarMobileCustomDepthForTranslucency) with a default value of 1 (On). It can be changed at runtime through console commands or programmatically.

The associated variable CVarMobileCustomDepthForTranslucency directly interacts with r.Mobile.CustomDepthForTranslucency. They share the same value and purpose.

Developers must be aware that this variable affects the rendering performance and visual quality of translucent objects in mobile games. Enabling this feature (value = 1) allows for more accurate rendering of translucent objects that use custom depth or stencil, but it may have a performance cost.

Best practices when using this variable include:

  1. Only enable it if your mobile game actually uses custom depth/stencil for translucent objects.
  2. Test the performance impact on target mobile devices before enabling it in production.
  3. Consider providing an in-game option for users to toggle this feature on lower-end devices.

Regarding the associated variable CVarMobileCustomDepthForTranslucency:

The purpose of CVarMobileCustomDepthForTranslucency is to provide a programmatic way to control the r.Mobile.CustomDepthForTranslucency setting within the engine’s C++ code.

This console variable is defined and used within the Renderer module, specifically in the mobile shading renderer.

The value of CVarMobileCustomDepthForTranslucency is set when the engine initializes, but it can be changed at runtime through console commands or programmatically.

It directly controls the behavior of the custom depth/stencil rendering for translucency in the mobile rendering pipeline. The GetCustomDepthStencilUsage function uses this variable to determine whether to enable custom depth/stencil rendering for translucent objects.

Developers should be aware that changes to this console variable will immediately affect the rendering behavior of translucent objects that use custom depth or stencil.

Best practices for using CVarMobileCustomDepthForTranslucency include:

  1. Use it to dynamically adjust the custom depth/stencil rendering based on performance requirements or device capabilities.
  2. When modifying this value, ensure that all related systems (like post-processing or material setups) are updated accordingly.
  3. Document any runtime changes to this variable to aid in debugging and performance optimization.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/MobileShadingRenderer.cpp:92

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarMobileCustomDepthForTranslucency(
	TEXT("r.Mobile.CustomDepthForTranslucency"),
	1,
	TEXT(" Whether to render custom depth/stencil if any tranclucency in the scene uses it. \n")
	TEXT(" 0 = Off \n")
	TEXT(" 1 = On [default]"),
	ECVF_Scalability | ECVF_RenderThreadSafe);

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/MobileShadingRenderer.cpp:91

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarMobileCustomDepthForTranslucency(
	TEXT("r.Mobile.CustomDepthForTranslucency"),
	1,
	TEXT(" Whether to render custom depth/stencil if any tranclucency in the scene uses it. \n")
	TEXT(" 0 = Off \n")
	TEXT(" 1 = On [default]"),
	ECVF_Scalability | ECVF_RenderThreadSafe);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/MobileShadingRenderer.cpp:146

Scope (from outer to inner):

file
function     static FMobileCustomDepthStencilUsage GetCustomDepthStencilUsage

Source code excerpt:

	{
		// Find out whether CustomDepth/Stencil used in translucent materials
		if (CVarMobileCustomDepthForTranslucency.GetValueOnAnyThread() != 0)
		{
			CustomDepthStencilUsage.bUsesCustomDepthStencil = View.bUsesCustomDepth || View.bUsesCustomStencil;
			CustomDepthStencilUsage.bSamplesCustomStencil = View.bUsesCustomStencil;
		}

		if (!CustomDepthStencilUsage.bSamplesCustomStencil)