copy_effects.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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. #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_SET_COLOR,
  58. BLUR_MODE_MAX
  59. };
  60. enum {
  61. BLUR_FLAG_HORIZONTAL = (1 << 0),
  62. BLUR_FLAG_USE_ORTHOGONAL_PROJECTION = (1 << 1),
  63. BLUR_FLAG_GLOW_FIRST_PASS = (1 << 2),
  64. };
  65. struct BlurRasterPushConstant {
  66. float pixel_size[2];
  67. uint32_t flags;
  68. uint32_t pad;
  69. //glow
  70. float glow_strength;
  71. float glow_bloom;
  72. float glow_hdr_threshold;
  73. float glow_hdr_scale;
  74. float glow_exposure;
  75. float glow_white;
  76. float glow_luminance_cap;
  77. float glow_auto_exposure_scale;
  78. float luminance_multiplier;
  79. float res1;
  80. float res2;
  81. float res3;
  82. };
  83. struct BlurRaster {
  84. BlurRasterPushConstant push_constant;
  85. BlurRasterShaderRD shader;
  86. RID shader_version;
  87. PipelineCacheRD pipelines[BLUR_MODE_MAX];
  88. } blur_raster;
  89. // Copy shader
  90. enum CopyMode {
  91. COPY_MODE_GAUSSIAN_COPY,
  92. COPY_MODE_GAUSSIAN_COPY_8BIT,
  93. COPY_MODE_GAUSSIAN_GLOW,
  94. COPY_MODE_GAUSSIAN_GLOW_AUTO_EXPOSURE,
  95. COPY_MODE_SIMPLY_COPY,
  96. COPY_MODE_SIMPLY_COPY_8BIT,
  97. COPY_MODE_SIMPLY_COPY_DEPTH,
  98. COPY_MODE_SET_COLOR,
  99. COPY_MODE_SET_COLOR_8BIT,
  100. COPY_MODE_MIPMAP,
  101. COPY_MODE_LINEARIZE_DEPTH,
  102. COPY_MODE_CUBE_TO_PANORAMA,
  103. COPY_MODE_CUBE_ARRAY_TO_PANORAMA,
  104. COPY_MODE_MAX,
  105. };
  106. enum {
  107. COPY_FLAG_HORIZONTAL = (1 << 0),
  108. COPY_FLAG_USE_COPY_SECTION = (1 << 1),
  109. COPY_FLAG_USE_ORTHOGONAL_PROJECTION = (1 << 2),
  110. COPY_FLAG_DOF_NEAR_FIRST_TAP = (1 << 3),
  111. COPY_FLAG_GLOW_FIRST_PASS = (1 << 4),
  112. COPY_FLAG_FLIP_Y = (1 << 5),
  113. COPY_FLAG_FORCE_LUMINANCE = (1 << 6),
  114. COPY_FLAG_ALL_SOURCE = (1 << 7),
  115. COPY_FLAG_ALPHA_TO_ONE = (1 << 8),
  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_SET_COLOR,
  152. COPY_TO_FB_MAX,
  153. };
  154. enum CopyToFBFlags {
  155. COPY_TO_FB_FLAG_FLIP_Y = (1 << 0),
  156. COPY_TO_FB_FLAG_USE_SECTION = (1 << 1),
  157. COPY_TO_FB_FLAG_FORCE_LUMINANCE = (1 << 2),
  158. COPY_TO_FB_FLAG_ALPHA_TO_ZERO = (1 << 3),
  159. COPY_TO_FB_FLAG_SRGB = (1 << 4),
  160. COPY_TO_FB_FLAG_ALPHA_TO_ONE = (1 << 5),
  161. COPY_TO_FB_FLAG_LINEAR = (1 << 6),
  162. };
  163. struct CopyToFbPushConstant {
  164. float section[4];
  165. float pixel_size[2];
  166. float luminance_multiplier;
  167. uint32_t flags;
  168. float set_color[4];
  169. };
  170. struct CopyToFb {
  171. CopyToFbPushConstant push_constant;
  172. CopyToFbShaderRD shader;
  173. RID shader_version;
  174. PipelineCacheRD pipelines[COPY_TO_FB_MAX];
  175. } copy_to_fb;
  176. // Copy to DP
  177. struct CopyToDPPushConstant {
  178. float z_far;
  179. float z_near;
  180. float texel_size[2];
  181. float screen_rect[4];
  182. };
  183. struct CopyToDP {
  184. CubeToDpShaderRD shader;
  185. RID shader_version;
  186. PipelineCacheRD pipeline;
  187. } cube_to_dp;
  188. // Cubemap effects
  189. struct CubemapDownsamplerPushConstant {
  190. uint32_t face_size;
  191. uint32_t face_id;
  192. float pad[2];
  193. };
  194. struct CubemapDownsampler {
  195. CubemapDownsamplerPushConstant push_constant;
  196. CubemapDownsamplerShaderRD compute_shader;
  197. CubemapDownsamplerRasterShaderRD raster_shader;
  198. RID shader_version;
  199. RID compute_pipeline;
  200. PipelineCacheRD raster_pipeline;
  201. } cubemap_downsampler;
  202. enum CubemapFilterMode {
  203. FILTER_MODE_HIGH_QUALITY,
  204. FILTER_MODE_LOW_QUALITY,
  205. FILTER_MODE_HIGH_QUALITY_ARRAY,
  206. FILTER_MODE_LOW_QUALITY_ARRAY,
  207. FILTER_MODE_MAX,
  208. };
  209. struct CubemapFilterRasterPushConstant {
  210. uint32_t mip_level;
  211. uint32_t face_id;
  212. float pad[2];
  213. };
  214. struct CubemapFilter {
  215. CubemapFilterShaderRD compute_shader;
  216. CubemapFilterRasterShaderRD raster_shader;
  217. RID shader_version;
  218. RID compute_pipelines[FILTER_MODE_MAX];
  219. PipelineCacheRD raster_pipelines[FILTER_MODE_MAX];
  220. RID uniform_set;
  221. RID image_uniform_set;
  222. RID coefficient_buffer;
  223. bool use_high_quality;
  224. } filter;
  225. struct CubemapRoughnessPushConstant {
  226. uint32_t face_id;
  227. uint32_t sample_count;
  228. float roughness;
  229. uint32_t use_direct_write;
  230. float face_size;
  231. float pad[3];
  232. };
  233. struct CubemapRoughness {
  234. CubemapRoughnessPushConstant push_constant;
  235. CubemapRoughnessShaderRD compute_shader;
  236. CubemapRoughnessRasterShaderRD raster_shader;
  237. RID shader_version;
  238. RID compute_pipeline;
  239. PipelineCacheRD raster_pipeline;
  240. } roughness;
  241. // Merge specular
  242. enum SpecularMergeMode {
  243. SPECULAR_MERGE_ADD,
  244. SPECULAR_MERGE_SSR,
  245. SPECULAR_MERGE_ADDITIVE_ADD,
  246. SPECULAR_MERGE_ADDITIVE_SSR,
  247. SPECULAR_MERGE_ADD_MULTIVIEW,
  248. SPECULAR_MERGE_SSR_MULTIVIEW,
  249. SPECULAR_MERGE_ADDITIVE_ADD_MULTIVIEW,
  250. SPECULAR_MERGE_ADDITIVE_SSR_MULTIVIEW,
  251. SPECULAR_MERGE_MAX
  252. };
  253. /* Specular merge must be done using raster, rather than compute
  254. * because it must continue the existing color buffer
  255. */
  256. struct SpecularMerge {
  257. SpecularMergeShaderRD shader;
  258. RID shader_version;
  259. PipelineCacheRD pipelines[SPECULAR_MERGE_MAX];
  260. } specular_merge;
  261. static CopyEffects *singleton;
  262. public:
  263. static CopyEffects *get_singleton();
  264. CopyEffects(bool p_prefer_raster_effects);
  265. ~CopyEffects();
  266. bool get_prefer_raster_effects() { return prefer_raster_effects; }
  267. 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);
  268. 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);
  269. void copy_depth_to_rect(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2i &p_rect, bool p_flip_y = false);
  270. 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);
  271. 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);
  272. 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);
  273. void copy_raster(RID p_source_texture, RID p_dest_framebuffer);
  274. void gaussian_blur(RID p_source_rd_texture, RID p_texture, const Rect2i &p_region, const Size2i &p_size, bool p_8bit_dst = false);
  275. void gaussian_blur_raster(RID p_source_rd_texture, RID p_dest_texture, const Rect2i &p_region, const Size2i &p_size);
  276. 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);
  277. 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);
  278. void make_mipmap(RID p_source_rd_texture, RID p_dest_texture, const Size2i &p_size);
  279. void make_mipmap_raster(RID p_source_rd_texture, RID p_dest_texture, const Size2i &p_size);
  280. void set_color(RID p_dest_texture, const Color &p_color, const Rect2i &p_region, bool p_8bit_dst = false);
  281. void set_color_raster(RID p_dest_texture, const Color &p_color, const Rect2i &p_region);
  282. 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);
  283. void cubemap_downsample(RID p_source_cubemap, RID p_dest_cubemap, const Size2i &p_size);
  284. void cubemap_downsample_raster(RID p_source_cubemap, RID p_dest_framebuffer, uint32_t p_face_id, const Size2i &p_size);
  285. void cubemap_filter(RID p_source_cubemap, Vector<RID> p_dest_cubemap, bool p_use_array);
  286. void cubemap_filter_raster(RID p_source_cubemap, RID p_dest_framebuffer, uint32_t p_face_id, uint32_t p_mip_level);
  287. 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);
  288. 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);
  289. void merge_specular(RID p_dest_framebuffer, RID p_specular, RID p_base, RID p_reflection, uint32_t p_view_count);
  290. };
  291. } // namespace RendererRD
  292. #endif // COPY_EFFECTS_RD_H