r.RayTracing

r.RayTracing

#Overview

name: r.RayTracing

The value of this variable can be defined or overridden in .ini config files. 1 .ini config file referencing this setting variable.

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

It is referenced in 9 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.RayTracing is to enable or disable ray tracing in Unreal Engine 5. This setting variable is primarily used for controlling the rendering system’s ray tracing capabilities.

The r.RayTracing variable is utilized by several Unreal Engine subsystems and modules, including:

  1. The Renderer module
  2. The GPULightmassEditor plugin
  3. The ICVFXTesting plugin
  4. The TargetPlatform module
  5. The GameProjectGeneration module
  6. The Engine module (specifically for PostProcessVolume functionality)
  7. The RHI (Rendering Hardware Interface) module

The value of this variable is set as a console variable (CVar) in the engine’s initialization code. It can be modified through console commands or project settings.

Other variables that interact with r.RayTracing include:

Developers should be aware that:

  1. The variable is read-only and render thread safe.
  2. It’s a binary setting (0 for off, 1 for on).
  3. Changing this setting may affect other rendering features and performance.

Best practices when using this variable:

  1. Ensure the target hardware supports ray tracing before enabling it.
  2. Consider the performance impact of enabling ray tracing, especially on lower-end hardware.
  3. Use it in conjunction with other ray tracing-related settings for optimal results.
  4. Test thoroughly when enabling or disabling ray tracing, as it can significantly affect the visual output and performance of the game.

#Setting Variables

#References In INI files

Location: <Workspace>/Projects/Lyra/Config/DefaultEngine.ini:122, section: [/Script/Engine.RendererSettings]

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/DeferredShadingRenderer.cpp:149

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarRayTracing(
	TEXT("r.RayTracing"),
	0,
	TEXT("0 to disable ray tracing.\n")
	TEXT(" 0: off\n")
	TEXT(" 1: on"),
	ECVF_RenderThreadSafe | ECVF_ReadOnly);

#Loc: <Workspace>/Engine/Plugins/Experimental/GPULightmass/Source/GPULightmassEditor/Private/GPULightmassEditorModule.cpp:85

Scope (from outer to inner):

file
function     ERayTracingDisabledReason GetRayTracingDisabledReason

Source code excerpt:

	}
	
	static IConsoleVariable* RayTracingCVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.RayTracing"));
	if (RayTracingCVar->GetInt() == 0)
	{
		return ERayTracingDisabledReason::DISABLED_BY_PROJECT_SETTINGS;
	}

	if (!RHISupportsRayTracing(ShaderPlatform))

#Loc: <Workspace>/Engine/Plugins/VirtualProduction/ICVFXTesting/Source/ICVFXTesting/Public/ICVFXTestControllerBase.h:75

Scope (from outer to inner):

file
class        class UICVFXTestControllerBase : public UGauntletTestController

Source code excerpt:

		TEXT("r.nanite"),
		TEXT("r.ScreenPercentage"),
		TEXT("r.RayTracing"),
		TEXT("r.DynamicGlobalIlluminationMethod"),
		TEXT("r.ReflectionMethod"),
		TEXT("r.Lumen"),
		TEXT("FX.AllowGPUParticles"),
		TEXT("r.Shadow.Virtual.Enable")};

#Loc: <Workspace>/Engine/Source/Developer/TargetPlatform/Private/TargetPlatformBase.cpp:52

Scope (from outer to inner):

file
function     bool FTargetPlatformBase::UsesRayTracing

Source code excerpt:

bool FTargetPlatformBase::UsesRayTracing() const
{
	static IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.RayTracing"));
	return CVar ? (CVar->GetInt() != 0) : false;
}

