-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathShaderParameters.h
313 lines (253 loc) · 7.93 KB
/
ShaderParameters.h
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/***************************************************************************
# 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.
**************************************************************************/
#ifndef SHADER_PARAMETERS_H
#define SHADER_PARAMETERS_H
#include <donut/shaders/view_cb.h>
#include <donut/shaders/sky_cb.h>
#include <Rtxdi/DI/ReSTIRDIParameters.h>
#include <Rtxdi/GI/ReSTIRGIParameters.h>
#include <Rtxdi/ReGIR/ReGIRParameters.h>
#include "BRDFPTParameters.h"
#define TASK_PRIMITIVE_LIGHT_BIT 0x80000000u
#define RTXDI_PRESAMPLING_GROUP_SIZE 256
#define RTXDI_GRID_BUILD_GROUP_SIZE 256
#define RTXDI_SCREEN_SPACE_GROUP_SIZE 8
#define RTXDI_GRAD_FACTOR 3
#define RTXDI_GRAD_STORAGE_SCALE 256.0f
#define RTXDI_GRAD_MAX_VALUE 65504.0f
#define INSTANCE_MASK_OPAQUE 0x01
#define INSTANCE_MASK_ALPHA_TESTED 0x02
#define INSTANCE_MASK_TRANSPARENT 0x04
#define INSTANCE_MASK_ALL 0xFF
#define DENOISER_MODE_OFF 0
#define DENOISER_MODE_REBLUR 1
#define DENOISER_MODE_RELAX 2
#define VIS_MODE_NONE 0
#define VIS_MODE_COMPOSITED_COLOR 1
#define VIS_MODE_RESOLVED_COLOR 2
#define VIS_MODE_DIFFUSE 3
#define VIS_MODE_SPECULAR 4
#define VIS_MODE_DENOISED_DIFFUSE 5
#define VIS_MODE_DENOISED_SPECULAR 6
#define VIS_MODE_RESERVOIR_WEIGHT 7
#define VIS_MODE_RESERVOIR_M 8
#define VIS_MODE_DIFFUSE_GRADIENT 9
#define VIS_MODE_SPECULAR_GRADIENT 10
#define VIS_MODE_DIFFUSE_CONFIDENCE 11
#define VIS_MODE_SPECULAR_CONFIDENCE 12
#define VIS_MODE_GI_WEIGHT 13
#define VIS_MODE_GI_M 14
#define BACKGROUND_DEPTH 65504.f
#define RAY_COUNT_TRACED(index) ((index) * 2)
#define RAY_COUNT_HITS(index) ((index) * 2 + 1)
#define REPORT_RAY(hit) if (g_PerPassConstants.rayCountBufferIndex >= 0) { \
InterlockedAdd(u_RayCountBuffer[RAY_COUNT_TRACED(g_PerPassConstants.rayCountBufferIndex)], 1); \
if (hit) InterlockedAdd(u_RayCountBuffer[RAY_COUNT_HITS(g_PerPassConstants.rayCountBufferIndex)], 1); }
struct BrdfRayTracingConstants
{
PlanarViewConstants view;
uint frameIndex;
};
struct PrepareLightsConstants
{
uint numTasks;
uint currentFrameLightOffset;
uint previousFrameLightOffset;
};
struct PrepareLightsTask
{
uint instanceAndGeometryIndex; // low 12 bits are geometryIndex, mid 19 bits are instanceIndex, high bit is TASK_PRIMITIVE_LIGHT_BIT
uint triangleCount;
uint lightBufferOffset;
int previousLightBufferOffset; // -1 means no previous data
};
struct RenderEnvironmentMapConstants
{
ProceduralSkyShaderParameters params;
float2 invTextureSize;
};
struct PreprocessEnvironmentMapConstants
{
uint2 sourceSize;
uint sourceMipLevel;
uint numDestMipLevels;
};
struct GBufferConstants
{
PlanarViewConstants view;
PlanarViewConstants viewPrev;
float roughnessOverride;
float metalnessOverride;
float normalMapScale;
uint enableAlphaTestedGeometry;
int2 materialReadbackPosition;
uint materialReadbackBufferIndex;
uint enableTransparentGeometry;
float textureLodBias;
float textureGradientScale; // 2^textureLodBias
};
struct GlassConstants
{
PlanarViewConstants view;
uint enableEnvironmentMap;
uint environmentMapTextureIndex;
float environmentScale;
float environmentRotation;
int2 materialReadbackPosition;
uint materialReadbackBufferIndex;
float normalMapScale;
};
struct CompositingConstants
{
PlanarViewConstants view;
PlanarViewConstants viewPrev;
uint enableTextures;
uint denoiserMode;
uint enableEnvironmentMap;
uint environmentMapTextureIndex;
float environmentScale;
float environmentRotation;
float noiseMix;
float noiseClampLow;
float noiseClampHigh;
uint checkerboard;
};
struct AccumulationConstants
{
float2 outputSize;
float2 inputSize;
float2 inputTextureSizeInv;
float2 pixelOffset;
float blendFactor;
};
struct FilterGradientsConstants
{
uint2 viewportSize;
int passIndex;
uint checkerboard;
};
struct ConfidenceConstants
{
uint2 viewportSize;
float2 invGradientTextureSize;
float darknessBias;
float sensitivity;
uint checkerboard;
int inputBufferIndex;
float blendFactor;
};
struct VisualizationConstants
{
RTXDI_RuntimeParameters runtimeParams;
RTXDI_ReservoirBufferParameters restirDIReservoirBufferParams;
RTXDI_ReservoirBufferParameters restirGIReservoirBufferParams;
int2 outputSize;
float2 resolutionScale;
uint visualizationMode;
uint inputBufferIndex;
uint enableAccumulation;
};
struct SceneConstants
{
uint enableEnvironmentMap; // Global. Affects BRDFRayTracing's GI code, plus RTXDI, ReGIR, etc.
uint environmentMapTextureIndex; // Global
float environmentScale;
float environmentRotation;
uint enableAlphaTestedGeometry;
uint enableTransparentGeometry;
uint2 pad1;
};
struct ResamplingConstants
{
PlanarViewConstants view;
PlanarViewConstants prevView;
RTXDI_RuntimeParameters runtimeParams;
float4 reblurDiffHitDistParams;
float4 reblurSpecHitDistParams;
uint frameIndex;
uint enablePreviousTLAS;
uint denoiserMode;
uint discountNaiveSamples;
uint enableBrdfIndirect;
uint enableBrdfAdditiveBlend;
uint enableAccumulation; // StoreShadingOutput
uint pad1;
SceneConstants sceneConstants;
// Common buffer params
RTXDI_LightBufferParameters lightBufferParams;
RTXDI_RISBufferSegmentParameters localLightsRISBufferSegmentParams;
RTXDI_RISBufferSegmentParameters environmentLightRISBufferSegmentParams;
// Algo-specific params
ReSTIRDI_Parameters restirDI;
ReGIR_Parameters regir;
ReSTIRGI_Parameters restirGI;
BRDFPathTracing_Parameters brdfPT;
uint visualizeRegirCells;
uint3 pad2;
uint2 environmentPdfTextureSize;
uint2 localLightPdfTextureSize;
};
struct PerPassConstants
{
int rayCountBufferIndex;
};
struct SecondaryGBufferData
{
float3 worldPos;
uint normal;
uint2 throughputAndFlags; // .x = throughput.rg as float16, .y = throughput.b as float16, flags << 16
uint diffuseAlbedo; // R11G11B10_UFLOAT
uint specularAndRoughness; // R8G8B8A8_Gamma_UFLOAT
float3 emission;
float pdf;
};
static const uint kSecondaryGBuffer_IsSpecularRay = 1;
static const uint kSecondaryGBuffer_IsDeltaSurface = 2;
static const uint kSecondaryGBuffer_IsEnvironmentMap = 4;
static const uint kPolymorphicLightTypeShift = 24;
static const uint kPolymorphicLightTypeMask = 0xf;
static const uint kPolymorphicLightShapingEnableBit = 1 << 28;
static const uint kPolymorphicLightIesProfileEnableBit = 1 << 29;
static const float kPolymorphicLightMinLog2Radiance = -8.f;
static const float kPolymorphicLightMaxLog2Radiance = 40.f;
#ifdef __cplusplus
enum class PolymorphicLightType
#else
enum PolymorphicLightType
#endif
{
kSphere = 0,
kCylinder,
kDisk,
kRect,
kTriangle,
kDirectional,
kEnvironment,
kPoint
};
// Stores shared light information (type) and specific light information
// See PolymorphicLight.hlsli for encoding format
struct PolymorphicLightInfo
{
// uint4[0]
float3 center;
uint colorTypeAndFlags; // RGB8 + uint8 (see the kPolymorphicLight... constants above)
// uint4[1]
uint direction1; // oct-encoded
uint direction2; // oct-encoded
uint scalars; // 2x float16
uint logRadiance; // uint16
// uint4[2] -- optional, contains only shaping data
uint iesProfileIndex;
uint primaryAxis; // oct-encoded
uint cosConeAngleAndSoftness; // 2x float16
uint padding;
};
#endif // SHADER_PARAMETERS_H