r.RayTracing.Shadows.AcceptFirstHit
r.RayTracing.Shadows.AcceptFirstHit
#Overview
name: r.RayTracing.Shadows.AcceptFirstHit
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Whether to allow shadow rays to terminate early, on first intersected primitive. This may result in worse denoising quality in some cases. (default = 0)
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:
- Testing the visual quality with both settings (0 and 1) in your specific scenes.
- Consider disabling it (setting to 0) for final renders or in scenes where shadow quality is crucial.
- Be mindful of the performance-quality tradeoff, especially in real-time applications.
Regarding the associated variable CVarRayTracingShadowsAcceptFirstHit:
- Its purpose is identical to r.RayTracing.Shadows.AcceptFirstHit, serving as the internal representation of the console variable.
- It’s used within the rendering system to actually control the behavior of the shadow ray tracing.
- Its value is set by the console variable system and can be accessed in C++ code using GetValueOnRenderThread().
- It interacts directly with the CommonPassParameters struct, setting the bAcceptFirstHit parameter for the ray tracing pass.
- Developers should be aware that this variable is used in the render thread, so any changes to it should be thread-safe.
- Best practices include using the appropriate getter methods (GetValueOnRenderThread) when accessing its value in render code.
#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;