copy_effects.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. /*************************************************************************/
  2. /* copy_effects.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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. #ifndef COPY_EFFECTS_RD_H
  31. #define COPY_EFFECTS_RD_H
  32. #include "servers/rendering/renderer_rd/pipeline_cache_rd.h"
  33. #include "servers/rendering/renderer_rd/shaders/effects/blur_raster.glsl.gen.h"
  34. #include "servers/rendering/renderer_rd/shaders/effects/copy.glsl.gen.h"
  35. #include "servers/rendering/renderer_rd/shaders/effects/copy_to_fb.glsl.gen.h"
  36. #include "servers/rendering/renderer_rd/shaders/effects/cube_to_dp.glsl.gen.h"
  37. #include "servers/rendering/renderer_rd/shaders/effects/cubemap_downsampler.glsl.gen.h"
  38. #include "servers/rendering/renderer_rd/shaders/effects/cubemap_downsampler_raster.glsl.gen.h"
  39. #include "servers/rendering/renderer_rd/shaders/effects/cubemap_filter.glsl.gen.h"
  40. #include "servers/rendering/renderer_rd/shaders/effects/cubemap_filter_raster.glsl.gen.h"
  41. #include "servers/rendering/renderer_rd/shaders/effects/cubemap_roughness.glsl.gen.h"
  42. #include "servers/rendering/renderer_rd/shaders/effects/cubemap_roughness_raster.glsl.gen.h"
  43. #include "servers/rendering/renderer_rd/shaders/effects/specular_merge.glsl.gen.h"
  44. #include "servers/rendering/renderer_scene_render.h"
  45. #include "servers/rendering_server.h"
  46. namespace RendererRD {
  47. class CopyEffects {
  48. private:
  49. bool prefer_raster_effects;
  50. // Blur raster shader
  51. enum BlurRasterMode {
  52. BLUR_MIPMAP,
  53. BLUR_MODE_GAUSSIAN_BLUR,
  54. BLUR_MODE_GAUSSIAN_GLOW,
  55. BLUR_MODE_GAUSSIAN_GLOW_AUTO_EXPOSURE,
  56. BLUR_MODE_COPY,
  57. BLUR_MODE_MAX
  58. };
  59. enum {
  60. BLUR_FLAG_HORIZONTAL = (1 << 0),
  61. BLUR_FLAG_USE_ORTHOGONAL_PROJECTION = (1 << 1),
  62. BLUR_FLAG_GLOW_FIRST_PASS = (1 << 2),
  63. };
  64. struct BlurRasterPushConstant {
  65. float pixel_size[2];
  66. uint32_t flags;
  67. uint32_t pad;
  68. //glow
  69. float glow_strength;
  70. float glow_bloom;
  71. float glow_hdr_threshold;
  72. float glow_hdr_scale;
  73. float glow_exposure;
  74. float glow_white;
  75. float glow_luminance_cap;
  76. float glow_auto_exposure_scale;
  77. float luminance_multiplier;
  78. float res1;
  79. float res2;
  80. float res3;
  81. };
  82. struct BlurRaster {
  83. BlurRasterPushConstant push_constant;
  84. BlurRasterShaderRD shader;
  85. RID shader_version;
  86. PipelineCacheRD pipelines[BLUR_MODE_MAX];
  87. } blur_raster;
  88. // Copy shader
  89. enum CopyMode {
  90. COPY_MODE_GAUSSIAN_COPY,
  91. COPY_MODE_GAUSSIAN_COPY_8BIT,
  92. COPY_MODE_GAUSSIAN_GLOW,
  93. COPY_MODE_GAUSSIAN_GLOW_AUTO_EXPOSURE,
  94. COPY_MODE_SIMPLY_COPY,
  95. COPY_MODE_SIMPLY_COPY_8BIT,
  96. COPY_MODE_SIMPLY_COPY_DEPTH,
  97. COPY_MODE_SET_COLOR,
  98. COPY_MODE_SET_COLOR_8BIT,
  99. COPY_MODE_MIPMAP,
  100. COPY_MODE_LINEARIZE_DEPTH,
  101. COPY_MODE_CUBE_TO_PANORAMA,
  102. COPY_MODE_CUBE_ARRAY_TO_PANORAMA,
  103. COPY_MODE_MAX,
  104. };
  105. enum {
  106. COPY_FLAG_HORIZONTAL = (1 << 0),
  107. COPY_FLAG_USE_COPY_SECTION = (1 << 1),
  108. COPY_FLAG_USE_ORTHOGONAL_PROJECTION = (1 << 2),
  109. COPY_FLAG_DOF_NEAR_FIRST_TAP = (1 << 3),
  110. COPY_FLAG_GLOW_FIRST_PASS = (1 << 4),
  111. COPY_FLAG_FLIP_Y = (1 << 5),
  112. COPY_FLAG_FORCE_LUMINANCE = (1 << 6),
  113. COPY_FLAG_ALL_SOURCE = (1 << 7),
  114. COPY_FLAG_HIGH_QUALITY_GLOW = (1 << 8),
  115. COPY_FLAG_ALPHA_TO_ONE = (1 << 9),
  116. };
  117. struct CopyPushConstant {
  118. int32_t section[4];
  119. int32_t target[2];
  120. uint32_t flags;
  121. uint32_t pad;
  122. // Glow.
  123. float glow_strength;
  124. float glow_bloom;
  125. float glow_hdr_threshold;
  126. float glow_hdr_scale;
  127. float glow_exposure;
  128. float glow_white;
  129. float glow_luminance_cap;
  130. float glow_auto_exposure_scale;
  131. // DOF.
  132. float camera_z_far;
  133. float camera_z_near;
  134. uint32_t pad2[2];
  135. //SET color
  136. float set_color[4];
  137. };
  138. struct Copy {
  139. CopyPushConstant push_constant;
  140. CopyShaderRD shader;
  141. RID shader_version;
  142. RID pipelines[COPY_MODE_MAX];
  143. } copy;
  144. // Copy to FB shader
  145. enum CopyToFBMode {
  146. COPY_TO_FB_COPY,
  147. COPY_TO_FB_COPY_PANORAMA_TO_DP,
  148. COPY_TO_FB_COPY2,
  149. COPY_TO_FB_MULTIVIEW,
  150. COPY_TO_FB_MULTIVIEW_WITH_DEPTH,
  151. COPY_TO_FB_MAX,
  152. };
  153. struct CopyToFbPushConstant {
  154. float section[4];
  155. float pixel_size[2];
  156. uint32_t flip_y;
  157. uint32_t use_section;
  158. uint32_t force_luminance;
  159. uint32_t alpha_to_zero;
  160. uint32_t srgb;
  161. uint32_t pad;
  162. };
  163. struct CopyToFb {
  164. CopyToFbPushConstant push_constant;
  165. CopyToFbShaderRD shader;
  166. RID shader_version;
  167. PipelineCacheRD pipelines[COPY_TO_FB_MAX];
  168. } copy_to_fb;
  169. // Copy to DP
  170. struct CopyToDPPushConstant {
  171. float z_far;
  172. float z_near;
  173. float texel_size[2];
  174. float screen_rect[4];
  175. };
  176. struct CopyToDP {
  177. CubeToDpShaderRD shader;
  178. RID shader_version;
  179. PipelineCacheRD pipeline;
  180. } cube_to_dp;
  181. // Cubemap effects
  182. struct CubemapDownsamplerPushConstant {
  183. uint32_t face_size;
  184. uint32_t face_id;
  185. float pad[2];
  186. };
  187. struct CubemapDownsampler {
  188. CubemapDownsamplerPushConstant push_constant;
  189. CubemapDownsamplerShaderRD compute_shader;
  190. CubemapDownsamplerRasterShaderRD raster_shader;
  191. RID shader_version;
  192. RID compute_pipeline;
  193. PipelineCacheRD raster_pipeline;
  194. } cubemap_downsampler;
  195. enum CubemapFilterMode {
  196. FILTER_MODE_HIGH_QUALITY,
  197. FILTER_MODE_LOW_QUALITY,
  198. FILTER_MODE_HIGH_QUALITY_ARRAY,
  199. FILTER_MODE_LOW_QUALITY_ARRAY,
  200. FILTER_MODE_MAX,
  201. };
  202. struct CubemapFilterRasterPushConstant {
  203. uint32_t mip_level;
  204. uint32_t face_id;
  205. float pad[2];
  206. };
  207. struct CubemapFilter {
  208. CubemapFilterShaderRD compute_shader;
  209. CubemapFilterRasterShaderRD raster_shader;
  210. RID shader_version;
  211. RID compute_pipelines[FILTER_MODE_MAX];
  212. PipelineCacheRD raster_pipelines[FILTER_MODE_MAX];
  213. RID uniform_set;
  214. RID image_uniform_set;
  215. RID coefficient_buffer;
  216. bool use_high_quality;
  217. } filter;
  218. struct CubemapRoughnessPushConstant {
  219. uint32_t face_id;
  220. uint32_t sample_count;
  221. float roughness;
  222. uint32_t use_direct_write;
  223. float face_size;
  224. float pad[3];
  225. };
  226. struct CubemapRoughness {
  227. CubemapRoughnessPushConstant push_constant;
  228. CubemapRoughnessShaderRD compute_shader;
  229. CubemapRoughnessRasterShaderRD raster_shader;
  230. RID shader_version;
  231. RID compute_pipeline;
  232. PipelineCacheRD raster_pipeline;
  233. } roughness;
  234. // Merge specular
  235. enum SpecularMergeMode {
  236. SPECULAR_MERGE_ADD,
  237. SPECULAR_MERGE_SSR,
  238. SPECULAR_MERGE_ADDITIVE_ADD,
  239. SPECULAR_MERGE_ADDITIVE_SSR,
  240. SPECULAR_MERGE_ADD_MULTIVIEW,
  241. SPECULAR_MERGE_SSR_MULTIVIEW,
  242. SPECULAR_MERGE_ADDITIVE_ADD_MULTIVIEW,
  243. SPECULAR_MERGE_ADDITIVE_SSR_MULTIVIEW,
  244. SPECULAR_MERGE_MAX
  245. };
  246. /* Specular merge must be done using raster, rather than compute
  247. * because it must continue the existing color buffer
  248. */
  249. struct SpecularMerge {
  250. SpecularMergeShaderRD shader;
  251. RID shader_version;
  252. PipelineCacheRD pipelines[SPECULAR_MERGE_MAX];
  253. } specular_merge;
  254. static CopyEffects *singleton;
  255. public:
  256. static CopyEffects *get_singleton();
  257. CopyEffects(bool p_prefer_raster_effects);
  258. ~CopyEffects();
  259. bool get_prefer_raster_effects() { return prefer_raster_effects; }
  260. 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);
  261. 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);
  262. void copy_depth_to_rect(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2i &p_rect, bool p_flip_y = false);
  263. 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);
  264. 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);
  265. 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);
  266. void copy_raster(RID p_source_texture, RID p_dest_framebuffer);
  267. void gaussian_blur(RID p_source_rd_texture, RID p_texture, const Rect2i &p_region, bool p_8bit_dst = false);
  268. void gaussian_glow(RID p_source_rd_texture, RID p_back_texture, const Size2i &p_size, float p_strength = 1.0, bool p_high_quality = false, 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);
  269. 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_high_quality = false, 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);
  270. void make_mipmap(RID p_source_rd_texture, RID p_dest_texture, const Size2i &p_size);
  271. void make_mipmap_raster(RID p_source_rd_texture, RID p_dest_texture, const Size2i &p_size);
  272. void set_color(RID p_dest_texture, const Color &p_color, const Rect2i &p_region, bool p_8bit_dst = false);
  273. 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);
  274. void cubemap_downsample(RID p_source_cubemap, RID p_dest_cubemap, const Size2i &p_size);
  275. void cubemap_downsample_raster(RID p_source_cubemap, RID p_dest_framebuffer, uint32_t p_face_id, const Size2i &p_size);
  276. void cubemap_filter(RID p_source_cubemap, Vector<RID> p_dest_cubemap, bool p_use_array);
  277. void cubemap_filter_raster(RID p_source_cubemap, RID p_dest_framebuffer, uint32_t p_face_id, uint32_t p_mip_level);
  278. 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);
  279. 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);
  280. void merge_specular(RID p_dest_framebuffer, RID p_specular, RID p_base, RID p_reflection, uint32_t p_view_count);
  281. };
  282. } // namespace RendererRD
  283. #endif // COPY_EFFECTS_RD_H