r.RayTracing.Shadows.AcceptFirstHit

r.RayTracing.Shadows.AcceptFirstHit

#Overview

name: r.RayTracing.Shadows.AcceptFirstHit

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.AcceptFirstHit is to control whether shadow rays in ray-traced rendering should terminate early upon the first intersection with a primitive. This setting is part of Unreal Engine 5’s ray tracing system, specifically for shadow calculations.

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

The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 1 (enabled) but can be changed at runtime through console commands or project settings.

The associated variable CVarRayTracingShadowsAcceptFirstHit directly interacts with r.RayTracing.Shadows.AcceptFirstHit. They share the same value and purpose.

Developers must be aware that enabling this feature (setting it to 1) may result in faster rendering times but potentially lower quality shadows, especially in scenes with complex geometry or translucent objects. The comment in the code explicitly mentions that this “may result in worse denoising quality in some cases.”

Best practices when using this variable include:

  1. Testing the visual quality with both settings (0 and 1) in your specific scenes.
  2. Consider disabling it (setting to 0) for final renders or in scenes where shadow quality is crucial.
  3. Be mindful of the performance-quality tradeoff, especially in real-time applications.

Regarding the associated variable CVarRayTracingShadowsAcceptFirstHit:

#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:103

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarRayTracingShadowsAcceptFirstHit(
	TEXT("r.RayTracing.Shadows.AcceptFirstHit"),
	1,
	TEXT("Whether to allow shadow rays to terminate early, on first intersected primitive. This may result in worse denoising quality in some cases. (default = 0)"),
	ECVF_RenderThreadSafe
);

static TAutoConsoleVariable<int32> CVarRayTracingShadowsTranslucency(

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

);

static TAutoConsoleVariable<int32> CVarRayTracingShadowsAcceptFirstHit(
	TEXT("r.RayTracing.Shadows.AcceptFirstHit"),
	1,
	TEXT("Whether to allow shadow rays to terminate early, on first intersected primitive. This may result in worse denoising quality in some cases. (default = 0)"),
	ECVF_RenderThreadSafe
);

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

Scope: file

Source code excerpt:

		CommonPassParameters->LODTransitionEnd = CVarRayTracingShadowsLODTransitionEnd.GetValueOnRenderThread();
		CommonPassParameters->AvoidSelfIntersectionTraceDistance = GRayTracingShadowsAvoidSelfIntersectionTraceDistance;
		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;