forked from NVIDIA/Q2RTX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
global_ubo.h
297 lines (266 loc) · 16.3 KB
/
global_ubo.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
/*
Copyright (C) 2018 Christoph Schied
Copyright (C) 2019, NVIDIA CORPORATION. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef _GLOBAL_UBO_DESCRIPTOR_SET_LAYOUT_H_
#define _GLOBAL_UBO_DESCRIPTOR_SET_LAYOUT_H_
#include "constants.h"
#define GLOBAL_UBO_BINDING_IDX 0
#define GLOBAL_INSTANCE_BUFFER_BINDING_IDX 1
#define UBO_CVAR_DO(name, default_value) GLOBAL_UBO_VAR_LIST_DO(float, name)
// The variables listed in UBO_CVAR_LIST are registered as console variables and copied directly into the UBO.
// See main.c for the implementation of that.
// Variables that have "_lf", "_hf" or "_spec" suffix apply to the low-frequency, high-frequency or specular lighting channels, respectively.
#define UBO_CVAR_LIST \
UBO_CVAR_DO(flt_antilag_hf, 1) /* A-SVGF anti-lag filter strength, [0..inf) */ \
UBO_CVAR_DO(flt_antilag_lf, 0.2) \
UBO_CVAR_DO(flt_antilag_spec, 2) \
UBO_CVAR_DO(flt_atrous_depth, 0.5) /* wavelet fitler sensitivity to depth, [0..inf) */ \
UBO_CVAR_DO(flt_atrous_deflicker_lf, 2) /* max brightness difference between adjacent pixels in the LF channel, (0..inf) */ \
UBO_CVAR_DO(flt_atrous_hf, 4) /* number of a-trous wavelet filter iterations on the LF channel, [0..4] */ \
UBO_CVAR_DO(flt_atrous_lf, 4) \
UBO_CVAR_DO(flt_atrous_spec, 3) \
UBO_CVAR_DO(flt_atrous_lum_hf, 16) /* wavelet filter sensitivity to luminance, [0..inf) */ \
UBO_CVAR_DO(flt_atrous_normal_hf, 64) /* wavelet filter sensitivity to normals, [0..inf) */ \
UBO_CVAR_DO(flt_atrous_normal_lf, 8) \
UBO_CVAR_DO(flt_atrous_normal_spec, 1) \
UBO_CVAR_DO(flt_enable, 1) /* switch for the entire SVGF reconstruction, 0 or 1 */ \
UBO_CVAR_DO(flt_fixed_albedo, 0) /* if nonzero, replaces surface albedo with that value after filtering */ \
UBO_CVAR_DO(flt_grad_transparent, 0.3) /* gradient scale for reflections and refractions, [0..1] */ \
UBO_CVAR_DO(flt_min_alpha_color_hf, 0.1) /* minimum weight for the new frame data, color channel, (0..1] */ \
UBO_CVAR_DO(flt_min_alpha_color_lf, 0.01) \
UBO_CVAR_DO(flt_min_alpha_color_spec, 0.1) \
UBO_CVAR_DO(flt_min_alpha_moments_hf, 0.01) /* minimum weight for the new frame data, moments channel, (0..1] */ \
UBO_CVAR_DO(flt_scale_hf, 1) /* overall per-channel output scale, [0..inf) */ \
UBO_CVAR_DO(flt_scale_lf, 1) \
UBO_CVAR_DO(flt_scale_overlay, 1.0) /* scale for transparent and emissive objects visible with primary rays */ \
UBO_CVAR_DO(flt_scale_spec, 1) \
UBO_CVAR_DO(flt_show_gradients, 0) /* switch for showing the gradient values as overlay image, 0 or 1 */ \
UBO_CVAR_DO(flt_taa, 1) /* switch for temporal AA, 0 or 1 */ \
UBO_CVAR_DO(flt_taa_anti_sparkle, 0.25) /* strength of the anti-sparkle filter of TAA, [0..1] */ \
UBO_CVAR_DO(flt_taa_variance, 0.7) /* temporal AA variance window scale, 0 means disable NCC, [0..inf) */ \
UBO_CVAR_DO(flt_taa_history_weight, 0.95) /* temporal AA weight of the history sample, [0..1) */ \
UBO_CVAR_DO(flt_temporal_hf, 1) /* temporal filter strength, [0..1] */ \
UBO_CVAR_DO(flt_temporal_lf, 1) \
UBO_CVAR_DO(flt_temporal_spec, 1) \
UBO_CVAR_DO(pt_aperture, 2.0) /* aperture size for the Depth of Field effect, in world units */ \
UBO_CVAR_DO(pt_aperture_angle, 0) /* rotation of the polygonal aperture, [0..1] */ \
UBO_CVAR_DO(pt_aperture_type, 0) /* number of aperture polygon edges, circular if less than 3 */ \
UBO_CVAR_DO(pt_beam_softness, 1.0) /* beam softness */ \
UBO_CVAR_DO(pt_bump_scale, 1.0) /* scale for normal maps [0..1] */ \
UBO_CVAR_DO(pt_cameras, 1) /* switch for security cameras, 0 or 1 */ \
UBO_CVAR_DO(pt_direct_polygon_lights, 1) /* switch for direct lighting from local polygon lights, 0 or 1 */ \
UBO_CVAR_DO(pt_direct_roughness_threshold, 0.18) /* roughness value where the path tracer switches direct light specular sampling from NDF based to light based, [0..1] */ \
UBO_CVAR_DO(pt_direct_area_threshold, 0.2) /* projected area of triangle light at which direct light sampling for specular is replaced with random sampling, [0..1] */ \
UBO_CVAR_DO(pt_direct_sphere_lights, 1) /* switch for direct lighting from local sphere lights, 0 or 1 */ \
UBO_CVAR_DO(pt_direct_sun_light, 1) /* switch for direct lighting from the sun, 0 or 1 */ \
UBO_CVAR_DO(pt_explosion_brightness, 4.0) /* brightness factor for explosions */ \
UBO_CVAR_DO(pt_fake_roughness_threshold, 0.20) /* roughness value where the path tracer starts switching indirect light specular sampling from NDF based to SH based, [0..1] */ \
UBO_CVAR_DO(pt_focus, 200) /* focal distance for the Depth of Field effect, in world units */ \
UBO_CVAR_DO(pt_indirect_polygon_lights, 1) /* switch for bounce lighting from local polygon lights, 0 or 1 */ \
UBO_CVAR_DO(pt_indirect_sphere_lights, 1) /* switch for bounce lighting from local sphere lights, 0 or 1 */ \
UBO_CVAR_DO(pt_light_stats, 1) /* switch for statistical light PDF correction, 0 or 1 */ \
UBO_CVAR_DO(pt_max_log_sky_luminance, -3) /* maximum sky luminance, log2 scale, used for polygon light selection, (-inf..inf) */ \
UBO_CVAR_DO(pt_min_log_sky_luminance, -10) /* minimum sky luminance, log2 scale, used for polygon light selection, (-inf..inf) */ \
UBO_CVAR_DO(pt_metallic_override, -1) /* overrides metallic parameter of all materials if non-negative, [0..1] */ \
UBO_CVAR_DO(pt_ndf_trim, 0.9) /* trim factor for GGX NDF sampling (0..1] */ \
UBO_CVAR_DO(pt_num_bounce_rays, 1) /* number of bounce rays, [1..inf) */ \
UBO_CVAR_DO(pt_particle_softness, 1.0) /* particle softness */ \
UBO_CVAR_DO(pt_reflect_refract, 2) /* number of reflection or refraction bounces: 0, 1 or 2 */ \
UBO_CVAR_DO(pt_roughness_override, -1) /* overrides roughness of all materials if non-negative, [0..1] */ \
UBO_CVAR_DO(pt_specular_anti_flicker, 2) /* fade factor for rough reflections of surfaces far away, [0..inf) */ \
UBO_CVAR_DO(pt_show_sky, 0) /* switch for showing the sky polygons, 0 or 1 */ \
UBO_CVAR_DO(pt_sun_bounce_range, 2000) /* range limiter for indirect lighting from the sun, helps reduce noise, (0..inf) */ \
UBO_CVAR_DO(pt_sun_specular, 1.0) /* scale for the direct specular reflection of the sun */ \
UBO_CVAR_DO(pt_texture_lod_bias, 0) /* LOD bias for textures, (-inf..inf) */ \
UBO_CVAR_DO(pt_toksvig, 1) /* intensity of Toksvig roughness correction, [0..inf) */ \
UBO_CVAR_DO(pt_thick_glass, 0) /* switch for thick glass refraction: 0 (disabled), 1 (reference mode only), 2 (real-time mode) */ \
UBO_CVAR_DO(pt_water_density, 0.5) /* scale for light extinction in water and other media, [0..inf) */ \
UBO_CVAR_DO(tm_debug, 0) /* switch to show the histogram (1) or tonemapping curve (2) */ \
UBO_CVAR_DO(tm_dyn_range_stops, 7.0) /* Effective display dynamic range in linear stops = log2((max+refl)/(darkest+refl)) (eqn. 6), (-inf..0) */ \
UBO_CVAR_DO(tm_enable, 1) /* switch for tone mapping, 0 or 1 */ \
UBO_CVAR_DO(tm_exposure_bias, -1.0) /* exposure bias, log-2 scale */ \
UBO_CVAR_DO(tm_exposure_speed_down, 1) /* speed of exponential eye adaptation when scene gets darker, 0 means instant */ \
UBO_CVAR_DO(tm_exposure_speed_up, 2) /* speed of exponential eye adaptation when scene gets brighter, 0 means instant */ \
UBO_CVAR_DO(tm_high_percentile, 90) /* high percentile for computing histogram average, (0..100] */ \
UBO_CVAR_DO(tm_knee_start, 0.6) /* where to switch from a linear to a rational function ramp in the post-tonemapping process, (0..1) */ \
UBO_CVAR_DO(tm_low_percentile, 70) /* low percentile for computing histogram average, [0..100) */ \
UBO_CVAR_DO(tm_max_luminance, 1.0) /* auto-exposure maximum luminance, (0..inf) */ \
UBO_CVAR_DO(tm_min_luminance, 0.0002) /* auto-exposure minimum luminance, (0..inf) */ \
UBO_CVAR_DO(tm_noise_blend, 0.5) /* Amount to blend noise values between autoexposed and flat image [0..1] */ \
UBO_CVAR_DO(tm_noise_stops, -12) /* Absolute noise level in photographic stops, (-inf..inf) */ \
UBO_CVAR_DO(tm_reinhard, 0.5) /* blend factor between adaptive curve tonemapper (0) and Reinhard curve (1) */ \
UBO_CVAR_DO(tm_slope_blur_sigma, 12.0) /* sigma for Gaussian blur of tone curve slopes, (0..inf) */ \
UBO_CVAR_DO(tm_white_point, 10.0) /* how bright colors can be before they become white, (0..inf) */ \
#define GLOBAL_UBO_VAR_LIST \
GLOBAL_UBO_VAR_LIST_DO(int, current_frame_idx) \
GLOBAL_UBO_VAR_LIST_DO(int, width) \
GLOBAL_UBO_VAR_LIST_DO(int, height)\
GLOBAL_UBO_VAR_LIST_DO(int, current_gpu_slice_width) \
\
GLOBAL_UBO_VAR_LIST_DO(int, medium) \
GLOBAL_UBO_VAR_LIST_DO(float, time) \
GLOBAL_UBO_VAR_LIST_DO(int, first_person_model) \
GLOBAL_UBO_VAR_LIST_DO(int, environment_type) \
\
GLOBAL_UBO_VAR_LIST_DO(vec3, sun_direction) \
GLOBAL_UBO_VAR_LIST_DO(float, bloom_intensity) \
GLOBAL_UBO_VAR_LIST_DO(vec3, sun_tangent) \
GLOBAL_UBO_VAR_LIST_DO(float, sun_tan_half_angle) \
GLOBAL_UBO_VAR_LIST_DO(vec3, sun_bitangent) \
GLOBAL_UBO_VAR_LIST_DO(float, sun_bounce_scale) \
GLOBAL_UBO_VAR_LIST_DO(vec3, sun_color) \
GLOBAL_UBO_VAR_LIST_DO(float, sun_cos_half_angle) \
GLOBAL_UBO_VAR_LIST_DO(vec3, sun_direction_envmap) \
GLOBAL_UBO_VAR_LIST_DO(int, sun_visible) \
\
GLOBAL_UBO_VAR_LIST_DO(float, sky_transmittance) \
GLOBAL_UBO_VAR_LIST_DO(float, sky_phase_g) \
GLOBAL_UBO_VAR_LIST_DO(float, sky_amb_phase_g) \
GLOBAL_UBO_VAR_LIST_DO(float, sun_solid_angle) \
\
GLOBAL_UBO_VAR_LIST_DO(vec3, physical_sky_ground_radiance) \
GLOBAL_UBO_VAR_LIST_DO(int, physical_sky_flags) \
\
GLOBAL_UBO_VAR_LIST_DO(float, sky_scattering) \
GLOBAL_UBO_VAR_LIST_DO(float, temporal_blend_factor) \
GLOBAL_UBO_VAR_LIST_DO(int, planet_albedo_map) \
GLOBAL_UBO_VAR_LIST_DO(int, planet_normal_map) \
\
GLOBAL_UBO_VAR_LIST_DO(int, num_sphere_lights) \
GLOBAL_UBO_VAR_LIST_DO(int , num_static_lights) \
GLOBAL_UBO_VAR_LIST_DO(int, num_static_primitives) \
GLOBAL_UBO_VAR_LIST_DO(int, cluster_debug_index) \
\
GLOBAL_UBO_VAR_LIST_DO(int, water_normal_texture) \
GLOBAL_UBO_VAR_LIST_DO(float, pt_env_scale) \
GLOBAL_UBO_VAR_LIST_DO(float, cylindrical_hfov) \
GLOBAL_UBO_VAR_LIST_DO(float, cylindrical_hfov_prev) \
\
GLOBAL_UBO_VAR_LIST_DO(int, pt_swap_checkerboard) \
GLOBAL_UBO_VAR_LIST_DO(float, shadow_map_depth_scale) \
GLOBAL_UBO_VAR_LIST_DO(float, god_rays_intensity) \
GLOBAL_UBO_VAR_LIST_DO(float, god_rays_eccentricity) \
\
GLOBAL_UBO_VAR_LIST_DO(int, num_cameras) \
GLOBAL_UBO_VAR_LIST_DO(int, screen_image_width) \
GLOBAL_UBO_VAR_LIST_DO(int, screen_image_height) \
GLOBAL_UBO_VAR_LIST_DO(int, prev_gpu_slice_width) \
\
GLOBAL_UBO_VAR_LIST_DO(int, prev_width) \
GLOBAL_UBO_VAR_LIST_DO(int, prev_height)\
GLOBAL_UBO_VAR_LIST_DO(float, inv_width)\
GLOBAL_UBO_VAR_LIST_DO(float, inv_height)\
\
GLOBAL_UBO_VAR_LIST_DO(float, prev_adapted_luminance) \
GLOBAL_UBO_VAR_LIST_DO(float, padding1) \
GLOBAL_UBO_VAR_LIST_DO(float, padding2) \
GLOBAL_UBO_VAR_LIST_DO(float, padding3) \
\
GLOBAL_UBO_VAR_LIST_DO(vec4, world_center) \
GLOBAL_UBO_VAR_LIST_DO(vec4, world_size) \
GLOBAL_UBO_VAR_LIST_DO(vec4, world_half_size_inv) \
\
GLOBAL_UBO_VAR_LIST_DO(vec4, sphere_light_data[MAX_LIGHT_SOURCES * 2]) \
GLOBAL_UBO_VAR_LIST_DO(vec4, cam_pos) \
GLOBAL_UBO_VAR_LIST_DO(mat4, V) \
GLOBAL_UBO_VAR_LIST_DO(mat4, invV) \
GLOBAL_UBO_VAR_LIST_DO(mat4, V_prev) \
GLOBAL_UBO_VAR_LIST_DO(mat4, P) \
GLOBAL_UBO_VAR_LIST_DO(mat4, invP) \
GLOBAL_UBO_VAR_LIST_DO(mat4, P_prev) \
GLOBAL_UBO_VAR_LIST_DO(mat4, invP_prev) \
GLOBAL_UBO_VAR_LIST_DO(mat4, environment_rotation_matrix) \
GLOBAL_UBO_VAR_LIST_DO(mat4, shadow_map_VP) \
GLOBAL_UBO_VAR_LIST_DO(mat4, security_camera_data[MAX_CAMERAS]) \
\
UBO_CVAR_LIST // WARNING: Do not put any other members into global_ubo after this: the CVAR list is not vec4-aligned
#define INSTANCE_BUFFER_VAR_LIST \
INSTANCE_BUFFER_VAR_LIST_DO(int, model_indices [SHADER_MAX_ENTITIES + SHADER_MAX_BSP_ENTITIES]) \
INSTANCE_BUFFER_VAR_LIST_DO(uint, model_current_to_prev [SHADER_MAX_ENTITIES]) \
INSTANCE_BUFFER_VAR_LIST_DO(uint, model_prev_to_current [SHADER_MAX_ENTITIES]) \
INSTANCE_BUFFER_VAR_LIST_DO(uint, world_current_to_prev [SHADER_MAX_BSP_ENTITIES]) \
INSTANCE_BUFFER_VAR_LIST_DO(uint, world_prev_to_current [SHADER_MAX_BSP_ENTITIES]) \
INSTANCE_BUFFER_VAR_LIST_DO(uint, bsp_prim_offset [SHADER_MAX_BSP_ENTITIES]) \
INSTANCE_BUFFER_VAR_LIST_DO(uint, model_idx_offset [SHADER_MAX_ENTITIES]) \
INSTANCE_BUFFER_VAR_LIST_DO(uint, model_cluster_id [SHADER_MAX_ENTITIES]) \
INSTANCE_BUFFER_VAR_LIST_DO(uint, model_cluster_id_prev [SHADER_MAX_ENTITIES]) \
INSTANCE_BUFFER_VAR_LIST_DO(uint, bsp_cluster_id [SHADER_MAX_BSP_ENTITIES]) \
INSTANCE_BUFFER_VAR_LIST_DO(uint, bsp_cluster_id_prev [SHADER_MAX_BSP_ENTITIES]) \
INSTANCE_BUFFER_VAR_LIST_DO(ModelInstance, model_instances [SHADER_MAX_ENTITIES]) \
INSTANCE_BUFFER_VAR_LIST_DO(ModelInstance, model_instances_prev [SHADER_MAX_ENTITIES]) \
INSTANCE_BUFFER_VAR_LIST_DO(BspMeshInstance, bsp_mesh_instances [SHADER_MAX_BSP_ENTITIES]) \
INSTANCE_BUFFER_VAR_LIST_DO(BspMeshInstance, bsp_mesh_instances_prev [SHADER_MAX_BSP_ENTITIES]) \
/* stores the offset into the instance buffer in numberof primitives */ \
INSTANCE_BUFFER_VAR_LIST_DO(uint, model_instance_buf_offset[SHADER_MAX_ENTITIES]) \
INSTANCE_BUFFER_VAR_LIST_DO(uint, model_instance_buf_size [SHADER_MAX_ENTITIES]) \
INSTANCE_BUFFER_VAR_LIST_DO(uint, bsp_instance_buf_offset [SHADER_MAX_BSP_ENTITIES]) \
INSTANCE_BUFFER_VAR_LIST_DO(uint, bsp_instance_buf_size [SHADER_MAX_BSP_ENTITIES]) \
#ifndef VKPT_SHADER
#if SHADER_MAX_ENTITIES != MAX_ENTITIES
#error need to update constant here
#endif
typedef uint32_t uvec4_t[4];
typedef int ivec4_t[4];
typedef uint32_t uint;
typedef struct {
float M[16]; // 16
uint32_t material; int offset_curr, offset_prev; float backlerp; // 4
float alpha; float padding[3];
} ModelInstance;
typedef struct {
float M[16];
int frame; float padding[3];
} BspMeshInstance;
#define int_t int32_t
typedef struct QVKUniformBuffer_s {
#define GLOBAL_UBO_VAR_LIST_DO(type, name) type##_t name;
GLOBAL_UBO_VAR_LIST
#undef GLOBAL_UBO_VAR_LIST_DO
} QVKUniformBuffer_t;
typedef struct QVKInstanceBuffer_s {
#define INSTANCE_BUFFER_VAR_LIST_DO(type, name) type name;
INSTANCE_BUFFER_VAR_LIST
#undef INSTANCE_BUFFER_VAR_LIST_DO
} QVKInstanceBuffer_t;
#undef int_t
#else
struct ModelInstance {
mat4 M;
uvec4 mat_offset_backlerp;
vec4 alpha;
};
struct BspMeshInstance {
mat4 M;
ivec4 frame;
};
struct GlobalUniformBuffer {
#define GLOBAL_UBO_VAR_LIST_DO(type, name) type name;
GLOBAL_UBO_VAR_LIST
#undef GLOBAL_UBO_VAR_LIST_DO
};
struct GlobalUniformInstanceBuffer {
#define INSTANCE_BUFFER_VAR_LIST_DO(type, name) type name;
INSTANCE_BUFFER_VAR_LIST
#undef INSTANCE_BUFFER_VAR_LIST_DO
};
layout(set = GLOBAL_UBO_DESC_SET_IDX, binding = GLOBAL_UBO_BINDING_IDX, std140) uniform UBO {
GlobalUniformBuffer global_ubo;
};
layout(set = GLOBAL_UBO_DESC_SET_IDX, binding = GLOBAL_INSTANCE_BUFFER_BINDING_IDX) readonly buffer InstanceUBO {
GlobalUniformInstanceBuffer instance_buffer;
};
#endif
#undef UBO_CVAR_DO
#endif /*_GLOBAL_UBO_DESCRIPTOR_SET_LAYOUT_H_*/