r.RayTracing.SkyLight.DecoupleSampleGeneration
r.RayTracing.SkyLight.DecoupleSampleGeneration
#Overview
name: r.RayTracing.SkyLight.DecoupleSampleGeneration
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Decouples sample generation from ray traversal (default = 1)
It is referenced in 8
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.RayTracing.SkyLight.DecoupleSampleGeneration is to control the decoupling of sample generation from ray traversal in the ray-traced skylight rendering process. This setting is part of Unreal Engine’s ray tracing system, specifically for skylight rendering.
The Unreal Engine subsystem that relies on this setting variable is the Renderer module, particularly the ray tracing component for skylights. This can be seen from the file path where the variable is defined and used: Engine/Source/Runtime/Renderer/Private/RayTracing/RaytracingSkylight.cpp
.
The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 1, meaning the sample generation is decoupled from ray traversal by default.
This variable interacts closely with its associated variable CVarRayTracingSkyLightDecoupleSampleGeneration
. They share the same value and are used interchangeably in the code.
Developers must be aware that this variable affects the performance and quality of ray-traced skylight rendering. When enabled (set to 1), it decouples the sample generation process from ray traversal, which can potentially improve performance or allow for more flexible rendering techniques.
Best practices when using this variable include:
- Understanding the performance implications of enabling or disabling this feature.
- Testing the visual quality and performance with both settings (0 and 1) to determine the best option for your specific use case.
- Considering the impact on different hardware configurations, as the performance benefit may vary.
Regarding the associated variable CVarRayTracingSkyLightDecoupleSampleGeneration
:
This is the actual console variable that controls the setting. It’s used to get the current value of the setting in various parts of the code, such as in the GetRayTracingSkyLightDecoupleSampleGenerationCVarValue()
function and in conditional statements throughout the skylight rendering process.
The variable is used to determine whether to generate sky light visibility rays separately, allocate appropriate buffers, and set up shader parameters. It affects the ray generation shader permutations and the storage of visibility ray data in the scene view state.
Developers should be aware that changing this variable at runtime will affect the skylight rendering process, potentially requiring reallocation of resources or changes in the rendering pipeline. Therefore, it’s important to set this value appropriately based on the desired balance between performance and quality, and to handle any potential changes in resource allocation that may result from modifying this setting.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/RayTracing/RaytracingSkylight.cpp:92
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarRayTracingSkyLightDecoupleSampleGeneration(
TEXT("r.RayTracing.SkyLight.DecoupleSampleGeneration"),
1,
TEXT("Decouples sample generation from ray traversal (default = 1)"),
ECVF_RenderThreadSafe
);
static TAutoConsoleVariable<int32> CVarRayTracingSkyLightEnableHairVoxel(
#Associated Variable and Callsites
This variable is associated with another variable named CVarRayTracingSkyLightDecoupleSampleGeneration
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/RayTracing/RaytracingSkylight.cpp:91
Scope: file
Source code excerpt:
);
static TAutoConsoleVariable<int32> CVarRayTracingSkyLightDecoupleSampleGeneration(
TEXT("r.RayTracing.SkyLight.DecoupleSampleGeneration"),
1,
TEXT("Decouples sample generation from ray traversal (default = 1)"),
ECVF_RenderThreadSafe
);
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/RayTracing/RaytracingSkylight.cpp:114
Scope (from outer to inner):
file
function int32 GetRayTracingSkyLightDecoupleSampleGenerationCVarValue
Source code excerpt:
int32 GetRayTracingSkyLightDecoupleSampleGenerationCVarValue()
{
return CVarRayTracingSkyLightDecoupleSampleGeneration.GetValueOnRenderThread();
}
int32 GetSkyLightSamplesPerPixel(const FSkyLightSceneProxy* SkyLightSceneProxy)
{
check(SkyLightSceneProxy != nullptr);
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/RayTracing/RaytracingSkylight.cpp:191
Scope (from outer to inner):
file
function void SetupSkyLightVisibilityRaysParameters
Source code excerpt:
(SceneViewState != nullptr) &&
(SceneViewState->SkyLightVisibilityRaysBuffer != nullptr) &&
(CVarRayTracingSkyLightDecoupleSampleGeneration.GetValueOnRenderThread() == 1))
{
// Set the Sky Light Visibility Ray pooled buffer to the stored pooled buffer
SkyLightVisibilityRaysBuffer = GraphBuilder.RegisterExternalBuffer(SceneViewState->SkyLightVisibilityRaysBuffer);
// Set the Sky Light Visibility Ray Dimensions from the stored dimensions
SkyLightVisibilityRaysDimensions = SceneViewState->SkyLightVisibilityRaysDimensions;
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/RayTracing/RaytracingSkylight.cpp:408
Scope (from outer to inner):
file
function void FDeferredShadingSceneRenderer::RenderRayTracingSkyLight
Source code excerpt:
FRDGBufferRef SkyLightVisibilityRaysBuffer;
FIntVector SkyLightVisibilityRaysDimensions;
if (CVarRayTracingSkyLightDecoupleSampleGeneration.GetValueOnRenderThread() == 1)
{
GenerateSkyLightVisibilityRays(GraphBuilder, Views[0], SkylightParameters, SkyLightData, SkyLightVisibilityRaysBuffer, SkyLightVisibilityRaysDimensions);
}
else
{
FRDGBufferDesc BufferDesc = FRDGBufferDesc::CreateStructuredDesc(sizeof(FSkyLightVisibilityRays), 1);
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/RayTracing/RaytracingSkylight.cpp:440
Scope (from outer to inner):
file
function void FDeferredShadingSceneRenderer::RenderRayTracingSkyLight
Source code excerpt:
PassParameters->SkyLightData = CreateUniformBufferImmediate(SkyLightData, EUniformBufferUsage::UniformBuffer_SingleDraw);
PassParameters->SkyLightVisibilityRaysData.SkyLightVisibilityRaysDimensions = SkyLightVisibilityRaysDimensions;
if (CVarRayTracingSkyLightDecoupleSampleGeneration.GetValueOnRenderThread() == 1)
{
PassParameters->SkyLightVisibilityRaysData.SkyLightVisibilityRays = GraphBuilder.CreateSRV(SkyLightVisibilityRaysBuffer, EPixelFormat::PF_R32_UINT);
}
PassParameters->SceneTextures = SceneTextures;
PassParameters->UpscaleFactor = UpscaleFactor;
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/RayTracing/RaytracingSkylight.cpp:462
Scope (from outer to inner):
file
function void FDeferredShadingSceneRenderer::RenderRayTracingSkyLight
Source code excerpt:
PermutationVector.Set<FRayTracingSkyLightRGS::FEnableTwoSidedGeometryDim>(CVarRayTracingSkyLightEnableTwoSidedGeometry.GetValueOnRenderThread() != 0);
PermutationVector.Set<FRayTracingSkyLightRGS::FEnableMaterialsDim>(CVarRayTracingSkyLightEnableMaterials.GetValueOnRenderThread() != 0);
PermutationVector.Set<FRayTracingSkyLightRGS::FDecoupleSampleGeneration>(CVarRayTracingSkyLightDecoupleSampleGeneration.GetValueOnRenderThread() != 0);
PermutationVector.Set<FRayTracingSkyLightRGS::FHairLighting>(bUseHairLighting ? 1 : 0);
TShaderMapRef<FRayTracingSkyLightRGS> RayGenerationShader(GetGlobalShaderMap(FeatureLevel), PermutationVector);
ClearUnusedGraphResources(RayGenerationShader, PassParameters);
FIntPoint RayTracingResolution = View.ViewRect.Size() / UpscaleFactor;
GraphBuilder.AddPass(
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/RayTracing/RaytracingSkylight.cpp:539
Scope (from outer to inner):
file
function void FDeferredShadingSceneRenderer::RenderRayTracingSkyLight
Source code excerpt:
if (SceneViewState != nullptr)
{
if (CVarRayTracingSkyLightDecoupleSampleGeneration.GetValueOnRenderThread() == 1)
{
// Set the Sky Light Visibility Ray dimensions and its extracted pooled RDG buffer on the scene view state
GraphBuilder.QueueBufferExtraction(SkyLightVisibilityRaysBuffer, &SceneViewState->SkyLightVisibilityRaysBuffer);
SceneViewState->SkyLightVisibilityRaysDimensions = SkyLightVisibilityRaysDimensions;
}
else