r.Test.Aplha.OpaqueWorldDistance

r.Test.Aplha.OpaqueWorldDistance

#Overview

name: r.Test.Aplha.OpaqueWorldDistance

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.Test.Aplha.OpaqueWorldDistance is to set the world distance beyond which opaque pixels are lerped to translucent for testing purposes in the rendering system of Unreal Engine 5.

This setting variable is primarily used in the rendering subsystem, specifically in the post-processing module for debugging alpha channel-related issues. It is part of the debug functionality for alpha channel rendering.

The value of this variable is set through the console variable system in Unreal Engine. It is defined as a TAutoConsoleVariable with an initial value of 0.0f.

This variable interacts closely with another variable named CVarTestAlphaOpaqueLerpWorldRange, which sets the gradient length in world units for the lerping process.

Developers must be aware that this variable is only active when DEBUG_ALPHA_CHANNEL is defined, as it’s wrapped in an #if DEBUG_ALPHA_CHANNEL block. It’s specifically designed for testing and debugging purposes, not for use in production environments.

Best practices when using this variable include:

  1. Only use it for debugging alpha channel issues in the rendering pipeline.
  2. Be cautious when adjusting its value, as it can significantly affect the visual output of the scene.
  3. Use it in conjunction with CVarTestAlphaOpaqueLerpWorldRange for fine-tuned control over the translucency effect.
  4. Remember to disable or reset it to 0.0f when not actively debugging to avoid unintended visual artifacts.

The associated variable CVarTestAlphaOpaqueWorldDistance serves the same purpose and is used interchangeably with r.Test.Aplha.OpaqueWorldDistance. It’s defined in the same file and is used in the ShouldMakeDistantGeometryTranslucent and MakeDistanceGeometryTranslucent functions.

When working with CVarTestAlphaOpaqueWorldDistance:

  1. Access its value using GetValueOnRenderThread() to ensure thread-safe operations.
  2. It’s used as a threshold to determine if distant geometry should be made translucent.
  3. Values greater than 0.0f activate the translucency effect for distant objects.
  4. It’s passed directly to shader parameters, so be mindful of potential performance implications when modifying its value frequently.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/DebugAlphaChannel.cpp:11

Scope: file

Source code excerpt:


TAutoConsoleVariable<float> CVarTestAlphaOpaqueWorldDistance(
	TEXT("r.Test.Aplha.OpaqueWorldDistance"), 0.0f,
	TEXT("Sets the world distance beyond which the opaque pixel are lerped to translucent for testing purposes."),
	ECVF_RenderThreadSafe);

TAutoConsoleVariable<float> CVarTestAlphaOpaqueLerpWorldRange(
	TEXT("r.Test.Aplha.OpaqueLerpWorldRange"), 100.0f,
	TEXT("Sets the gradient length in world unit on which opaque pixel are lerped to translucent for testing purposes."),

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/DebugAlphaChannel.cpp:10

Scope: file

Source code excerpt:

#if DEBUG_ALPHA_CHANNEL

TAutoConsoleVariable<float> CVarTestAlphaOpaqueWorldDistance(
	TEXT("r.Test.Aplha.OpaqueWorldDistance"), 0.0f,
	TEXT("Sets the world distance beyond which the opaque pixel are lerped to translucent for testing purposes."),
	ECVF_RenderThreadSafe);

TAutoConsoleVariable<float> CVarTestAlphaOpaqueLerpWorldRange(
	TEXT("r.Test.Aplha.OpaqueLerpWorldRange"), 100.0f,

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/DebugAlphaChannel.cpp:50

Scope (from outer to inner):

file
function     bool ShouldMakeDistantGeometryTranslucent

Source code excerpt:

bool ShouldMakeDistantGeometryTranslucent()
{
	return CVarTestAlphaOpaqueWorldDistance.GetValueOnRenderThread() > 0.0f;
}

FRDGTextureMSAA MakeDistanceGeometryTranslucent(
	FRDGBuilder& GraphBuilder,
	TArrayView<const FViewInfo> Views,
	FMinimalSceneTextures SceneTextures)

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/DebugAlphaChannel.cpp:68

Scope (from outer to inner):

file
function     FRDGTextureMSAA MakeDistanceGeometryTranslucent

Source code excerpt:

		PassParameters->ViewUniformBuffer = View.ViewUniformBuffer;
		PassParameters->DebugModeId = 0; // MakeDistanceOpaqueTranslucent
		PassParameters->OpaqueWorldDistance = CVarTestAlphaOpaqueWorldDistance.GetValueOnRenderThread();
		PassParameters->OpaqueLerpWorldRange = CVarTestAlphaOpaqueLerpWorldRange.GetValueOnRenderThread();

		PassParameters->SceneColorTexture = SceneTextures.Color.Resolve;
		PassParameters->SceneDepthTexture = SceneTextures.Depth.Resolve;

		PassParameters->SceneColorOutput = GraphBuilder.CreateUAV(NewSceneColorTexture);