Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/servers/rendering/renderer_rd/effects/copy_effects.h
21420 views
1
/**************************************************************************/
2
/* copy_effects.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "servers/rendering/renderer_rd/pipeline_cache_rd.h"
34
#include "servers/rendering/renderer_rd/pipeline_deferred_rd.h"
35
#include "servers/rendering/renderer_rd/shaders/effects/blur_raster.glsl.gen.h"
36
#include "servers/rendering/renderer_rd/shaders/effects/copy.glsl.gen.h"
37
#include "servers/rendering/renderer_rd/shaders/effects/copy_to_fb.glsl.gen.h"
38
#include "servers/rendering/renderer_rd/shaders/effects/cube_to_dp.glsl.gen.h"
39
#include "servers/rendering/renderer_rd/shaders/effects/cube_to_octmap.glsl.gen.h"
40
#include "servers/rendering/renderer_rd/shaders/effects/octmap_downsampler.glsl.gen.h"
41
#include "servers/rendering/renderer_rd/shaders/effects/octmap_downsampler_raster.glsl.gen.h"
42
#include "servers/rendering/renderer_rd/shaders/effects/octmap_filter.glsl.gen.h"
43
#include "servers/rendering/renderer_rd/shaders/effects/octmap_filter_raster.glsl.gen.h"
44
#include "servers/rendering/renderer_rd/shaders/effects/octmap_roughness.glsl.gen.h"
45
#include "servers/rendering/renderer_rd/shaders/effects/octmap_roughness_raster.glsl.gen.h"
46
#include "servers/rendering/renderer_rd/shaders/effects/specular_merge.glsl.gen.h"
47
#include "servers/rendering/renderer_scene_render.h"
48
49
#include "servers/rendering/rendering_server.h"
50
51
namespace RendererRD {
52
53
class CopyEffects {
54
public:
55
enum RasterEffects {
56
RASTER_EFFECT_COPY = 1 << 0,
57
RASTER_EFFECT_GAUSSIAN_BLUR = 1 << 1,
58
RASTER_EFFECT_OCTMAP = 1 << 2,
59
};
60
61
private:
62
BitField<RasterEffects> raster_effects;
63
64
// Blur raster shader
65
66
enum BlurRasterMode {
67
BLUR_MIPMAP,
68
69
BLUR_MODE_GAUSSIAN_BLUR,
70
BLUR_MODE_GAUSSIAN_GLOW_GATHER,
71
BLUR_MODE_GAUSSIAN_GLOW_DOWNSAMPLE,
72
BLUR_MODE_GAUSSIAN_GLOW_UPSAMPLE,
73
BLUR_MODE_COPY,
74
75
BLUR_MODE_SET_COLOR,
76
77
BLUR_MODE_MAX
78
};
79
80
enum {
81
BLUR_FLAG_USE_ORTHOGONAL_PROJECTION = (1 << 1),
82
};
83
84
struct BlurRasterPushConstant {
85
float dest_pixel_size[2];
86
float source_pixel_size[2];
87
88
float pad[2];
89
uint32_t flags;
90
float level;
91
92
//glow
93
float glow_strength;
94
float glow_bloom;
95
float glow_hdr_threshold;
96
float glow_hdr_scale;
97
98
float glow_exposure;
99
float glow_white;
100
float glow_luminance_cap;
101
float luminance_multiplier;
102
};
103
104
struct BlurRaster {
105
BlurRasterPushConstant push_constant;
106
BlurRasterShaderRD shader;
107
RID shader_version;
108
PipelineCacheRD pipelines[BLUR_MODE_MAX];
109
RID glow_sampler;
110
} blur_raster;
111
112
// Copy shader
113
114
enum CopyMode {
115
COPY_MODE_GAUSSIAN_COPY,
116
COPY_MODE_GAUSSIAN_COPY_8BIT,
117
COPY_MODE_GAUSSIAN_GLOW,
118
COPY_MODE_GAUSSIAN_GLOW_AUTO_EXPOSURE,
119
COPY_MODE_SIMPLY_COPY,
120
COPY_MODE_SIMPLY_COPY_8BIT,
121
COPY_MODE_SIMPLY_COPY_DEPTH,
122
COPY_MODE_SET_COLOR,
123
COPY_MODE_SET_COLOR_8BIT,
124
COPY_MODE_MIPMAP,
125
COPY_MODE_LINEARIZE_DEPTH,
126
COPY_MODE_OCTMAP_TO_PANORAMA,
127
COPY_MODE_OCTMAP_ARRAY_TO_PANORAMA,
128
COPY_MODE_MAX,
129
130
};
131
132
enum {
133
COPY_FLAG_HORIZONTAL = (1 << 0),
134
COPY_FLAG_USE_COPY_SECTION = (1 << 1),
135
COPY_FLAG_USE_ORTHOGONAL_PROJECTION = (1 << 2),
136
COPY_FLAG_DOF_NEAR_FIRST_TAP = (1 << 3),
137
COPY_FLAG_GLOW_FIRST_PASS = (1 << 4),
138
COPY_FLAG_FLIP_Y = (1 << 5),
139
COPY_FLAG_FORCE_LUMINANCE = (1 << 6),
140
COPY_FLAG_ALL_SOURCE = (1 << 7),
141
COPY_FLAG_ALPHA_TO_ONE = (1 << 8),
142
COPY_FLAG_SANITIZE_INF_NAN = (1 << 9),
143
};
144
145
struct CopyPushConstant {
146
int32_t section[4];
147
int32_t target[2];
148
uint32_t flags;
149
float luminance_multiplier;
150
// Glow.
151
float glow_strength;
152
float glow_bloom;
153
float glow_hdr_threshold;
154
float glow_hdr_scale;
155
156
float glow_exposure;
157
float glow_white;
158
float glow_luminance_cap;
159
float glow_auto_exposure_scale;
160
// DOF.
161
float camera_z_far;
162
float camera_z_near;
163
// Octmap.
164
float octmap_border_size[2];
165
//SET color
166
float set_color[4];
167
};
168
169
struct Copy {
170
CopyPushConstant push_constant;
171
CopyShaderRD shader;
172
RID shader_version;
173
PipelineDeferredRD pipelines[COPY_MODE_MAX];
174
175
} copy;
176
177
// Copy to FB shader
178
179
enum CopyToFBMode {
180
COPY_TO_FB_COPY,
181
COPY_TO_FB_COPY_PANORAMA_TO_DP,
182
COPY_TO_FB_COPY2,
183
COPY_TO_FB_SET_COLOR,
184
185
// These variants are disabled unless XR shaders are enabled.
186
// They should be listed last.
187
COPY_TO_FB_MULTIVIEW,
188
COPY_TO_FB_MULTIVIEW_WITH_DEPTH,
189
190
COPY_TO_FB_MAX,
191
};
192
193
enum CopyToFBFlags {
194
COPY_TO_FB_FLAG_FLIP_Y = (1 << 0),
195
COPY_TO_FB_FLAG_USE_SECTION = (1 << 1),
196
COPY_TO_FB_FLAG_FORCE_LUMINANCE = (1 << 2),
197
COPY_TO_FB_FLAG_ALPHA_TO_ZERO = (1 << 3),
198
COPY_TO_FB_FLAG_SRGB = (1 << 4),
199
COPY_TO_FB_FLAG_ALPHA_TO_ONE = (1 << 5),
200
COPY_TO_FB_FLAG_LINEAR = (1 << 6),
201
COPY_TO_FB_FLAG_NORMAL = (1 << 7),
202
COPY_TO_FB_FLAG_USE_SRC_SECTION = (1 << 8),
203
};
204
205
struct CopyToFbPushConstant {
206
float section[4];
207
float pixel_size[2];
208
float luminance_multiplier;
209
uint32_t flags;
210
211
float set_color[4];
212
};
213
214
struct CopyToFb {
215
CopyToFbPushConstant push_constant;
216
CopyToFbShaderRD shader;
217
RID shader_version;
218
PipelineCacheRD pipelines[COPY_TO_FB_MAX];
219
220
} copy_to_fb;
221
222
// Copy to DP
223
224
struct CopyToDPPushConstant {
225
float z_far;
226
float z_near;
227
float texel_size[2];
228
};
229
230
struct CopyToDP {
231
CubeToDpShaderRD shader;
232
RID shader_version;
233
PipelineCacheRD pipeline;
234
} cube_to_dp;
235
236
// Copy to Octmap
237
238
struct CopyToOctmapPushConstant {
239
float border_size;
240
uint32_t pad[3];
241
};
242
243
struct CopyToOctmap {
244
CopyToOctmapPushConstant push_constant;
245
CubeToOctmapShaderRD shader;
246
RID shader_version;
247
PipelineCacheRD pipeline;
248
} cube_to_octmap;
249
250
// Octmap effects
251
252
struct OctmapDownsamplerPushConstant {
253
float border_size;
254
uint32_t size;
255
uint32_t pad[2];
256
};
257
258
enum OctmapDownsamplerMode {
259
DOWNSAMPLER_MODE_FLAG_RGB10_A2 = (1 << 0),
260
261
DOWNSAMPLER_MODE_COMPUTE_MAX = (DOWNSAMPLER_MODE_FLAG_RGB10_A2 + 1),
262
DOWNSAMPLER_MODE_RASTER_MAX = 1,
263
};
264
265
struct OctmapDownsampler {
266
OctmapDownsamplerPushConstant push_constant;
267
OctmapDownsamplerShaderRD compute_shader;
268
OctmapDownsamplerRasterShaderRD raster_shader;
269
RID shader_version;
270
PipelineDeferredRD compute_pipelines[DOWNSAMPLER_MODE_COMPUTE_MAX];
271
PipelineCacheRD raster_pipeline;
272
} octmap_downsampler;
273
274
enum OctmapFilterMode {
275
FILTER_MODE_FLAG_HIGH_QUALITY = (1 << 0),
276
FILTER_MODE_FLAG_ARRAY = (1 << 1),
277
FILTER_MODE_FLAG_RGB10_A2 = (1 << 2),
278
279
FILTER_MODE_COMPUTE_MAX = ((FILTER_MODE_FLAG_HIGH_QUALITY | FILTER_MODE_FLAG_ARRAY | FILTER_MODE_FLAG_RGB10_A2) + 1),
280
FILTER_MODE_RASTER_MAX = (FILTER_MODE_FLAG_HIGH_QUALITY + 1),
281
};
282
283
struct OctmapFilterPushConstant {
284
float border_size[2];
285
uint32_t pad1;
286
uint32_t pad2;
287
};
288
289
struct OctmapFilterRasterPushConstant {
290
float border_size[2];
291
uint32_t mip_level;
292
uint32_t pad;
293
};
294
295
struct OctmapFilter {
296
OctmapFilterShaderRD compute_shader;
297
OctmapFilterRasterShaderRD raster_shader;
298
RID shader_version;
299
PipelineDeferredRD compute_pipelines[FILTER_MODE_COMPUTE_MAX];
300
PipelineCacheRD raster_pipelines[FILTER_MODE_RASTER_MAX];
301
302
RID uniform_set;
303
RID image_uniform_set;
304
RID coefficient_buffer;
305
bool use_high_quality;
306
307
} filter;
308
309
enum OctmapRoughnessMode {
310
ROUGHNESS_MODE_RGBA16F,
311
ROUGHNESS_MODE_RGB10_A2,
312
ROUGHNESS_MODE_MAX,
313
};
314
315
struct OctmapRoughnessPushConstant {
316
uint32_t sample_count;
317
float roughness;
318
uint32_t source_size;
319
uint32_t dest_size;
320
321
float border_size[2];
322
uint32_t use_direct_write;
323
uint32_t pad;
324
};
325
326
struct OctmapRoughness {
327
OctmapRoughnessPushConstant push_constant;
328
OctmapRoughnessShaderRD compute_shader;
329
OctmapRoughnessRasterShaderRD raster_shader;
330
RID shader_version;
331
PipelineDeferredRD compute_pipelines[ROUGHNESS_MODE_MAX];
332
PipelineCacheRD raster_pipeline;
333
} roughness;
334
335
// Merge specular
336
337
enum SpecularMergeMode {
338
SPECULAR_MERGE_ADD,
339
SPECULAR_MERGE_SSR,
340
SPECULAR_MERGE_ADDITIVE_ADD,
341
SPECULAR_MERGE_ADDITIVE_SSR,
342
343
SPECULAR_MERGE_ADD_MULTIVIEW,
344
SPECULAR_MERGE_SSR_MULTIVIEW,
345
SPECULAR_MERGE_ADDITIVE_ADD_MULTIVIEW,
346
SPECULAR_MERGE_ADDITIVE_SSR_MULTIVIEW,
347
348
SPECULAR_MERGE_MAX
349
};
350
351
/* Specular merge must be done using raster, rather than compute
352
* because it must continue the existing color buffer
353
*/
354
355
struct SpecularMerge {
356
SpecularMergeShaderRD shader;
357
RID shader_version;
358
PipelineCacheRD pipelines[SPECULAR_MERGE_MAX];
359
360
} specular_merge;
361
362
static CopyEffects *singleton;
363
364
public:
365
static CopyEffects *get_singleton();
366
367
CopyEffects(BitField<RasterEffects> p_raster_effects);
368
~CopyEffects();
369
370
BitField<RasterEffects> get_raster_effects() { return raster_effects; }
371
372
void copy_to_rect(RID p_source_rd_texture, RID p_dest_texture, const Rect2i &p_rect, bool p_flip_y = false, bool p_force_luminance = false, bool p_all_source = false, bool p_8_bit_dst = false, bool p_alpha_to_one = false, bool p_sanitize_inf_nan = false);
373
void copy_octmap_to_panorama(RID p_source_octmap, RID p_dest_panorama, const Size2i &p_panorama_size, float p_lod, bool p_is_array, const Size2 &p_source_octmap_border_size);
374
void copy_depth_to_rect(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2i &p_rect, bool p_flip_y = false);
375
void copy_depth_to_rect_and_linearize(RID p_source_rd_texture, RID p_dest_texture, const Rect2i &p_rect, bool p_flip_y, float p_z_near, float p_z_far);
376
void copy_to_fb_rect(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2i &p_rect, bool p_flip_y = false, bool p_force_luminance = false, bool p_alpha_to_zero = false, bool p_srgb = false, RID p_secondary = RID(), bool p_multiview = false, bool alpha_to_one = false, bool p_linear = false, bool p_normal = false, const Rect2 &p_src_rect = Rect2(), float p_linear_luminance_multiplier = 1.0);
377
void copy_to_atlas_fb(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2 &p_uv_rect, RD::DrawListID p_draw_list, bool p_flip_y = false, bool p_panorama = false);
378
void copy_to_drawlist(RD::DrawListID p_draw_list, RD::FramebufferFormatID p_fb_format, RID p_source_rd_texture, bool p_linear = false, float p_linear_luminance_multiplier = 1.0);
379
void copy_raster(RID p_source_texture, RID p_dest_framebuffer);
380
381
void gaussian_blur(RID p_source_rd_texture, RID p_texture, const Rect2i &p_region, const Size2i &p_size, bool p_8bit_dst = false);
382
void gaussian_blur_raster(RID p_source_rd_texture, RID p_dest_texture, const Rect2i &p_region, const Size2i &p_size);
383
void gaussian_glow(RID p_source_rd_texture, RID p_back_texture, const Size2i &p_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_threshold = 1.0, float p_hdr_bleed_scale = 1.0, RID p_auto_exposure = RID(), float p_auto_exposure_scale = 1.0);
384
void gaussian_glow_downsample_raster(RID p_source_rd_texture, RID p_dest_texture, float p_luminance_multiplier, const Size2i &p_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_threshold = 1.0, float p_hdr_bleed_scale = 1.0);
385
void gaussian_glow_upsample_raster(RID p_source_rd_texture, RID p_dest_texture, RID p_blend_texture, float p_luminance_multiplier, const Size2i &p_source_size, const Size2i &p_dest_size, float p_level, float p_base_strength, bool p_use_debanding);
386
387
void make_mipmap(RID p_source_rd_texture, RID p_dest_texture, const Size2i &p_size);
388
void make_mipmap_raster(RID p_source_rd_texture, RID p_dest_texture, const Size2i &p_size);
389
390
void set_color(RID p_dest_texture, const Color &p_color, const Rect2i &p_region, bool p_8bit_dst = false);
391
void set_color_raster(RID p_dest_texture, const Color &p_color, const Rect2i &p_region);
392
393
void copy_cubemap_to_dp(RID p_source_rd_texture, RID p_dst_framebuffer, const Rect2 &p_rect, const Vector2 &p_dst_size, float p_z_near, float p_z_far, bool p_dp_flip);
394
void copy_cubemap_to_octmap(RID p_source_rd_texture, RID p_dst_framebuffer, float p_border_size);
395
void octmap_downsample(RID p_source_octmap, RID p_dest_octmap, const Size2i &p_size, float p_border_size);
396
void octmap_downsample_raster(RID p_source_octmap, RID p_dest_framebuffer, const Size2i &p_size, float p_border_size);
397
void octmap_filter(RID p_source_octmap, const Vector<RID> &p_dest_octmap, bool p_use_array, float p_border_size);
398
void octmap_filter_raster(RID p_source_octmap, RID p_dest_framebuffer, uint32_t p_mip_level, float p_border_size);
399
void octmap_roughness(RID p_source_rd_texture, RID p_dest_texture, uint32_t p_sample_count, float p_roughness, uint32_t p_source_size, uint32_t p_dest_size, float p_border_size);
400
void octmap_roughness_raster(RID p_source_rd_texture, RID p_dest_framebuffer, uint32_t p_sample_count, float p_roughness, uint32_t p_source_size, uint32_t p_dest_size, float p_border_size);
401
402
void merge_specular(RID p_dest_framebuffer, RID p_specular, RID p_base, RID p_reflection, uint32_t p_view_count);
403
};
404
405
} // namespace RendererRD
406
407