effects_rd.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883
  1. /*************************************************************************/
  2. /* effects_rd.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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 EFFECTS_RD_H
  31. #define EFFECTS_RD_H
  32. #include "core/math/camera_matrix.h"
  33. #include "servers/rendering/renderer_rd/pipeline_cache_rd.h"
  34. #include "servers/rendering/renderer_rd/shaders/blur_raster.glsl.gen.h"
  35. #include "servers/rendering/renderer_rd/shaders/bokeh_dof.glsl.gen.h"
  36. #include "servers/rendering/renderer_rd/shaders/bokeh_dof_raster.glsl.gen.h"
  37. #include "servers/rendering/renderer_rd/shaders/copy.glsl.gen.h"
  38. #include "servers/rendering/renderer_rd/shaders/copy_to_fb.glsl.gen.h"
  39. #include "servers/rendering/renderer_rd/shaders/cube_to_dp.glsl.gen.h"
  40. #include "servers/rendering/renderer_rd/shaders/cubemap_downsampler.glsl.gen.h"
  41. #include "servers/rendering/renderer_rd/shaders/cubemap_downsampler_raster.glsl.gen.h"
  42. #include "servers/rendering/renderer_rd/shaders/cubemap_filter.glsl.gen.h"
  43. #include "servers/rendering/renderer_rd/shaders/cubemap_filter_raster.glsl.gen.h"
  44. #include "servers/rendering/renderer_rd/shaders/cubemap_roughness.glsl.gen.h"
  45. #include "servers/rendering/renderer_rd/shaders/cubemap_roughness_raster.glsl.gen.h"
  46. #include "servers/rendering/renderer_rd/shaders/luminance_reduce.glsl.gen.h"
  47. #include "servers/rendering/renderer_rd/shaders/luminance_reduce_raster.glsl.gen.h"
  48. #include "servers/rendering/renderer_rd/shaders/resolve.glsl.gen.h"
  49. #include "servers/rendering/renderer_rd/shaders/roughness_limiter.glsl.gen.h"
  50. #include "servers/rendering/renderer_rd/shaders/screen_space_reflection.glsl.gen.h"
  51. #include "servers/rendering/renderer_rd/shaders/screen_space_reflection_filter.glsl.gen.h"
  52. #include "servers/rendering/renderer_rd/shaders/screen_space_reflection_scale.glsl.gen.h"
  53. #include "servers/rendering/renderer_rd/shaders/sort.glsl.gen.h"
  54. #include "servers/rendering/renderer_rd/shaders/specular_merge.glsl.gen.h"
  55. #include "servers/rendering/renderer_rd/shaders/ssao.glsl.gen.h"
  56. #include "servers/rendering/renderer_rd/shaders/ssao_blur.glsl.gen.h"
  57. #include "servers/rendering/renderer_rd/shaders/ssao_downsample.glsl.gen.h"
  58. #include "servers/rendering/renderer_rd/shaders/ssao_importance_map.glsl.gen.h"
  59. #include "servers/rendering/renderer_rd/shaders/ssao_interleave.glsl.gen.h"
  60. #include "servers/rendering/renderer_rd/shaders/subsurface_scattering.glsl.gen.h"
  61. #include "servers/rendering/renderer_rd/shaders/tonemap.glsl.gen.h"
  62. #include "servers/rendering/renderer_scene_render.h"
  63. #include "servers/rendering_server.h"
  64. class EffectsRD {
  65. private:
  66. bool prefer_raster_effects;
  67. enum BlurRasterMode {
  68. BLUR_MIPMAP,
  69. BLUR_MODE_GAUSSIAN_BLUR,
  70. BLUR_MODE_GAUSSIAN_GLOW,
  71. BLUR_MODE_GAUSSIAN_GLOW_AUTO_EXPOSURE,
  72. BLUR_MODE_COPY,
  73. BLUR_MODE_MAX
  74. };
  75. enum {
  76. BLUR_FLAG_HORIZONTAL = (1 << 0),
  77. BLUR_FLAG_USE_ORTHOGONAL_PROJECTION = (1 << 1),
  78. BLUR_FLAG_GLOW_FIRST_PASS = (1 << 2),
  79. };
  80. struct BlurRasterPushConstant {
  81. float pixel_size[2];
  82. uint32_t flags;
  83. uint32_t pad;
  84. //glow
  85. float glow_strength;
  86. float glow_bloom;
  87. float glow_hdr_threshold;
  88. float glow_hdr_scale;
  89. float glow_exposure;
  90. float glow_white;
  91. float glow_luminance_cap;
  92. float glow_auto_exposure_grey;
  93. };
  94. struct BlurRaster {
  95. BlurRasterPushConstant push_constant;
  96. BlurRasterShaderRD shader;
  97. RID shader_version;
  98. PipelineCacheRD pipelines[BLUR_MODE_MAX];
  99. } blur_raster;
  100. enum CopyMode {
  101. COPY_MODE_GAUSSIAN_COPY,
  102. COPY_MODE_GAUSSIAN_COPY_8BIT,
  103. COPY_MODE_GAUSSIAN_GLOW,
  104. COPY_MODE_GAUSSIAN_GLOW_AUTO_EXPOSURE,
  105. COPY_MODE_SIMPLY_COPY,
  106. COPY_MODE_SIMPLY_COPY_8BIT,
  107. COPY_MODE_SIMPLY_COPY_DEPTH,
  108. COPY_MODE_SET_COLOR,
  109. COPY_MODE_SET_COLOR_8BIT,
  110. COPY_MODE_MIPMAP,
  111. COPY_MODE_LINEARIZE_DEPTH,
  112. COPY_MODE_CUBE_TO_PANORAMA,
  113. COPY_MODE_CUBE_ARRAY_TO_PANORAMA,
  114. COPY_MODE_MAX,
  115. };
  116. enum {
  117. COPY_FLAG_HORIZONTAL = (1 << 0),
  118. COPY_FLAG_USE_COPY_SECTION = (1 << 1),
  119. COPY_FLAG_USE_ORTHOGONAL_PROJECTION = (1 << 2),
  120. COPY_FLAG_DOF_NEAR_FIRST_TAP = (1 << 3),
  121. COPY_FLAG_GLOW_FIRST_PASS = (1 << 4),
  122. COPY_FLAG_FLIP_Y = (1 << 5),
  123. COPY_FLAG_FORCE_LUMINANCE = (1 << 6),
  124. COPY_FLAG_ALL_SOURCE = (1 << 7),
  125. COPY_FLAG_HIGH_QUALITY_GLOW = (1 << 8),
  126. COPY_FLAG_ALPHA_TO_ONE = (1 << 9),
  127. };
  128. struct CopyPushConstant {
  129. int32_t section[4];
  130. int32_t target[2];
  131. uint32_t flags;
  132. uint32_t pad;
  133. // Glow.
  134. float glow_strength;
  135. float glow_bloom;
  136. float glow_hdr_threshold;
  137. float glow_hdr_scale;
  138. float glow_exposure;
  139. float glow_white;
  140. float glow_luminance_cap;
  141. float glow_auto_exposure_grey;
  142. // DOF.
  143. float camera_z_far;
  144. float camera_z_near;
  145. uint32_t pad2[2];
  146. //SET color
  147. float set_color[4];
  148. };
  149. struct Copy {
  150. CopyPushConstant push_constant;
  151. CopyShaderRD shader;
  152. RID shader_version;
  153. RID pipelines[COPY_MODE_MAX];
  154. } copy;
  155. enum CopyToFBMode {
  156. COPY_TO_FB_COPY,
  157. COPY_TO_FB_COPY_PANORAMA_TO_DP,
  158. COPY_TO_FB_COPY2,
  159. COPY_TO_FB_MAX,
  160. };
  161. struct CopyToFbPushConstant {
  162. float section[4];
  163. float pixel_size[2];
  164. uint32_t flip_y;
  165. uint32_t use_section;
  166. uint32_t force_luminance;
  167. uint32_t alpha_to_zero;
  168. uint32_t srgb;
  169. uint32_t pad;
  170. };
  171. struct CopyToFb {
  172. CopyToFbPushConstant push_constant;
  173. CopyToFbShaderRD shader;
  174. RID shader_version;
  175. PipelineCacheRD pipelines[COPY_TO_FB_MAX];
  176. } copy_to_fb;
  177. struct CubemapRoughnessPushConstant {
  178. uint32_t face_id;
  179. uint32_t sample_count;
  180. float roughness;
  181. uint32_t use_direct_write;
  182. float face_size;
  183. float pad[3];
  184. };
  185. struct CubemapRoughness {
  186. CubemapRoughnessPushConstant push_constant;
  187. CubemapRoughnessShaderRD compute_shader;
  188. CubemapRoughnessRasterShaderRD raster_shader;
  189. RID shader_version;
  190. RID compute_pipeline;
  191. PipelineCacheRD raster_pipeline;
  192. } roughness;
  193. enum TonemapMode {
  194. TONEMAP_MODE_NORMAL,
  195. TONEMAP_MODE_BICUBIC_GLOW_FILTER,
  196. TONEMAP_MODE_1D_LUT,
  197. TONEMAP_MODE_BICUBIC_GLOW_FILTER_1D_LUT,
  198. TONEMAP_MODE_SUBPASS,
  199. TONEMAP_MODE_SUBPASS_1D_LUT,
  200. TONEMAP_MODE_NORMAL_MULTIVIEW,
  201. TONEMAP_MODE_BICUBIC_GLOW_FILTER_MULTIVIEW,
  202. TONEMAP_MODE_1D_LUT_MULTIVIEW,
  203. TONEMAP_MODE_BICUBIC_GLOW_FILTER_1D_LUT_MULTIVIEW,
  204. TONEMAP_MODE_SUBPASS_MULTIVIEW,
  205. TONEMAP_MODE_SUBPASS_1D_LUT_MULTIVIEW,
  206. TONEMAP_MODE_MAX
  207. };
  208. struct TonemapPushConstant {
  209. float bcs[3]; // 12 - 12
  210. uint32_t use_bcs; // 4 - 16
  211. uint32_t use_glow; // 4 - 20
  212. uint32_t use_auto_exposure; // 4 - 24
  213. uint32_t use_color_correction; // 4 - 28
  214. uint32_t tonemapper; // 4 - 32
  215. uint32_t glow_texture_size[2]; // 8 - 40
  216. float glow_intensity; // 4 - 44
  217. uint32_t pad3; // 4 - 48
  218. uint32_t glow_mode; // 4 - 52
  219. float glow_levels[7]; // 28 - 80
  220. float exposure; // 4 - 84
  221. float white; // 4 - 88
  222. float auto_exposure_grey; // 4 - 92
  223. float luminance_multiplier; // 4 - 96
  224. float pixel_size[2]; // 8 - 104
  225. uint32_t use_fxaa; // 4 - 108
  226. uint32_t use_debanding; // 4 - 112
  227. };
  228. /* tonemap actually writes to a framebuffer, which is
  229. * better to do using the raster pipeline rather than
  230. * compute, as that framebuffer might be in different formats
  231. */
  232. struct Tonemap {
  233. TonemapPushConstant push_constant;
  234. TonemapShaderRD shader;
  235. RID shader_version;
  236. PipelineCacheRD pipelines[TONEMAP_MODE_MAX];
  237. } tonemap;
  238. enum LuminanceReduceMode {
  239. LUMINANCE_REDUCE_READ,
  240. LUMINANCE_REDUCE,
  241. LUMINANCE_REDUCE_WRITE,
  242. LUMINANCE_REDUCE_MAX
  243. };
  244. struct LuminanceReducePushConstant {
  245. int32_t source_size[2];
  246. float max_luminance;
  247. float min_luminance;
  248. float exposure_adjust;
  249. float pad[3];
  250. };
  251. struct LuminanceReduce {
  252. LuminanceReducePushConstant push_constant;
  253. LuminanceReduceShaderRD shader;
  254. RID shader_version;
  255. RID pipelines[LUMINANCE_REDUCE_MAX];
  256. } luminance_reduce;
  257. enum LuminanceReduceRasterMode {
  258. LUMINANCE_REDUCE_FRAGMENT_FIRST,
  259. LUMINANCE_REDUCE_FRAGMENT,
  260. LUMINANCE_REDUCE_FRAGMENT_FINAL,
  261. LUMINANCE_REDUCE_FRAGMENT_MAX
  262. };
  263. struct LuminanceReduceRasterPushConstant {
  264. int32_t source_size[2];
  265. int32_t dest_size[2];
  266. float exposure_adjust;
  267. float min_luminance;
  268. float max_luminance;
  269. uint32_t pad1;
  270. };
  271. struct LuminanceReduceFragment {
  272. LuminanceReduceRasterPushConstant push_constant;
  273. LuminanceReduceRasterShaderRD shader;
  274. RID shader_version;
  275. PipelineCacheRD pipelines[LUMINANCE_REDUCE_FRAGMENT_MAX];
  276. } luminance_reduce_raster;
  277. struct CopyToDPPushConstant {
  278. float z_far;
  279. float z_near;
  280. float texel_size[2];
  281. float screen_rect[4];
  282. };
  283. struct CoptToDP {
  284. CubeToDpShaderRD shader;
  285. RID shader_version;
  286. PipelineCacheRD pipeline;
  287. } cube_to_dp;
  288. struct BokehPushConstant {
  289. uint32_t size[2];
  290. float z_far;
  291. float z_near;
  292. uint32_t orthogonal;
  293. float blur_size;
  294. float blur_scale;
  295. uint32_t steps;
  296. uint32_t blur_near_active;
  297. float blur_near_begin;
  298. float blur_near_end;
  299. uint32_t blur_far_active;
  300. float blur_far_begin;
  301. float blur_far_end;
  302. uint32_t second_pass;
  303. uint32_t half_size;
  304. uint32_t use_jitter;
  305. float jitter_seed;
  306. uint32_t pad[2];
  307. };
  308. enum BokehMode {
  309. BOKEH_GEN_BLUR_SIZE,
  310. BOKEH_GEN_BOKEH_BOX,
  311. BOKEH_GEN_BOKEH_BOX_NOWEIGHT,
  312. BOKEH_GEN_BOKEH_HEXAGONAL,
  313. BOKEH_GEN_BOKEH_HEXAGONAL_NOWEIGHT,
  314. BOKEH_GEN_BOKEH_CIRCULAR,
  315. BOKEH_COMPOSITE,
  316. BOKEH_MAX
  317. };
  318. struct Bokeh {
  319. BokehPushConstant push_constant;
  320. BokehDofShaderRD compute_shader;
  321. BokehDofRasterShaderRD raster_shader;
  322. RID shader_version;
  323. RID compute_pipelines[BOKEH_MAX];
  324. PipelineCacheRD raster_pipelines[BOKEH_MAX];
  325. } bokeh;
  326. enum SSAOMode {
  327. SSAO_DOWNSAMPLE,
  328. SSAO_DOWNSAMPLE_HALF_RES,
  329. SSAO_DOWNSAMPLE_MIPMAP,
  330. SSAO_DOWNSAMPLE_MIPMAP_HALF_RES,
  331. SSAO_DOWNSAMPLE_HALF,
  332. SSAO_DOWNSAMPLE_HALF_RES_HALF,
  333. SSAO_GATHER,
  334. SSAO_GATHER_BASE,
  335. SSAO_GATHER_ADAPTIVE,
  336. SSAO_GENERATE_IMPORTANCE_MAP,
  337. SSAO_PROCESS_IMPORTANCE_MAPA,
  338. SSAO_PROCESS_IMPORTANCE_MAPB,
  339. SSAO_BLUR_PASS,
  340. SSAO_BLUR_PASS_SMART,
  341. SSAO_BLUR_PASS_WIDE,
  342. SSAO_INTERLEAVE,
  343. SSAO_INTERLEAVE_SMART,
  344. SSAO_INTERLEAVE_HALF,
  345. SSAO_MAX
  346. };
  347. struct SSAODownsamplePushConstant {
  348. float pixel_size[2];
  349. float z_far;
  350. float z_near;
  351. uint32_t orthogonal;
  352. float radius_sq;
  353. uint32_t pad[2];
  354. };
  355. struct SSAOGatherPushConstant {
  356. int32_t screen_size[2];
  357. int pass;
  358. int quality;
  359. float half_screen_pixel_size[2];
  360. int size_multiplier;
  361. float detail_intensity;
  362. float NDC_to_view_mul[2];
  363. float NDC_to_view_add[2];
  364. float pad[2];
  365. float half_screen_pixel_size_x025[2];
  366. float radius;
  367. float intensity;
  368. float shadow_power;
  369. float shadow_clamp;
  370. float fade_out_mul;
  371. float fade_out_add;
  372. float horizon_angle_threshold;
  373. float inv_radius_near_limit;
  374. bool is_orthogonal;
  375. float neg_inv_radius;
  376. float load_counter_avg_div;
  377. float adaptive_sample_limit;
  378. int32_t pass_coord_offset[2];
  379. float pass_uv_offset[2];
  380. };
  381. struct SSAOGatherConstants {
  382. float rotation_matrices[80]; //5 vec4s * 4
  383. };
  384. struct SSAOImportanceMapPushConstant {
  385. float half_screen_pixel_size[2];
  386. float intensity;
  387. float power;
  388. };
  389. struct SSAOBlurPushConstant {
  390. float edge_sharpness;
  391. float pad;
  392. float half_screen_pixel_size[2];
  393. };
  394. struct SSAOInterleavePushConstant {
  395. float inv_sharpness;
  396. uint32_t size_modifier;
  397. float pixel_size[2];
  398. };
  399. struct SSAO {
  400. SSAODownsamplePushConstant downsample_push_constant;
  401. SsaoDownsampleShaderRD downsample_shader;
  402. RID downsample_shader_version;
  403. SSAOGatherPushConstant gather_push_constant;
  404. SsaoShaderRD gather_shader;
  405. RID gather_shader_version;
  406. RID gather_constants_buffer;
  407. bool gather_initialized = false;
  408. SSAOImportanceMapPushConstant importance_map_push_constant;
  409. SsaoImportanceMapShaderRD importance_map_shader;
  410. RID importance_map_shader_version;
  411. RID importance_map_load_counter;
  412. RID counter_uniform_set;
  413. SSAOBlurPushConstant blur_push_constant;
  414. SsaoBlurShaderRD blur_shader;
  415. RID blur_shader_version;
  416. SSAOInterleavePushConstant interleave_push_constant;
  417. SsaoInterleaveShaderRD interleave_shader;
  418. RID interleave_shader_version;
  419. RID mirror_sampler;
  420. RID pipelines[SSAO_MAX];
  421. } ssao;
  422. struct RoughnessLimiterPushConstant {
  423. int32_t screen_size[2];
  424. float curve;
  425. uint32_t pad;
  426. };
  427. struct RoughnessLimiter {
  428. RoughnessLimiterPushConstant push_constant;
  429. RoughnessLimiterShaderRD shader;
  430. RID shader_version;
  431. RID pipeline;
  432. } roughness_limiter;
  433. struct CubemapDownsamplerPushConstant {
  434. uint32_t face_size;
  435. uint32_t face_id;
  436. float pad[2];
  437. };
  438. struct CubemapDownsampler {
  439. CubemapDownsamplerPushConstant push_constant;
  440. CubemapDownsamplerShaderRD compute_shader;
  441. CubemapDownsamplerRasterShaderRD raster_shader;
  442. RID shader_version;
  443. RID compute_pipeline;
  444. PipelineCacheRD raster_pipeline;
  445. } cubemap_downsampler;
  446. enum CubemapFilterMode {
  447. FILTER_MODE_HIGH_QUALITY,
  448. FILTER_MODE_LOW_QUALITY,
  449. FILTER_MODE_HIGH_QUALITY_ARRAY,
  450. FILTER_MODE_LOW_QUALITY_ARRAY,
  451. FILTER_MODE_MAX,
  452. };
  453. struct CubemapFilterRasterPushConstant {
  454. uint32_t mip_level;
  455. uint32_t face_id;
  456. float pad[2];
  457. };
  458. struct CubemapFilter {
  459. CubemapFilterShaderRD compute_shader;
  460. CubemapFilterRasterShaderRD raster_shader;
  461. RID shader_version;
  462. RID compute_pipelines[FILTER_MODE_MAX];
  463. PipelineCacheRD raster_pipelines[FILTER_MODE_MAX];
  464. RID uniform_set;
  465. RID image_uniform_set;
  466. RID coefficient_buffer;
  467. bool use_high_quality;
  468. } filter;
  469. enum SpecularMergeMode {
  470. SPECULAR_MERGE_ADD,
  471. SPECULAR_MERGE_SSR,
  472. SPECULAR_MERGE_ADDITIVE_ADD,
  473. SPECULAR_MERGE_ADDITIVE_SSR,
  474. SPECULAR_MERGE_MAX
  475. };
  476. /* Specular merge must be done using raster, rather than compute
  477. * because it must continue the existing color buffer
  478. */
  479. struct SpecularMerge {
  480. SpecularMergeShaderRD shader;
  481. RID shader_version;
  482. PipelineCacheRD pipelines[SPECULAR_MERGE_MAX];
  483. } specular_merge;
  484. enum ScreenSpaceReflectionMode {
  485. SCREEN_SPACE_REFLECTION_NORMAL,
  486. SCREEN_SPACE_REFLECTION_ROUGH,
  487. SCREEN_SPACE_REFLECTION_MAX,
  488. };
  489. struct ScreenSpaceReflectionPushConstant {
  490. float proj_info[4];
  491. int32_t screen_size[2];
  492. float camera_z_near;
  493. float camera_z_far;
  494. int32_t num_steps;
  495. float depth_tolerance;
  496. float distance_fade;
  497. float curve_fade_in;
  498. uint32_t orthogonal;
  499. float filter_mipmap_levels;
  500. uint32_t use_half_res;
  501. uint8_t metallic_mask[4];
  502. float projection[16];
  503. };
  504. struct ScreenSpaceReflection {
  505. ScreenSpaceReflectionPushConstant push_constant;
  506. ScreenSpaceReflectionShaderRD shader;
  507. RID shader_version;
  508. RID pipelines[SCREEN_SPACE_REFLECTION_MAX];
  509. } ssr;
  510. struct ScreenSpaceReflectionFilterPushConstant {
  511. float proj_info[4];
  512. uint32_t orthogonal;
  513. float edge_tolerance;
  514. int32_t increment;
  515. uint32_t pad;
  516. int32_t screen_size[2];
  517. uint32_t vertical;
  518. uint32_t steps;
  519. };
  520. enum {
  521. SCREEN_SPACE_REFLECTION_FILTER_HORIZONTAL,
  522. SCREEN_SPACE_REFLECTION_FILTER_VERTICAL,
  523. SCREEN_SPACE_REFLECTION_FILTER_MAX,
  524. };
  525. struct ScreenSpaceReflectionFilter {
  526. ScreenSpaceReflectionFilterPushConstant push_constant;
  527. ScreenSpaceReflectionFilterShaderRD shader;
  528. RID shader_version;
  529. RID pipelines[SCREEN_SPACE_REFLECTION_FILTER_MAX];
  530. } ssr_filter;
  531. struct ScreenSpaceReflectionScalePushConstant {
  532. int32_t screen_size[2];
  533. float camera_z_near;
  534. float camera_z_far;
  535. uint32_t orthogonal;
  536. uint32_t filter;
  537. uint32_t pad[2];
  538. };
  539. struct ScreenSpaceReflectionScale {
  540. ScreenSpaceReflectionScalePushConstant push_constant;
  541. ScreenSpaceReflectionScaleShaderRD shader;
  542. RID shader_version;
  543. RID pipeline;
  544. } ssr_scale;
  545. struct SubSurfaceScatteringPushConstant {
  546. int32_t screen_size[2];
  547. float camera_z_far;
  548. float camera_z_near;
  549. uint32_t vertical;
  550. uint32_t orthogonal;
  551. float unit_size;
  552. float scale;
  553. float depth_scale;
  554. uint32_t pad[3];
  555. };
  556. struct SubSurfaceScattering {
  557. SubSurfaceScatteringPushConstant push_constant;
  558. SubsurfaceScatteringShaderRD shader;
  559. RID shader_version;
  560. RID pipelines[3]; //3 quality levels
  561. } sss;
  562. struct ResolvePushConstant {
  563. int32_t screen_size[2];
  564. int32_t samples;
  565. uint32_t pad;
  566. };
  567. enum ResolveMode {
  568. RESOLVE_MODE_GI,
  569. RESOLVE_MODE_GI_VOXEL_GI,
  570. RESOLVE_MODE_DEPTH,
  571. RESOLVE_MODE_MAX
  572. };
  573. struct Resolve {
  574. ResolvePushConstant push_constant;
  575. ResolveShaderRD shader;
  576. RID shader_version;
  577. RID pipelines[RESOLVE_MODE_MAX]; //3 quality levels
  578. } resolve;
  579. enum SortMode {
  580. SORT_MODE_BLOCK,
  581. SORT_MODE_STEP,
  582. SORT_MODE_INNER,
  583. SORT_MODE_MAX
  584. };
  585. struct Sort {
  586. struct PushConstant {
  587. uint32_t total_elements;
  588. uint32_t pad[3];
  589. int32_t job_params[4];
  590. };
  591. SortShaderRD shader;
  592. RID shader_version;
  593. RID pipelines[SORT_MODE_MAX];
  594. } sort;
  595. RID default_sampler;
  596. RID default_mipmap_sampler;
  597. RID index_buffer;
  598. RID index_array;
  599. Map<RID, RID> texture_to_uniform_set_cache;
  600. Map<RID, RID> input_to_uniform_set_cache;
  601. Map<RID, RID> image_to_uniform_set_cache;
  602. struct TexturePair {
  603. RID texture1;
  604. RID texture2;
  605. _FORCE_INLINE_ bool operator<(const TexturePair &p_pair) const {
  606. if (texture1 == p_pair.texture1) {
  607. return texture2 < p_pair.texture2;
  608. } else {
  609. return texture1 < p_pair.texture1;
  610. }
  611. }
  612. };
  613. struct TextureSamplerPair {
  614. RID texture;
  615. RID sampler;
  616. _FORCE_INLINE_ bool operator<(const TextureSamplerPair &p_pair) const {
  617. if (texture == p_pair.texture) {
  618. return sampler < p_pair.sampler;
  619. } else {
  620. return texture < p_pair.texture;
  621. }
  622. }
  623. };
  624. Map<RID, RID> texture_to_compute_uniform_set_cache;
  625. Map<TexturePair, RID> texture_pair_to_compute_uniform_set_cache;
  626. Map<TexturePair, RID> image_pair_to_compute_uniform_set_cache;
  627. Map<TextureSamplerPair, RID> texture_sampler_to_compute_uniform_set_cache;
  628. RID _get_uniform_set_from_image(RID p_texture);
  629. RID _get_uniform_set_for_input(RID p_texture);
  630. RID _get_uniform_set_from_texture(RID p_texture, bool p_use_mipmaps = false);
  631. RID _get_compute_uniform_set_from_texture(RID p_texture, bool p_use_mipmaps = false);
  632. RID _get_compute_uniform_set_from_texture_and_sampler(RID p_texture, RID p_sampler);
  633. RID _get_compute_uniform_set_from_texture_pair(RID p_texture, RID p_texture2, bool p_use_mipmaps = false);
  634. RID _get_compute_uniform_set_from_image_pair(RID p_texture, RID p_texture2);
  635. public:
  636. bool get_prefer_raster_effects();
  637. 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());
  638. 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);
  639. 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);
  640. void copy_depth_to_rect(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2i &p_rect, bool p_flip_y = false);
  641. 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);
  642. 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);
  643. void gaussian_blur(RID p_source_rd_texture, RID p_texture, RID p_back_texture, const Rect2i &p_region, bool p_8bit_dst = false);
  644. void set_color(RID p_dest_texture, const Color &p_color, const Rect2i &p_region, bool p_8bit_dst = false);
  645. 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_grey = 1.0);
  646. void gaussian_glow_raster(RID p_source_rd_texture, RID p_framebuffer_half, RID p_rd_texture_half, RID p_dest_framebuffer, const Vector2 &p_pixel_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_grey = 1.0);
  647. 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);
  648. 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);
  649. void make_mipmap(RID p_source_rd_texture, RID p_dest_texture, const Size2i &p_size);
  650. void make_mipmap_raster(RID p_source_rd_texture, RID p_dest_framebuffer, const Size2i &p_size);
  651. 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);
  652. void luminance_reduction(RID p_source_texture, const Size2i p_source_size, const Vector<RID> p_reduce, RID p_prev_luminance, float p_min_luminance, float p_max_luminance, float p_adjust, bool p_set = false);
  653. void luminance_reduction_raster(RID p_source_texture, const Size2i p_source_size, const Vector<RID> p_reduce, Vector<RID> p_fb, RID p_prev_luminance, float p_min_luminance, float p_max_luminance, float p_adjust, bool p_set = false);
  654. struct BokehBuffers {
  655. // bokeh buffers
  656. // textures
  657. Size2i base_texture_size;
  658. RID base_texture;
  659. RID depth_texture;
  660. RID secondary_texture;
  661. RID half_texture[2];
  662. // raster only
  663. RID base_fb;
  664. RID secondary_fb; // with weights
  665. RID half_fb[2]; // with weights
  666. RID base_weight_fb;
  667. RID weight_texture[4];
  668. };
  669. void bokeh_dof(const BokehBuffers &p_buffers, bool p_dof_far, float p_dof_far_begin, float p_dof_far_size, bool p_dof_near, float p_dof_near_begin, float p_dof_near_size, float p_bokeh_size, RS::DOFBokehShape p_bokeh_shape, RS::DOFBlurQuality p_quality, bool p_use_jitter, float p_cam_znear, float p_cam_zfar, bool p_cam_orthogonal);
  670. void bokeh_dof_raster(const BokehBuffers &p_buffers, bool p_dof_far, float p_dof_far_begin, float p_dof_far_size, bool p_dof_near, float p_dof_near_begin, float p_dof_near_size, float p_dof_blur_amount, RenderingServer::DOFBokehShape p_bokeh_shape, RS::DOFBlurQuality p_quality, float p_cam_znear, float p_cam_zfar, bool p_cam_orthogonal);
  671. struct TonemapSettings {
  672. bool use_glow = false;
  673. enum GlowMode {
  674. GLOW_MODE_ADD,
  675. GLOW_MODE_SCREEN,
  676. GLOW_MODE_SOFTLIGHT,
  677. GLOW_MODE_REPLACE,
  678. GLOW_MODE_MIX
  679. };
  680. GlowMode glow_mode = GLOW_MODE_ADD;
  681. float glow_intensity = 1.0;
  682. float glow_levels[7] = { 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0 };
  683. Vector2i glow_texture_size;
  684. bool glow_use_bicubic_upscale = false;
  685. RID glow_texture;
  686. RS::EnvironmentToneMapper tonemap_mode = RS::ENV_TONE_MAPPER_LINEAR;
  687. float exposure = 1.0;
  688. float white = 1.0;
  689. bool use_auto_exposure = false;
  690. float auto_exposure_grey = 0.5;
  691. RID exposure_texture;
  692. float luminance_multiplier = 1.0;
  693. bool use_bcs = false;
  694. float brightness = 1.0;
  695. float contrast = 1.0;
  696. float saturation = 1.0;
  697. bool use_color_correction = false;
  698. bool use_1d_color_correction = false;
  699. RID color_correction_texture;
  700. bool use_fxaa = false;
  701. bool use_debanding = false;
  702. Vector2i texture_size;
  703. uint32_t view_count = 1;
  704. };
  705. struct SSAOSettings {
  706. float radius = 1.0;
  707. float intensity = 2.0;
  708. float power = 1.5;
  709. float detail = 0.5;
  710. float horizon = 0.06;
  711. float sharpness = 0.98;
  712. RS::EnvironmentSSAOQuality quality = RS::ENV_SSAO_QUALITY_MEDIUM;
  713. bool half_size = false;
  714. float adaptive_target = 0.5;
  715. int blur_passes = 2;
  716. float fadeout_from = 50.0;
  717. float fadeout_to = 300.0;
  718. Size2i full_screen_size = Size2i();
  719. Size2i half_screen_size = Size2i();
  720. Size2i quarter_screen_size = Size2i();
  721. };
  722. void tonemapper(RID p_source_color, RID p_dst_framebuffer, const TonemapSettings &p_settings);
  723. void tonemapper(RD::DrawListID p_subpass_draw_list, RID p_source_color, RD::FramebufferFormatID p_dst_format_id, const TonemapSettings &p_settings);
  724. void gather_ssao(RD::ComputeListID p_compute_list, const Vector<RID> p_ao_slices, const SSAOSettings &p_settings, bool p_adaptive_base_pass, RID p_gather_uniform_set, RID p_importance_map_uniform_set);
  725. void generate_ssao(RID p_depth_buffer, RID p_normal_buffer, RID p_depth_mipmaps_texture, const Vector<RID> &depth_mipmaps, RID p_ao, const Vector<RID> p_ao_slices, RID p_ao_pong, const Vector<RID> p_ao_pong_slices, RID p_upscale_buffer, RID p_importance_map, RID p_importance_map_pong, const CameraMatrix &p_projection, const SSAOSettings &p_settings, bool p_invalidate_uniform_sets, RID &r_downsample_uniform_set, RID &r_gather_uniform_set, RID &r_importance_map_uniform_set);
  726. void roughness_limit(RID p_source_normal, RID p_roughness, const Size2i &p_size, float p_curve);
  727. void cubemap_downsample(RID p_source_cubemap, RID p_dest_cubemap, const Size2i &p_size);
  728. void cubemap_downsample_raster(RID p_source_cubemap, RID p_dest_framebuffer, uint32_t p_face_id, const Size2i &p_size);
  729. void cubemap_filter(RID p_source_cubemap, Vector<RID> p_dest_cubemap, bool p_use_array);
  730. void cubemap_filter_raster(RID p_source_cubemap, RID p_dest_framebuffer, uint32_t p_face_id, uint32_t p_mip_level);
  731. void screen_space_reflection(RID p_diffuse, RID p_normal_roughness, RS::EnvironmentSSRRoughnessQuality p_roughness_quality, RID p_blur_radius, RID p_blur_radius2, RID p_metallic, const Color &p_metallic_mask, RID p_depth, RID p_scale_depth, RID p_scale_normal, RID p_output, RID p_output_blur, const Size2i &p_screen_size, int p_max_steps, float p_fade_in, float p_fade_out, float p_tolerance, const CameraMatrix &p_camera);
  732. void merge_specular(RID p_dest_framebuffer, RID p_specular, RID p_base, RID p_reflection);
  733. void sub_surface_scattering(RID p_diffuse, RID p_diffuse2, RID p_depth, const CameraMatrix &p_camera, const Size2i &p_screen_size, float p_scale, float p_depth_scale, RS::SubSurfaceScatteringQuality p_quality);
  734. void resolve_gi(RID p_source_depth, RID p_source_normal_roughness, RID p_source_voxel_gi, RID p_dest_depth, RID p_dest_normal_roughness, RID p_dest_voxel_gi, Vector2i p_screen_size, int p_samples, uint32_t p_barrier = RD::BARRIER_MASK_ALL);
  735. void resolve_depth(RID p_source_depth, RID p_dest_depth, Vector2i p_screen_size, int p_samples, uint32_t p_barrier = RD::BARRIER_MASK_ALL);
  736. void sort_buffer(RID p_uniform_set, int p_size);
  737. EffectsRD(bool p_prefer_raster_effects);
  738. ~EffectsRD();
  739. };
  740. #endif // !RASTERIZER_EFFECTS_RD_H