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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
|
/*************************************************************************/
/* rasterizer_effects_rd.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef RASTERIZER_EFFECTS_RD_H
#define RASTERIZER_EFFECTS_RD_H
#include "core/math/camera_matrix.h"
#include "render_pipeline_vertex_format_cache_rd.h"
#include "servers/visual/rasterizer_rd/shaders/blur.glsl.gen.h"
#include "servers/visual/rasterizer_rd/shaders/bokeh_dof.glsl.gen.h"
#include "servers/visual/rasterizer_rd/shaders/copy.glsl.gen.h"
#include "servers/visual/rasterizer_rd/shaders/cubemap_downsampler.glsl.gen.h"
#include "servers/visual/rasterizer_rd/shaders/cubemap_filter.glsl.gen.h"
#include "servers/visual/rasterizer_rd/shaders/cubemap_roughness.glsl.gen.h"
#include "servers/visual/rasterizer_rd/shaders/luminance_reduce.glsl.gen.h"
#include "servers/visual/rasterizer_rd/shaders/roughness_limiter.glsl.gen.h"
#include "servers/visual/rasterizer_rd/shaders/sky.glsl.gen.h"
#include "servers/visual/rasterizer_rd/shaders/ssao.glsl.gen.h"
#include "servers/visual/rasterizer_rd/shaders/ssao_blur.glsl.gen.h"
#include "servers/visual/rasterizer_rd/shaders/ssao_minify.glsl.gen.h"
#include "servers/visual/rasterizer_rd/shaders/tonemap.glsl.gen.h"
#include "servers/visual_server.h"
class RasterizerEffectsRD {
enum BlurMode {
BLUR_MODE_GAUSSIAN_BLUR,
BLUR_MODE_GAUSSIAN_GLOW,
BLUR_MODE_GAUSSIAN_GLOW_AUTO_EXPOSURE,
BLUR_MODE_DOF_NEAR_LOW,
BLUR_MODE_DOF_NEAR_MEDIUM,
BLUR_MODE_DOF_NEAR_HIGH,
BLUR_MODE_DOF_NEAR_MERGE_LOW,
BLUR_MODE_DOF_NEAR_MERGE_MEDIUM,
BLUR_MODE_DOF_NEAR_MERGE_HIGH,
BLUR_MODE_DOF_FAR_LOW,
BLUR_MODE_DOF_FAR_MEDIUM,
BLUR_MODE_DOF_FAR_HIGH,
BLUR_MODE_SSAO_MERGE,
BLUR_MODE_SIMPLY_COPY,
BLUR_MODE_MIPMAP,
BLUR_MODE_MAX,
};
enum {
BLUR_FLAG_HORIZONTAL = (1 << 0),
BLUR_FLAG_USE_BLUR_SECTION = (1 << 1),
BLUR_FLAG_USE_ORTHOGONAL_PROJECTION = (1 << 2),
BLUR_FLAG_DOF_NEAR_FIRST_TAP = (1 << 3),
BLUR_FLAG_GLOW_FIRST_PASS = (1 << 4),
BLUR_FLAG_FLIP_Y = (1 << 5),
BLUR_COPY_FORCE_LUMINANCE = (1 << 6)
};
struct BlurPushConstant {
float section[4];
float pixel_size[2];
uint32_t flags;
uint32_t pad;
//glow
float glow_strength;
float glow_bloom;
float glow_hdr_threshold;
float glow_hdr_scale;
float glow_exposure;
float glow_white;
float glow_luminance_cap;
float glow_auto_exposure_grey;
//dof
float dof_begin;
float dof_end;
float dof_radius;
float dof_pad;
float dof_dir[2];
float camera_z_far;
float camera_z_near;
float ssao_color[4];
};
struct Blur {
BlurPushConstant push_constant;
BlurShaderRD shader;
RID shader_version;
RenderPipelineVertexFormatCacheRD pipelines[BLUR_MODE_MAX];
} blur;
enum CubemapRoughnessSource {
CUBEMAP_ROUGHNESS_SOURCE_PANORAMA,
CUBEMAP_ROUGHNESS_SOURCE_CUBEMAP,
CUBEMAP_ROUGHNESS_SOURCE_MAX
};
struct CubemapRoughnessPushConstant {
uint32_t face_id;
uint32_t sample_count;
float roughness;
uint32_t use_direct_write;
};
struct CubemapRoughness {
CubemapRoughnessPushConstant push_constant;
CubemapRoughnessShaderRD shader;
RID shader_version;
RenderPipelineVertexFormatCacheRD pipelines[CUBEMAP_ROUGHNESS_SOURCE_MAX];
} roughness;
struct SkyPushConstant {
float orientation[12];
float proj[4];
float multiplier;
float alpha;
float depth;
float pad;
};
struct Sky {
SkyPushConstant push_constant;
SkyShaderRD shader;
RID shader_version;
RenderPipelineVertexFormatCacheRD pipeline;
} sky;
enum TonemapMode {
TONEMAP_MODE_NORMAL,
TONEMAP_MODE_BICUBIC_GLOW_FILTER,
TONEMAP_MODE_MAX
};
struct TonemapPushConstant {
float bcs[3];
uint32_t use_bcs;
uint32_t use_glow;
uint32_t use_auto_exposure;
uint32_t use_color_correction;
uint32_t tonemapper;
uint32_t glow_texture_size[2];
float glow_intensity;
uint32_t glow_level_flags;
uint32_t glow_mode;
float exposure;
float white;
float auto_exposure_grey;
};
struct Tonemap {
TonemapPushConstant push_constant;
TonemapShaderRD shader;
RID shader_version;
RenderPipelineVertexFormatCacheRD pipelines[TONEMAP_MODE_MAX];
} tonemap;
enum LuminanceReduceMode {
LUMINANCE_REDUCE_READ,
LUMINANCE_REDUCE,
LUMINANCE_REDUCE_WRITE,
LUMINANCE_REDUCE_MAX
};
struct LuminanceReducePushConstant {
int32_t source_size[2];
float max_luminance;
float min_luminance;
float exposure_adjust;
float pad[3];
};
struct LuminanceReduce {
LuminanceReducePushConstant push_constant;
LuminanceReduceShaderRD shader;
RID shader_version;
RID pipelines[LUMINANCE_REDUCE_MAX];
} luminance_reduce;
struct CopyToDPPushConstant {
float bias;
float z_far;
float z_near;
uint32_t z_flip;
};
enum CopyMode {
COPY_MODE_CUBE_TO_DP,
COPY_MODE_MAX
};
struct Copy {
CopyShaderRD shader;
RID shader_version;
RenderPipelineVertexFormatCacheRD pipelines[COPY_MODE_MAX];
} copy;
struct BokehPushConstant {
uint32_t size[2];
float z_far;
float z_near;
uint32_t orthogonal;
float blur_size;
float blur_scale;
uint32_t steps;
uint32_t blur_near_active;
float blur_near_begin;
float blur_near_end;
uint32_t blur_far_active;
float blur_far_begin;
float blur_far_end;
uint32_t second_pass;
uint32_t half_size;
uint32_t use_jitter;
float jitter_seed;
uint32_t pad[2];
};
enum BokehMode {
BOKEH_GEN_BLUR_SIZE,
BOKEH_GEN_BOKEH_BOX,
BOKEH_GEN_BOKEH_HEXAGONAL,
BOKEH_GEN_BOKEH_CIRCULAR,
BOKEH_COMPOSITE,
BOKEH_MAX
};
struct Bokeh {
BokehPushConstant push_constant;
BokehDofShaderRD shader;
RID shader_version;
RID pipelines[BOKEH_MAX];
} bokeh;
enum SSAOMode {
SSAO_MINIFY_FIRST,
SSAO_MINIFY_MIPMAP,
SSAO_GATHER_LOW,
SSAO_GATHER_MEDIUM,
SSAO_GATHER_HIGH,
SSAO_GATHER_ULTRA,
SSAO_GATHER_LOW_HALF,
SSAO_GATHER_MEDIUM_HALF,
SSAO_GATHER_HIGH_HALF,
SSAO_GATHER_ULTRA_HALF,
SSAO_BLUR_PASS,
SSAO_BLUR_PASS_HALF,
SSAO_BLUR_UPSCALE,
SSAO_MAX
};
struct SSAOMinifyPushConstant {
float pixel_size[2];
float z_far;
float z_near;
int32_t source_size[2];
uint32_t orthogonal;
uint32_t pad;
};
struct SSAOGatherPushConstant {
int32_t screen_size[2];
float z_far;
float z_near;
uint32_t orthogonal;
float intensity_div_r6;
float radius;
float bias;
float proj_info[4];
float pixel_size[2];
float proj_scale;
uint32_t pad;
};
struct SSAOBlurPushConstant {
float edge_sharpness;
int32_t filter_scale;
float z_far;
float z_near;
uint32_t orthogonal;
uint32_t pad[3];
int32_t axis[2];
int32_t screen_size[2];
};
struct SSAO {
SSAOMinifyPushConstant minify_push_constant;
SsaoMinifyShaderRD minify_shader;
RID minify_shader_version;
SSAOGatherPushConstant gather_push_constant;
SsaoShaderRD gather_shader;
RID gather_shader_version;
SSAOBlurPushConstant blur_push_constant;
SsaoBlurShaderRD blur_shader;
RID blur_shader_version;
RID pipelines[SSAO_MAX];
} ssao;
struct RoughnessLimiterPushConstant {
int32_t screen_size[2];
float curve;
uint32_t pad;
};
struct RoughnessLimiter {
RoughnessLimiterPushConstant push_constant;
RoughnessLimiterShaderRD shader;
RID shader_version;
RID pipeline;
} roughness_limiter;
enum CubemapDownsamplerSource {
CUBEMAP_DOWNSAMPLER_SOURCE_PANORAMA,
CUBEMAP_DOWNSAMPLER_SOURCE_CUBEMAP,
CUBEMAP_DOWNSAMPLER_SOURCE_MAX
};
struct CubemapDownsamplerPushConstant {
uint32_t face_size;
float pad[3];
};
struct CubemapDownsampler {
CubemapDownsamplerPushConstant push_constant;
CubemapDownsamplerShaderRD shader;
RID shader_version;
RID pipelines[CUBEMAP_DOWNSAMPLER_SOURCE_MAX];
} cubemap_downsampler;
enum CubemapFilterMode {
FILTER_MODE_HIGH_QUALITY,
FILTER_MODE_LOW_QUALITY,
FILTER_MODE_HIGH_QUALITY_ARRAY,
FILTER_MODE_LOW_QUALITY_ARRAY,
FILTER_MODE_MAX,
};
struct CubemapFilter {
CubemapFilterShaderRD shader;
RID shader_version;
RID pipelines[FILTER_MODE_MAX];
RID uniform_set;
RID coefficient_buffer;
bool use_high_quality;
} filter;
RID default_sampler;
RID default_mipmap_sampler;
RID index_buffer;
RID index_array;
Map<RID, RID> texture_to_uniform_set_cache;
Map<RID, RID> image_to_uniform_set_cache;
Map<RID, RID> texture_to_compute_uniform_set_cache;
RID _get_uniform_set_from_image(RID p_texture);
RID _get_uniform_set_from_texture(RID p_texture, bool p_use_mipmaps = false);
RID _get_compute_uniform_set_from_texture(RID p_texture, bool p_use_mipmaps = false);
public:
//TODO must re-do most of the shaders in compute
void region_copy(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2 &p_region);
void copy_to_rect(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2 &p_rect, bool p_flip_y = false, bool p_force_luminance = false);
void gaussian_blur(RID p_source_rd_texture, RID p_framebuffer_half, RID p_rd_texture_half, RID p_dest_framebuffer, const Vector2 &p_pixel_size, const Rect2 &p_region);
void gaussian_glow(RID p_source_rd_texture, RID p_framebuffer_half, RID p_rd_texture_half, RID p_dest_framebuffer, const Vector2 &p_pixel_size, float p_strength = 1.0, bool p_first_pass = false, float p_luminance_cap = 16.0, float p_exposure = 1.0, float p_bloom = 0.0, float p_hdr_bleed_treshold = 1.0, float p_hdr_bleed_scale = 1.0, RID p_auto_exposure = RID(), float p_auto_exposure_grey = 1.0);
void cubemap_roughness(RID p_source_rd_texture, bool p_source_is_panorama, RID p_dest_framebuffer, uint32_t p_face_id, uint32_t p_sample_count, float p_roughness);
void render_panorama(RD::DrawListID p_list, RenderingDevice::FramebufferFormatID p_fb_format, RID p_panorama, const CameraMatrix &p_camera, const Basis &p_orientation, float p_alpha, float p_multipler);
void make_mipmap(RID p_source_rd_texture, RID p_framebuffer_half, const Vector2 &p_pixel_size);
void copy_cubemap_to_dp(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2 &p_rect, float p_z_near, float p_z_far, float p_bias, bool p_dp_flip);
void luminance_reduction(RID p_source_texture, const Size2i p_source_size, const Vector<RID> p_reduce, RID p_prev_luminance, float p_min_luminance, float p_max_luminance, float p_adjust, bool p_set = false);
void bokeh_dof(RID p_base_texture, RID p_depth_texture, const Size2i &p_base_texture_size, RID p_secondary_texture, RID p_bokeh_texture1, RID p_bokeh_texture2, bool p_dof_far, float p_dof_far_begin, float p_dof_far_size, bool p_dof_near, float p_dof_near_begin, float p_dof_near_size, float p_bokeh_size, VS::DOFBokehShape p_bokeh_shape, VS::DOFBlurQuality p_quality, bool p_use_jitter, float p_cam_znear, float p_cam_zfar, bool p_cam_orthogonal);
struct TonemapSettings {
bool use_glow = false;
enum GlowMode {
GLOW_MODE_ADD,
GLOW_MODE_SCREEN,
GLOW_MODE_SOFTLIGHT,
GLOW_MODE_REPLACE,
GLOW_MODE_MIX
};
GlowMode glow_mode = GLOW_MODE_ADD;
float glow_intensity = 1.0;
uint32_t glow_level_flags = 0;
Vector2i glow_texture_size;
bool glow_use_bicubic_upscale = false;
RID glow_texture;
VS::EnvironmentToneMapper tonemap_mode = VS::ENV_TONE_MAPPER_LINEAR;
float exposure = 1.0;
float white = 1.0;
bool use_auto_exposure = false;
float auto_exposure_grey = 0.5;
RID exposure_texture;
bool use_bcs = false;
float brightness = 1.0;
float contrast = 1.0;
float saturation = 1.0;
bool use_color_correction = false;
RID color_correction_texture;
};
void tonemapper(RID p_source_color, RID p_dst_framebuffer, const TonemapSettings &p_settings);
void generate_ssao(RID p_depth_buffer, RID p_normal_buffer, const Size2i &p_depth_buffer_size, RID p_depth_mipmaps_texture, const Vector<RID> &depth_mipmaps, RID p_ao1, bool p_half_size, RID p_ao2, RID p_upscale_buffer, float p_intensity, float p_radius, float p_bias, const CameraMatrix &p_projection, VS::EnvironmentSSAOQuality p_quality, VS::EnvironmentSSAOBlur p_blur, float p_edge_sharpness);
void roughness_limit(RID p_source_normal, RID p_roughness, const Size2i &p_size, float p_curve);
void cubemap_downsample(RID p_source_cubemap, bool p_source_is_panorama, RID p_dest_cubemap, const Size2i &p_size);
void cubemap_filter(RID p_source_cubemap, Vector<RID> p_dest_cubemap, bool p_use_array);
RasterizerEffectsRD();
~RasterizerEffectsRD();
};
#endif // EFFECTS_RD_H
|