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
10279 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/shaders/effects/blur_raster.glsl.gen.h"
35
#include "servers/rendering/renderer_rd/shaders/effects/copy.glsl.gen.h"
36
#include "servers/rendering/renderer_rd/shaders/effects/copy_to_fb.glsl.gen.h"
37
#include "servers/rendering/renderer_rd/shaders/effects/cube_to_dp.glsl.gen.h"
38
#include "servers/rendering/renderer_rd/shaders/effects/cubemap_downsampler.glsl.gen.h"
39
#include "servers/rendering/renderer_rd/shaders/effects/cubemap_downsampler_raster.glsl.gen.h"
40
#include "servers/rendering/renderer_rd/shaders/effects/cubemap_filter.glsl.gen.h"
41
#include "servers/rendering/renderer_rd/shaders/effects/cubemap_filter_raster.glsl.gen.h"
42
#include "servers/rendering/renderer_rd/shaders/effects/cubemap_roughness.glsl.gen.h"
43
#include "servers/rendering/renderer_rd/shaders/effects/cubemap_roughness_raster.glsl.gen.h"
44
#include "servers/rendering/renderer_rd/shaders/effects/specular_merge.glsl.gen.h"
45
#include "servers/rendering/renderer_scene_render.h"
46
47
#include "servers/rendering_server.h"
48
49
namespace RendererRD {
50
51
class CopyEffects {
52
private:
53
bool prefer_raster_effects;
54
55
// Blur raster shader
56
57
enum BlurRasterMode {
58
BLUR_MIPMAP,
59
60
BLUR_MODE_GAUSSIAN_BLUR,
61
BLUR_MODE_GAUSSIAN_GLOW,
62
BLUR_MODE_GAUSSIAN_GLOW_AUTO_EXPOSURE,
63
BLUR_MODE_COPY,
64
65
BLUR_MODE_SET_COLOR,
66
67
BLUR_MODE_MAX
68
};
69
70
enum {
71
BLUR_FLAG_HORIZONTAL = (1 << 0),
72
BLUR_FLAG_USE_ORTHOGONAL_PROJECTION = (1 << 1),
73
BLUR_FLAG_GLOW_FIRST_PASS = (1 << 2),
74
};
75
76
struct BlurRasterPushConstant {
77
float pixel_size[2];
78
uint32_t flags;
79
uint32_t pad;
80
81
//glow
82
float glow_strength;
83
float glow_bloom;
84
float glow_hdr_threshold;
85
float glow_hdr_scale;
86
87
float glow_exposure;
88
float glow_white;
89
float glow_luminance_cap;
90
float glow_auto_exposure_scale;
91
92
float luminance_multiplier;
93
float res1;
94
float res2;
95
float res3;
96
};
97
98
struct BlurRaster {
99
BlurRasterPushConstant push_constant;
100
BlurRasterShaderRD shader;
101
RID shader_version;
102
PipelineCacheRD pipelines[BLUR_MODE_MAX];
103
} blur_raster;
104
105
// Copy shader
106
107
enum CopyMode {
108
COPY_MODE_GAUSSIAN_COPY,
109
COPY_MODE_GAUSSIAN_COPY_8BIT,
110
COPY_MODE_GAUSSIAN_GLOW,
111
COPY_MODE_GAUSSIAN_GLOW_AUTO_EXPOSURE,
112
COPY_MODE_SIMPLY_COPY,
113
COPY_MODE_SIMPLY_COPY_8BIT,
114
COPY_MODE_SIMPLY_COPY_DEPTH,
115
COPY_MODE_SET_COLOR,
116
COPY_MODE_SET_COLOR_8BIT,
117
COPY_MODE_MIPMAP,
118
COPY_MODE_LINEARIZE_DEPTH,
119
COPY_MODE_CUBE_TO_PANORAMA,
120
COPY_MODE_CUBE_ARRAY_TO_PANORAMA,
121
COPY_MODE_MAX,
122
123
};
124
125
enum {
126
COPY_FLAG_HORIZONTAL = (1 << 0),
127
COPY_FLAG_USE_COPY_SECTION = (1 << 1),
128
COPY_FLAG_USE_ORTHOGONAL_PROJECTION = (1 << 2),
129
COPY_FLAG_DOF_NEAR_FIRST_TAP = (1 << 3),
130
COPY_FLAG_GLOW_FIRST_PASS = (1 << 4),
131
COPY_FLAG_FLIP_Y = (1 << 5),
132
COPY_FLAG_FORCE_LUMINANCE = (1 << 6),
133
COPY_FLAG_ALL_SOURCE = (1 << 7),
134
COPY_FLAG_ALPHA_TO_ONE = (1 << 8),
135
};
136
137
struct CopyPushConstant {
138
int32_t section[4];
139
int32_t target[2];
140
uint32_t flags;
141
uint32_t pad;
142
// Glow.
143
float glow_strength;
144
float glow_bloom;
145
float glow_hdr_threshold;
146
float glow_hdr_scale;
147
148
float glow_exposure;
149
float glow_white;
150
float glow_luminance_cap;
151
float glow_auto_exposure_scale;
152
// DOF.
153
float camera_z_far;
154
float camera_z_near;
155
uint32_t pad2[2];
156
//SET color
157
float set_color[4];
158
};
159
160
struct Copy {
161
CopyPushConstant push_constant;
162
CopyShaderRD shader;
163
RID shader_version;
164
RID pipelines[COPY_MODE_MAX];
165
166
} copy;
167
168
// Copy to FB shader
169
170
enum CopyToFBMode {
171
COPY_TO_FB_COPY,
172
COPY_TO_FB_COPY_PANORAMA_TO_DP,
173
COPY_TO_FB_COPY2,
174
COPY_TO_FB_SET_COLOR,
175
176
// These variants are disabled unless XR shaders are enabled.
177
// They should be listed last.
178
COPY_TO_FB_MULTIVIEW,
179
COPY_TO_FB_MULTIVIEW_WITH_DEPTH,
180
181
COPY_TO_FB_MAX,
182
};
183
184
enum CopyToFBFlags {
185
COPY_TO_FB_FLAG_FLIP_Y = (1 << 0),
186
COPY_TO_FB_FLAG_USE_SECTION = (1 << 1),
187
COPY_TO_FB_FLAG_FORCE_LUMINANCE = (1 << 2),
188
COPY_TO_FB_FLAG_ALPHA_TO_ZERO = (1 << 3),
189
COPY_TO_FB_FLAG_SRGB = (1 << 4),
190
COPY_TO_FB_FLAG_ALPHA_TO_ONE = (1 << 5),
191
COPY_TO_FB_FLAG_LINEAR = (1 << 6),
192
COPY_TO_FB_FLAG_NORMAL = (1 << 7),
193
COPY_TO_FB_FLAG_USE_SRC_SECTION = (1 << 8),
194
};
195
196
struct CopyToFbPushConstant {
197
float section[4];
198
float pixel_size[2];
199
float luminance_multiplier;
200
uint32_t flags;
201
202
float set_color[4];
203
};
204
205
struct CopyToFb {
206
CopyToFbPushConstant push_constant;
207
CopyToFbShaderRD shader;
208
RID shader_version;
209
PipelineCacheRD pipelines[COPY_TO_FB_MAX];
210
211
} copy_to_fb;
212
213
// Copy to DP
214
215
struct CopyToDPPushConstant {
216
float z_far;
217
float z_near;
218
float texel_size[2];
219
};
220
221
struct CopyToDP {
222
CubeToDpShaderRD shader;
223
RID shader_version;
224
PipelineCacheRD pipeline;
225
} cube_to_dp;
226
227
// Cubemap effects
228
229
struct CubemapDownsamplerPushConstant {
230
uint32_t face_size;
231
uint32_t face_id;
232
float pad[2];
233
};
234
235
struct CubemapDownsampler {
236
CubemapDownsamplerPushConstant push_constant;
237
CubemapDownsamplerShaderRD compute_shader;
238
CubemapDownsamplerRasterShaderRD raster_shader;
239
RID shader_version;
240
RID compute_pipeline;
241
PipelineCacheRD raster_pipeline;
242
} cubemap_downsampler;
243
244
enum CubemapFilterMode {
245
FILTER_MODE_HIGH_QUALITY,
246
FILTER_MODE_LOW_QUALITY,
247
FILTER_MODE_HIGH_QUALITY_ARRAY,
248
FILTER_MODE_LOW_QUALITY_ARRAY,
249
FILTER_MODE_MAX,
250
};
251
252
struct CubemapFilterRasterPushConstant {
253
uint32_t mip_level;
254
uint32_t face_id;
255
float pad[2];
256
};
257
258
struct CubemapFilter {
259
CubemapFilterShaderRD compute_shader;
260
CubemapFilterRasterShaderRD raster_shader;
261
RID shader_version;
262
RID compute_pipelines[FILTER_MODE_MAX];
263
PipelineCacheRD raster_pipelines[FILTER_MODE_MAX];
264
265
RID uniform_set;
266
RID image_uniform_set;
267
RID coefficient_buffer;
268
bool use_high_quality;
269
270
} filter;
271
272
struct CubemapRoughnessPushConstant {
273
uint32_t face_id;
274
uint32_t sample_count;
275
float roughness;
276
uint32_t use_direct_write;
277
float face_size;
278
float pad[3];
279
};
280
281
struct CubemapRoughness {
282
CubemapRoughnessPushConstant push_constant;
283
CubemapRoughnessShaderRD compute_shader;
284
CubemapRoughnessRasterShaderRD raster_shader;
285
RID shader_version;
286
RID compute_pipeline;
287
PipelineCacheRD raster_pipeline;
288
} roughness;
289
290
// Merge specular
291
292
enum SpecularMergeMode {
293
SPECULAR_MERGE_ADD,
294
SPECULAR_MERGE_SSR,
295
SPECULAR_MERGE_ADDITIVE_ADD,
296
SPECULAR_MERGE_ADDITIVE_SSR,
297
298
SPECULAR_MERGE_ADD_MULTIVIEW,
299
SPECULAR_MERGE_SSR_MULTIVIEW,
300
SPECULAR_MERGE_ADDITIVE_ADD_MULTIVIEW,
301
SPECULAR_MERGE_ADDITIVE_SSR_MULTIVIEW,
302
303
SPECULAR_MERGE_MAX
304
};
305
306
/* Specular merge must be done using raster, rather than compute
307
* because it must continue the existing color buffer
308
*/
309
310
struct SpecularMerge {
311
SpecularMergeShaderRD shader;
312
RID shader_version;
313
PipelineCacheRD pipelines[SPECULAR_MERGE_MAX];
314
315
} specular_merge;
316
317
static CopyEffects *singleton;
318
319
public:
320
static CopyEffects *get_singleton();
321
322
CopyEffects(bool p_prefer_raster_effects);
323
~CopyEffects();
324
325
bool get_prefer_raster_effects() { return prefer_raster_effects; }
326
327
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);
328
void copy_cubemap_to_panorama(RID p_source_cube, RID p_dest_panorama, const Size2i &p_panorama_size, float p_lod, bool p_is_array);
329
void copy_depth_to_rect(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2i &p_rect, bool p_flip_y = false);
330
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);
331
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());
332
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);
333
void copy_to_drawlist(RD::DrawListID p_draw_list, RD::FramebufferFormatID p_fb_format, RID p_source_rd_texture, bool p_linear = false);
334
void copy_raster(RID p_source_texture, RID p_dest_framebuffer);
335
336
void gaussian_blur(RID p_source_rd_texture, RID p_texture, const Rect2i &p_region, const Size2i &p_size, bool p_8bit_dst = false);
337
void gaussian_blur_raster(RID p_source_rd_texture, RID p_dest_texture, const Rect2i &p_region, const Size2i &p_size);
338
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);
339
void gaussian_glow_raster(RID p_source_rd_texture, RID p_half_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, RID p_auto_exposure = RID(), float p_auto_exposure_scale = 1.0);
340
341
void make_mipmap(RID p_source_rd_texture, RID p_dest_texture, const Size2i &p_size);
342
void make_mipmap_raster(RID p_source_rd_texture, RID p_dest_texture, const Size2i &p_size);
343
344
void set_color(RID p_dest_texture, const Color &p_color, const Rect2i &p_region, bool p_8bit_dst = false);
345
void set_color_raster(RID p_dest_texture, const Color &p_color, const Rect2i &p_region);
346
347
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);
348
void cubemap_downsample(RID p_source_cubemap, RID p_dest_cubemap, const Size2i &p_size);
349
void cubemap_downsample_raster(RID p_source_cubemap, RID p_dest_framebuffer, uint32_t p_face_id, const Size2i &p_size);
350
void cubemap_filter(RID p_source_cubemap, Vector<RID> p_dest_cubemap, bool p_use_array);
351
void cubemap_filter_raster(RID p_source_cubemap, RID p_dest_framebuffer, uint32_t p_face_id, uint32_t p_mip_level);
352
353
void cubemap_roughness(RID p_source_rd_texture, RID p_dest_texture, uint32_t p_face_id, uint32_t p_sample_count, float p_roughness, float p_size);
354
void cubemap_roughness_raster(RID p_source_rd_texture, RID p_dest_framebuffer, uint32_t p_face_id, uint32_t p_sample_count, float p_roughness, float p_size);
355
356
void merge_specular(RID p_dest_framebuffer, RID p_specular, RID p_base, RID p_reflection, uint32_t p_view_count);
357
};
358
359
} // namespace RendererRD
360
361