r.RayTracing.Shadows

r.RayTracing.Shadows

#Overview

name: r.RayTracing.Shadows

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 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.RayTracing.Shadows is to control the use of ray tracing for shadow rendering in Unreal Engine 5. This setting variable is part of the rendering system, specifically for shadow rendering.

This setting variable is primarily used in the Renderer module of Unreal Engine 5. It is referenced in the LightRendering.cpp and RayTracingShadows.cpp files, which are part of the runtime renderer subsystem.

The value of this variable is set through a console variable (CVarRayTracingOcclusion) defined in LightRendering.cpp. It can be changed at runtime using console commands or through project settings.

The r.RayTracing.Shadows variable interacts with other variables and systems:

  1. It’s closely associated with CVarRayTracingOcclusion, which shares the same value.
  2. It influences the behavior of the PrepareRayTracingShadows function in the FDeferredShadingSceneRenderer class.
  3. It affects the ShouldRenderRayTracingShadows and ShouldRenderRayTracingShadowsForLight functions.

Developers must be aware of the following when using this variable:

  1. The variable accepts two values: 0 (default) for traditional rasterized shadow maps, and 1 for ray tracing shadows.
  2. Even if r.RayTracing.Shadows is set to 0, ray tracing shadow shaders may still be configured for individual lights that have ray tracing shadows enabled independently.
  3. The effectiveness of this setting depends on the overall ray tracing compatibility of the rendering pipeline.

Best practices when using this variable include:

  1. Consider performance implications when enabling ray tracing shadows, as it can be more computationally expensive than traditional shadow mapping.
  2. Use in conjunction with other ray tracing settings for a consistent visual style.
  3. Test thoroughly in various scenarios to ensure desired shadow quality and performance.

Regarding the associated variable CVarRayTracingOcclusion:

The purpose of CVarRayTracingOcclusion is to provide a console-accessible way to control the r.RayTracing.Shadows setting. It’s defined as a TAutoConsoleVariable, allowing for runtime changes to the ray tracing shadows behavior.

This variable is used in the Renderer module, specifically in the light rendering and ray tracing systems. Its value is set through console commands or engine configuration.

CVarRayTracingOcclusion directly controls the behavior of r.RayTracing.Shadows and is used in functions like ShouldRenderRayTracingShadows to determine whether ray tracing shadows should be used.

Developers should be aware that changes to CVarRayTracingOcclusion will immediately affect the shadow rendering method. It’s marked as render thread safe and scalable, meaning it can be adjusted for different quality settings.

Best practices for CVarRayTracingOcclusion include:

  1. Use it for quick toggling of ray tracing shadows during development or debugging.
  2. Consider exposing it in user-facing graphics settings for performance tuning.
  3. Be mindful of its impact on rendering performance and adjust other settings accordingly when enabling ray tracing shadows.

#Setting Variables

#References In INI files

Location: <Workspace>/Projects/Lyra/Config/DefaultEngine.ini:124, 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/LightRendering.cpp:72

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarRayTracingOcclusion(
	TEXT("r.RayTracing.Shadows"),
	0,
	TEXT("0: use traditional rasterized shadow map (default)\n")
	TEXT("1: use ray tracing shadows"),
	ECVF_RenderThreadSafe | ECVF_Scalability);

static int32 GShadowRayTracingSamplesPerPixel = -1;

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

Scope (from outer to inner):

file
function     void FDeferredShadingSceneRenderer::PrepareRayTracingShadows

Source code excerpt:

void FDeferredShadingSceneRenderer::PrepareRayTracingShadows(const FViewInfo& View, const FScene& Scene, TArray<FRHIRayTracingShader*>& OutRayGenShaders)
{
	// Ray tracing shadows shaders should be properly configured even if r.RayTracing.Shadows is 0 because lights can have raytracing shadows enabled independently of that CVar
	// We have to check if ray tracing is enabled on any of the scene lights. The Scene.bHasRayTracedLights is computed using ShouldRenderRayTracingShadowsForLight() helper, 
	// which handles various override conditions.

	if (Scene.bHasRayTracedLights == false)
	{
		return;

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/LightRendering.cpp:71

Scope: file

Source code excerpt:

);

static TAutoConsoleVariable<int32> CVarRayTracingOcclusion(
	TEXT("r.RayTracing.Shadows"),
	0,
	TEXT("0: use traditional rasterized shadow map (default)\n")
	TEXT("1: use ray tracing shadows"),
	ECVF_RenderThreadSafe | ECVF_Scalability);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/LightRendering.cpp:215

Scope (from outer to inner):

file
function     bool ShouldRenderRayTracingShadows

Source code excerpt:

	const bool bHairStrands = IsHairStrandsEnabled(EHairStrandsShaderType::Strands);

	return ShouldRenderRayTracingEffect((CVarRayTracingOcclusion.GetValueOnRenderThread() > 0) && !(bIsStereo && bHairStrands), ERayTracingPipelineCompatibilityFlags::FullPipeline | ERayTracingPipelineCompatibilityFlags::Inline, nullptr);
}

bool ShouldRenderRayTracingShadowsForLight(const FLightSceneProxy& LightProxy)
{
	const bool bShadowRayTracingAllowed = ShouldRenderRayTracingEffect(true, ERayTracingPipelineCompatibilityFlags::FullPipeline | ERayTracingPipelineCompatibilityFlags::Inline, nullptr);
	return (LightProxy.CastsRaytracedShadow() == ECastRayTracedShadow::Enabled || (ShouldRenderRayTracingShadows() && LightProxy.CastsRaytracedShadow() == ECastRayTracedShadow::UseProjectSetting))