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