uint32 FTargetPlatformBase::GetSupportedHardwareMask() const
{
	return 0;

#Loc: <Workspace>/Engine/Source/Developer/TargetPlatform/Private/TargetPlatformSettingsBase.cpp:41

Scope (from outer to inner):

file
function     bool FTargetPlatformSettingsBase::UsesRayTracing

Source code excerpt:

bool FTargetPlatformSettingsBase::UsesRayTracing() const
{
	static IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.RayTracing"));
	return CVar ? (CVar->GetInt() != 0) : false;
}

uint32 FTargetPlatformSettingsBase::GetSupportedHardwareMask() const
{
	return 0;

#Loc: <Workspace>/Engine/Source/Editor/GameProjectGeneration/Private/GameProjectUtils.cpp:174

Scope (from outer to inner):

file
namespace    anonymous
function     void AddRaytracingConfigValues

Source code excerpt:

			ConfigValues.Emplace(TEXT("DefaultEngine.ini"),
				TEXT("/Script/Engine.RendererSettings"),
				TEXT("r.RayTracing"),
				TEXT("True"),
				true /* ShouldReplaceExistingValue */);
		}
	}

	void AddDefaultMapConfigValues(const FProjectInformation& InProjectInfo, TArray<FTemplateConfigValue>& ConfigValues)
	{
		if (InProjectInfo.bIsBlankTemplate &&
			InProjectInfo.bCopyStarterContent &&
			GameProjectUtils::IsUsingEngineStarterContent(InProjectInfo) &&

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/PostProcessVolume.cpp:209

Scope (from outer to inner):

file
function     bool APostProcessVolume::CanEditChange

Source code excerpt:

			if (PropertyName == GET_MEMBER_NAME_STRING_CHECKED(FPostProcessSettings, LumenRayLightingMode))
			{
				static IConsoleVariable* RayTracingCVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.RayTracing"));
				if (RayTracingCVar->GetInt() == 0)
				{
					return false;
				}
			}

#Loc: <Workspace>/Engine/Source/Runtime/RHI/Public/DataDrivenShaderPlatformInfo.h:1088

Scope: file

Source code excerpt:


/** Whether this platform can build acceleration structures and use full ray tracing pipelines or inline ray tracing (ray queries).
 *  To use at runtime, also check GRHISupportsRayTracing and r.RayTracing CVar (see IsRayTracingEnabled() helper).
 *  Check GRHISupportsRayTracingShaders before using full ray tracing pipeline state objects.
 *  Check GRHISupportsInlineRayTracing before using inline ray tracing features in compute and other shaders.
 **/
inline bool RHISupportsRayTracing(const FStaticShaderPlatform Platform)
{
	return FDataDrivenShaderPlatformInfo::GetSupportsRayTracing(Platform);
}

/** Whether this platform can compile ray tracing shaders (regardless of project settings).
 *  To use at runtime, also check GRHISupportsRayTracing and r.RayTracing CVar (see IsRayTracingEnabled() helper).
 **/
inline bool RHISupportsRayTracingShaders(const FStaticShaderPlatform Platform)
{
	return FDataDrivenShaderPlatformInfo::GetSupportsRayTracingShaders(Platform);
}

/** Whether this platform can compile shaders with inline ray tracing features.
 *  To use at runtime, also check GRHISupportsRayTracing and r.RayTracing CVar (see IsRayTracingEnabled() helper).
 **/
inline bool RHISupportsInlineRayTracing(const FStaticShaderPlatform Platform)
{
	return FDataDrivenShaderPlatformInfo::GetSupportsInlineRayTracing(Platform);
}

/** Whether this platform can compile ray tracing callable shaders.
 *  To use at runtime, also check GRHISupportsRayTracing and r.RayTracing CVar (see IsRayTracingEnabled() helper).
 **/
inline bool RHISupportsRayTracingCallableShaders(const FStaticShaderPlatform Platform)
{
	return FDataDrivenShaderPlatformInfo::GetSupportsRayTracingCallableShaders(Platform);
}

/** Can this platform compile mesh shaders with tier0 capability.
 *  To use at runtime, also check GRHISupportsMeshShadersTier0.

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/RenderUtils.cpp:755

Scope (from outer to inner):

file
function     void RenderUtilsInit

Source code excerpt:

	GDistanceFieldsPlatformMask.Init(DistanceFieldsCVar && DistanceFieldsCVar->GetInt(), EShaderPlatform::SP_NumPlatforms);

	static IConsoleVariable* RayTracingCVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.RayTracing"));

	GSimpleSkyDiffusePlatformMask.Init(false, EShaderPlatform::SP_NumPlatforms);
	GVelocityEncodeDepthPlatformMask.Init(false, EShaderPlatform::SP_NumPlatforms);
	GRayTracingPlatformMask.Init(false, EShaderPlatform::SP_NumPlatforms);

	static IConsoleVariable* MobileAmbientOcclusionCVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Mobile.AmbientOcclusion"));