-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathShadeSamples.hlsl
87 lines (66 loc) · 3.3 KB
/
ShadeSamples.hlsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/***************************************************************************
# Copyright (c) 2020-2023, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION is strictly prohibited.
**************************************************************************/
#pragma pack_matrix(row_major)
#include "../RtxdiApplicationBridge/RtxdiApplicationBridge.hlsli"
#include "Rtxdi/DI/Reservoir.hlsli"
#if RTXDI_REGIR_MODE != RTXDI_REGIR_DISABLED
#include "Rtxdi/ReGIR/ReGIRSampling.hlsli"
#endif
#ifdef WITH_NRD
#define NRD_HEADER_ONLY
#include <NRDEncoding.hlsli>
#include <NRD.hlsli>
#endif
#include "../ShadingHelpers.hlsli"
#if USE_RAY_QUERY
[numthreads(RTXDI_SCREEN_SPACE_GROUP_SIZE, RTXDI_SCREEN_SPACE_GROUP_SIZE, 1)]
void main(uint2 GlobalIndex : SV_DispatchThreadID, uint2 LocalIndex : SV_GroupThreadID, uint2 GroupIdx : SV_GroupID)
#else
[shader("raygeneration")]
void RayGen()
#endif
{
#if !USE_RAY_QUERY
uint2 GlobalIndex = DispatchRaysIndex().xy;
#endif
const RTXDI_RuntimeParameters params = g_Const.runtimeParams;
uint2 pixelPosition = RTXDI_ReservoirPosToPixelPos(GlobalIndex, params.activeCheckerboardField);
RAB_Surface surface = RAB_GetGBufferSurface(pixelPosition, false);
RTXDI_DIReservoir reservoir = RTXDI_LoadDIReservoir(g_Const.restirDI.reservoirBufferParams, GlobalIndex, g_Const.restirDI.bufferIndices.shadingInputBufferIndex);
float3 diffuse = 0;
float3 specular = 0;
float lightDistance = 0;
float2 currLuminance = 0;
if (RTXDI_IsValidDIReservoir(reservoir))
{
RAB_LightInfo lightInfo = RAB_LoadLightInfo(RTXDI_GetDIReservoirLightIndex(reservoir), false);
RAB_LightSample lightSample = RAB_SamplePolymorphicLight(lightInfo,
surface, RTXDI_GetDIReservoirSampleUV(reservoir));
bool needToStore = ShadeSurfaceWithLightSample(reservoir, surface, lightSample,
/* previousFrameTLAS = */ false, /* enableVisibilityReuse = */ true, diffuse, specular, lightDistance);
currLuminance = float2(calcLuminance(diffuse * surface.material.diffuseAlbedo), calcLuminance(specular));
specular = DemodulateSpecular(surface.material.specularF0, specular);
if (needToStore)
{
RTXDI_StoreDIReservoir(reservoir, g_Const.restirDI.reservoirBufferParams, GlobalIndex, g_Const.restirDI.bufferIndices.shadingInputBufferIndex);
}
}
// Store the sampled lighting luminance for the gradient pass.
// Discard the pixels where the visibility was reused, as gradients need actual visibility.
u_RestirLuminance[GlobalIndex] = currLuminance * (reservoir.age > 0 ? 0 : 1);
#if RTXDI_REGIR_MODE != RTXDI_REGIR_DISABLED
if (g_Const.visualizeRegirCells)
{
diffuse *= RTXDI_VisualizeReGIRCells(g_Const.regir, RAB_GetSurfaceWorldPos(surface));
}
#endif
StoreShadingOutput(GlobalIndex, pixelPosition,
surface.viewDepth, surface.material.roughness, diffuse, specular, lightDistance, true, g_Const.restirDI.shadingParams.enableDenoiserInputPacking);
}