r.RayTracing.Shadows.Translucency

r.RayTracing.Shadows.Translucency

#Overview

name: r.RayTracing.Shadows.Translucency

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.RayTracing.Shadows.Translucency is to control how translucent materials cast shadows in ray-traced rendering. It is part of the ray tracing system in Unreal Engine 5, specifically for handling shadows cast by translucent objects.

This setting variable is used in the rendering subsystem of Unreal Engine, particularly in the ray tracing module for shadows. Based on the callsites, it’s primarily utilized in the RayTracingShadows.cpp file, which is part of the Renderer module.

The value of this variable is set through a console variable (CVarRayTracingShadowsTranslucency) with two possible options: 0: Translucent materials will not cast shadows (default behavior) 1: Translucent materials cast approximate translucent shadows based on opacity (very expensive computationally)

This variable interacts with other ray tracing shadow settings, such as CVarRayTracingShadowsAcceptFirstHit and CVarRayTracingShadowsMaxTranslucencyHitCount, as seen in the source code excerpt.

Developers must be aware that enabling translucent shadows (setting the value to 1) can be very expensive in terms of performance. This setting should be used judiciously, considering the performance impact on the target hardware.

Best practices when using this variable include:

  1. Keep it disabled (0) by default for better performance.
  2. Enable it (1) only when high-quality translucent shadows are absolutely necessary for the visual quality of the scene.
  3. Test thoroughly on target hardware to ensure acceptable performance when enabled.
  4. Consider using it selectively, perhaps only for specific important translucent objects rather than globally.

The associated variable CVarRayTracingShadowsTranslucency is the actual console variable that controls this setting. It’s defined with the same name as the setting (“r.RayTracing.Shadows.Translucency”) and shares the same value and purpose. This console variable is used to get the current setting value at runtime, as seen in the source code where it’s accessed using GetValueOnRenderThread(). Developers can modify this setting through the console or configuration files to adjust the behavior of translucent shadows in ray-traced rendering.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/RayTracing/RayTracingShadows.cpp:110

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarRayTracingShadowsTranslucency(
	TEXT("r.RayTracing.Shadows.Translucency"),
	0,
	TEXT("0: Translucent material will not cast shadow (by default).")
	TEXT("1: Translucent material cast approximate translucent shadows based on opacity (Very expensive)."),
	ECVF_RenderThreadSafe
);
static TAutoConsoleVariable<int32> CVarRayTracingShadowsMaxTranslucencyHitCount(

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/RayTracing/RayTracingShadows.cpp:109

Scope: file

Source code excerpt:

);

static TAutoConsoleVariable<int32> CVarRayTracingShadowsTranslucency(
	TEXT("r.RayTracing.Shadows.Translucency"),
	0,
	TEXT("0: Translucent material will not cast shadow (by default).")
	TEXT("1: Translucent material cast approximate translucent shadows based on opacity (Very expensive)."),
	ECVF_RenderThreadSafe
);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/RayTracing/RayTracingShadows.cpp:417

Scope: file

Source code excerpt:

		CommonPassParameters->bAcceptFirstHit = CVarRayTracingShadowsAcceptFirstHit.GetValueOnRenderThread();
		CommonPassParameters->bTwoSidedGeometry = EnableRayTracingShadowTwoSidedGeometry() ? 1 : 0;
		CommonPassParameters->TranslucentShadow = CVarRayTracingShadowsTranslucency.GetValueOnRenderThread();
		CommonPassParameters->MaxTranslucencyHitCount = GetRayTracingShadowsMaxTranslucencyHitCount();
		CommonPassParameters->TLAS = View.GetRayTracingSceneLayerViewChecked(ERayTracingSceneLayer::Base);
		CommonPassParameters->ViewUniformBuffer = View.ViewUniformBuffer;
		CommonPassParameters->SceneTextures = SceneTextures;
		CommonPassParameters->SceneLightingChannels = GetSceneLightingChannelParameters(GraphBuilder, LightingChannelsTexture);
		CommonPassParameters->LightScissor = ScissorRect;