effects_rd.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  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/bokeh_dof.glsl.gen.h"
  35. #include "servers/rendering/renderer_rd/shaders/copy.glsl.gen.h"
  36. #include "servers/rendering/renderer_rd/shaders/copy_to_fb.glsl.gen.h"
  37. #include "servers/rendering/renderer_rd/shaders/cube_to_dp.glsl.gen.h"
  38. #include "servers/rendering/renderer_rd/shaders/cubemap_downsampler.glsl.gen.h"
  39. #include "servers/rendering/renderer_rd/shaders/cubemap_filter.glsl.gen.h"
  40. #include "servers/rendering/renderer_rd/shaders/cubemap_roughness.glsl.gen.h"
  41. #include "servers/rendering/renderer_rd/shaders/luminance_reduce.glsl.gen.h"
  42. #include "servers/rendering/renderer_rd/shaders/resolve.glsl.gen.h"
  43. #include "servers/rendering/renderer_rd/shaders/roughness_limiter.glsl.gen.h"
  44. #include "servers/rendering/renderer_rd/shaders/screen_space_reflection.glsl.gen.h"
  45. #include "servers/rendering/renderer_rd/shaders/screen_space_reflection_filter.glsl.gen.h"
  46. #include "servers/rendering/renderer_rd/shaders/screen_space_reflection_scale.glsl.gen.h"
  47. #include "servers/rendering/renderer_rd/shaders/sort.glsl.gen.h"
  48. #include "servers/rendering/renderer_rd/shaders/specular_merge.glsl.gen.h"
  49. #include "servers/rendering/renderer_rd/shaders/ssao.glsl.gen.h"
  50. #include "servers/rendering/renderer_rd/shaders/ssao_blur.glsl.gen.h"
  51. #include "servers/rendering/renderer_rd/shaders/ssao_downsample.glsl.gen.h"
  52. #include "servers/rendering/renderer_rd/shaders/ssao_importance_map.glsl.gen.h"
  53. #include "servers/rendering/renderer_rd/shaders/ssao_interleave.glsl.gen.h"
  54. #include "servers/rendering/renderer_rd/shaders/subsurface_scattering.glsl.gen.h"
  55. #include "servers/rendering/renderer_rd/shaders/tonemap.glsl.gen.h"
  56. #include "servers/rendering_server.h"
  57. class EffectsRD {
  58. enum CopyMode {
  59. COPY_MODE_GAUSSIAN_COPY,
  60. COPY_MODE_GAUSSIAN_COPY_8BIT,
  61. COPY_MODE_GAUSSIAN_GLOW,
  62. COPY_MODE_GAUSSIAN_GLOW_AUTO_EXPOSURE,
  63. COPY_MODE_SIMPLY_COPY,
  64. COPY_MODE_SIMPLY_COPY_8BIT,
  65. COPY_MODE_SIMPLY_COPY_DEPTH,
  66. COPY_MODE_SET_COLOR,
  67. COPY_MODE_SET_COLOR_8BIT,
  68. COPY_MODE_MIPMAP,
  69. COPY_MODE_LINEARIZE_DEPTH,
  70. COPY_MODE_CUBE_TO_PANORAMA,
  71. COPY_MODE_CUBE_ARRAY_TO_PANORAMA,
  72. COPY_MODE_MAX,
  73. };
  74. enum {
  75. COPY_FLAG_HORIZONTAL = (1 << 0),
  76. COPY_FLAG_USE_COPY_SECTION = (1 << 1),
  77. COPY_FLAG_USE_ORTHOGONAL_PROJECTION = (1 << 2),
  78. COPY_FLAG_DOF_NEAR_FIRST_TAP = (1 << 3),
  79. COPY_FLAG_GLOW_FIRST_PASS = (1 << 4),
  80. COPY_FLAG_FLIP_Y = (1 << 5),
  81. COPY_FLAG_FORCE_LUMINANCE = (1 << 6),
  82. COPY_FLAG_ALL_SOURCE = (1 << 7),
  83. COPY_FLAG_HIGH_QUALITY_GLOW = (1 << 8),
  84. COPY_FLAG_ALPHA_TO_ONE = (1 << 9),
  85. };
  86. struct CopyPushConstant {
  87. int32_t section[4];
  88. int32_t target[2];
  89. uint32_t flags;
  90. uint32_t pad;
  91. // Glow.
  92. float glow_strength;
  93. float glow_bloom;
  94. float glow_hdr_threshold;
  95. float glow_hdr_scale;
  96. float glow_exposure;
  97. float glow_white;
  98. float glow_luminance_cap;
  99. float glow_auto_exposure_grey;
  100. // DOF.
  101. float camera_z_far;
  102. float camera_z_near;
  103. uint32_t pad2[2];
  104. //SET color
  105. float set_color[4];
  106. };
  107. struct Copy {
  108. CopyPushConstant push_constant;
  109. CopyShaderRD shader;
  110. RID shader_version;
  111. RID pipelines[COPY_MODE_MAX];
  112. } copy;
  113. enum CopyToFBMode {
  114. COPY_TO_FB_COPY,
  115. COPY_TO_FB_COPY_PANORAMA_TO_DP,
  116. COPY_TO_FB_COPY2,
  117. COPY_TO_FB_MAX,
  118. };
  119. struct CopyToFbPushConstant {
  120. float section[4];
  121. float pixel_size[2];
  122. uint32_t flip_y;
  123. uint32_t use_section;
  124. uint32_t force_luminance;
  125. uint32_t alpha_to_zero;
  126. uint32_t srgb;
  127. uint32_t pad;
  128. };
  129. struct CopyToFb {
  130. CopyToFbPushConstant push_constant;
  131. CopyToFbShaderRD shader;
  132. RID shader_version;
  133. PipelineCacheRD pipelines[COPY_TO_FB_MAX];
  134. } copy_to_fb;
  135. struct CubemapRoughnessPushConstant {
  136. uint32_t face_id;
  137. uint32_t sample_count;
  138. float roughness;
  139. uint32_t use_direct_write;
  140. float face_size;
  141. float pad[3];
  142. };
  143. struct CubemapRoughness {
  144. CubemapRoughnessPushConstant push_constant;
  145. CubemapRoughnessShaderRD shader;
  146. RID shader_version;
  147. RID pipeline;
  148. } roughness;
  149. enum TonemapMode {
  150. TONEMAP_MODE_NORMAL,
  151. TONEMAP_MODE_BICUBIC_GLOW_FILTER,
  152. TONEMAP_MODE_1D_LUT,
  153. TONEMAP_MODE_BICUBIC_GLOW_FILTER_1D_LUT,
  154. TONEMAP_MODE_MAX
  155. };
  156. struct TonemapPushConstant {
  157. float bcs[3];
  158. uint32_t use_bcs;
  159. uint32_t use_glow;
  160. uint32_t use_auto_exposure;
  161. uint32_t use_color_correction;
  162. uint32_t tonemapper;
  163. uint32_t glow_texture_size[2];
  164. float glow_intensity;
  165. uint32_t pad3;
  166. uint32_t glow_mode;
  167. float glow_levels[7];
  168. float exposure;
  169. float white;
  170. float auto_exposure_grey;
  171. uint32_t pad2;
  172. float pixel_size[2];
  173. uint32_t use_fxaa;
  174. uint32_t use_debanding;
  175. };
  176. /* tonemap actually writes to a framebuffer, which is
  177. * better to do using the raster pipeline rather than
  178. * compute, as that framebuffer might be in different formats
  179. */
  180. struct Tonemap {
  181. TonemapPushConstant push_constant;
  182. TonemapShaderRD shader;
  183. RID shader_version;
  184. PipelineCacheRD pipelines[TONEMAP_MODE_MAX];
  185. } tonemap;
  186. enum LuminanceReduceMode {
  187. LUMINANCE_REDUCE_READ,
  188. LUMINANCE_REDUCE,
  189. LUMINANCE_REDUCE_WRITE,
  190. LUMINANCE_REDUCE_MAX
  191. };
  192. struct LuminanceReducePushConstant {
  193. int32_t source_size[2];
  194. float max_luminance;
  195. float min_luminance;
  196. float exposure_adjust;
  197. float pad[3];
  198. };
  199. struct LuminanceReduce {
  200. LuminanceReducePushConstant push_constant;
  201. LuminanceReduceShaderRD shader;
  202. RID shader_version;
  203. RID pipelines[LUMINANCE_REDUCE_MAX];
  204. } luminance_reduce;
  205. struct CopyToDPPushConstant {
  206. float z_far;
  207. float z_near;
  208. uint32_t z_flip;
  209. uint32_t pad;
  210. float screen_rect[4];
  211. };
  212. struct CoptToDP {
  213. CubeToDpShaderRD shader;
  214. RID shader_version;
  215. PipelineCacheRD pipeline;
  216. } cube_to_dp;
  217. struct BokehPushConstant {
  218. uint32_t size[2];
  219. float z_far;
  220. float z_near;
  221. uint32_t orthogonal;
  222. float blur_size;
  223. float blur_scale;
  224. uint32_t steps;
  225. uint32_t blur_near_active;
  226. float blur_near_begin;
  227. float blur_near_end;
  228. uint32_t blur_far_active;
  229. float blur_far_begin;
  230. float blur_far_end;
  231. uint32_t second_pass;
  232. uint32_t half_size;
  233. uint32_t use_jitter;
  234. float jitter_seed;
  235. uint32_t pad[2];
  236. };
  237. enum BokehMode {
  238. BOKEH_GEN_BLUR_SIZE,
  239. BOKEH_GEN_BOKEH_BOX,
  240. BOKEH_GEN_BOKEH_HEXAGONAL,
  241. BOKEH_GEN_BOKEH_CIRCULAR,
  242. BOKEH_COMPOSITE,
  243. BOKEH_MAX
  244. };
  245. struct Bokeh {
  246. BokehPushConstant push_constant;
  247. BokehDofShaderRD shader;
  248. RID shader_version;
  249. RID pipelines[BOKEH_MAX];
  250. } bokeh;
  251. enum SSAOMode {
  252. SSAO_DOWNSAMPLE,
  253. SSAO_DOWNSAMPLE_HALF_RES,
  254. SSAO_DOWNSAMPLE_MIPMAP,
  255. SSAO_DOWNSAMPLE_MIPMAP_HALF_RES,
  256. SSAO_DOWNSAMPLE_HALF,
  257. SSAO_DOWNSAMPLE_HALF_RES_HALF,
  258. SSAO_GATHER,
  259. SSAO_GATHER_BASE,
  260. SSAO_GATHER_ADAPTIVE,
  261. SSAO_GENERATE_IMPORTANCE_MAP,
  262. SSAO_PROCESS_IMPORTANCE_MAPA,
  263. SSAO_PROCESS_IMPORTANCE_MAPB,
  264. SSAO_BLUR_PASS,
  265. SSAO_BLUR_PASS_SMART,
  266. SSAO_BLUR_PASS_WIDE,
  267. SSAO_INTERLEAVE,
  268. SSAO_INTERLEAVE_SMART,
  269. SSAO_INTERLEAVE_HALF,
  270. SSAO_MAX
  271. };
  272. struct SSAODownsamplePushConstant {
  273. float pixel_size[2];
  274. float z_far;
  275. float z_near;
  276. uint32_t orthogonal;
  277. float radius_sq;
  278. uint32_t pad[2];
  279. };
  280. struct SSAOGatherPushConstant {
  281. int32_t screen_size[2];
  282. int pass;
  283. int quality;
  284. float half_screen_pixel_size[2];
  285. int size_multiplier;
  286. float detail_intensity;
  287. float NDC_to_view_mul[2];
  288. float NDC_to_view_add[2];
  289. float pad[2];
  290. float half_screen_pixel_size_x025[2];
  291. float radius;
  292. float intensity;
  293. float shadow_power;
  294. float shadow_clamp;
  295. float fade_out_mul;
  296. float fade_out_add;
  297. float horizon_angle_threshold;
  298. float inv_radius_near_limit;
  299. bool is_orthogonal;
  300. float neg_inv_radius;
  301. float load_counter_avg_div;
  302. float adaptive_sample_limit;
  303. int32_t pass_coord_offset[2];
  304. float pass_uv_offset[2];
  305. };
  306. struct SSAOGatherConstants {
  307. float rotation_matrices[80]; //5 vec4s * 4
  308. };
  309. struct SSAOImportanceMapPushConstant {
  310. float half_screen_pixel_size[2];
  311. float intensity;
  312. float power;
  313. };
  314. struct SSAOBlurPushConstant {
  315. float edge_sharpness;
  316. float pad;
  317. float half_screen_pixel_size[2];
  318. };
  319. struct SSAOInterleavePushConstant {
  320. float inv_sharpness;
  321. uint32_t size_modifier;
  322. float pixel_size[2];
  323. };
  324. struct SSAO {
  325. SSAODownsamplePushConstant downsample_push_constant;
  326. SsaoDownsampleShaderRD downsample_shader;
  327. RID downsample_shader_version;
  328. RID downsample_uniform_set;
  329. SSAOGatherPushConstant gather_push_constant;
  330. SsaoShaderRD gather_shader;
  331. RID gather_shader_version;
  332. RID gather_uniform_set;
  333. RID gather_constants_buffer;
  334. bool gather_initialized = false;
  335. SSAOImportanceMapPushConstant importance_map_push_constant;
  336. SsaoImportanceMapShaderRD importance_map_shader;
  337. RID importance_map_shader_version;
  338. RID importance_map_load_counter;
  339. RID importance_map_uniform_set;
  340. RID counter_uniform_set;
  341. SSAOBlurPushConstant blur_push_constant;
  342. SsaoBlurShaderRD blur_shader;
  343. RID blur_shader_version;
  344. SSAOInterleavePushConstant interleave_push_constant;
  345. SsaoInterleaveShaderRD interleave_shader;
  346. RID interleave_shader_version;
  347. RID mirror_sampler;
  348. RID pipelines[SSAO_MAX];
  349. } ssao;
  350. struct RoughnessLimiterPushConstant {
  351. int32_t screen_size[2];
  352. float curve;
  353. uint32_t pad;
  354. };
  355. struct RoughnessLimiter {
  356. RoughnessLimiterPushConstant push_constant;
  357. RoughnessLimiterShaderRD shader;
  358. RID shader_version;
  359. RID pipeline;
  360. } roughness_limiter;
  361. struct CubemapDownsamplerPushConstant {
  362. uint32_t face_size;
  363. float pad[3];
  364. };
  365. struct CubemapDownsampler {
  366. CubemapDownsamplerPushConstant push_constant;
  367. CubemapDownsamplerShaderRD shader;
  368. RID shader_version;
  369. RID pipeline;
  370. } cubemap_downsampler;
  371. enum CubemapFilterMode {
  372. FILTER_MODE_HIGH_QUALITY,
  373. FILTER_MODE_LOW_QUALITY,
  374. FILTER_MODE_HIGH_QUALITY_ARRAY,
  375. FILTER_MODE_LOW_QUALITY_ARRAY,
  376. FILTER_MODE_MAX,
  377. };
  378. struct CubemapFilter {
  379. CubemapFilterShaderRD shader;
  380. RID shader_version;
  381. RID pipelines[FILTER_MODE_MAX];
  382. RID uniform_set;
  383. RID image_uniform_set;
  384. RID coefficient_buffer;
  385. bool use_high_quality;
  386. } filter;
  387. struct SkyPushConstant {
  388. float orientation[12];
  389. float proj[4];
  390. float position[3];
  391. float multiplier;
  392. float time;
  393. float pad[3];
  394. };
  395. enum SpecularMergeMode {
  396. SPECULAR_MERGE_ADD,
  397. SPECULAR_MERGE_SSR,
  398. SPECULAR_MERGE_ADDITIVE_ADD,
  399. SPECULAR_MERGE_ADDITIVE_SSR,
  400. SPECULAR_MERGE_MAX
  401. };
  402. /* Specular merge must be done using raster, rather than compute
  403. * because it must continue the existing color buffer
  404. */
  405. struct SpecularMerge {
  406. SpecularMergeShaderRD shader;
  407. RID shader_version;
  408. PipelineCacheRD pipelines[SPECULAR_MERGE_MAX];
  409. } specular_merge;
  410. enum ScreenSpaceReflectionMode {
  411. SCREEN_SPACE_REFLECTION_NORMAL,
  412. SCREEN_SPACE_REFLECTION_ROUGH,
  413. SCREEN_SPACE_REFLECTION_MAX,
  414. };
  415. struct ScreenSpaceReflectionPushConstant {
  416. float proj_info[4];
  417. int32_t screen_size[2];
  418. float camera_z_near;
  419. float camera_z_far;
  420. int32_t num_steps;
  421. float depth_tolerance;
  422. float distance_fade;
  423. float curve_fade_in;
  424. uint32_t orthogonal;
  425. float filter_mipmap_levels;
  426. uint32_t use_half_res;
  427. uint8_t metallic_mask[4];
  428. float projection[16];
  429. };
  430. struct ScreenSpaceReflection {
  431. ScreenSpaceReflectionPushConstant push_constant;
  432. ScreenSpaceReflectionShaderRD shader;
  433. RID shader_version;
  434. RID pipelines[SCREEN_SPACE_REFLECTION_MAX];
  435. } ssr;
  436. struct ScreenSpaceReflectionFilterPushConstant {
  437. float proj_info[4];
  438. uint32_t orthogonal;
  439. float edge_tolerance;
  440. int32_t increment;
  441. uint32_t pad;
  442. int32_t screen_size[2];
  443. uint32_t vertical;
  444. uint32_t steps;
  445. };
  446. enum {
  447. SCREEN_SPACE_REFLECTION_FILTER_HORIZONTAL,
  448. SCREEN_SPACE_REFLECTION_FILTER_VERTICAL,
  449. SCREEN_SPACE_REFLECTION_FILTER_MAX,
  450. };
  451. struct ScreenSpaceReflectionFilter {
  452. ScreenSpaceReflectionFilterPushConstant push_constant;
  453. ScreenSpaceReflectionFilterShaderRD shader;
  454. RID shader_version;
  455. RID pipelines[SCREEN_SPACE_REFLECTION_FILTER_MAX];
  456. } ssr_filter;
  457. struct ScreenSpaceReflectionScalePushConstant {
  458. int32_t screen_size[2];
  459. float camera_z_near;
  460. float camera_z_far;
  461. uint32_t orthogonal;
  462. uint32_t filter;
  463. uint32_t pad[2];
  464. };
  465. struct ScreenSpaceReflectionScale {
  466. ScreenSpaceReflectionScalePushConstant push_constant;
  467. ScreenSpaceReflectionScaleShaderRD shader;
  468. RID shader_version;
  469. RID pipeline;
  470. } ssr_scale;
  471. struct SubSurfaceScatteringPushConstant {
  472. int32_t screen_size[2];
  473. float camera_z_far;
  474. float camera_z_near;
  475. uint32_t vertical;
  476. uint32_t orthogonal;
  477. float unit_size;
  478. float scale;
  479. float depth_scale;
  480. uint32_t pad[3];
  481. };
  482. struct SubSurfaceScattering {
  483. SubSurfaceScatteringPushConstant push_constant;
  484. SubsurfaceScatteringShaderRD shader;
  485. RID shader_version;
  486. RID pipelines[3]; //3 quality levels
  487. } sss;
  488. struct ResolvePushConstant {
  489. int32_t screen_size[2];
  490. int32_t samples;
  491. uint32_t pad;
  492. };
  493. enum ResolveMode {
  494. RESOLVE_MODE_GI,
  495. RESOLVE_MODE_GI_GIPROBE,
  496. RESOLVE_MODE_MAX
  497. };
  498. struct Resolve {
  499. ResolvePushConstant push_constant;
  500. ResolveShaderRD shader;
  501. RID shader_version;
  502. RID pipelines[RESOLVE_MODE_MAX]; //3 quality levels
  503. } resolve;
  504. enum SortMode {
  505. SORT_MODE_BLOCK,
  506. SORT_MODE_STEP,
  507. SORT_MODE_INNER,
  508. SORT_MODE_MAX
  509. };
  510. struct Sort {
  511. struct PushConstant {
  512. uint32_t total_elements;
  513. uint32_t pad[3];
  514. int32_t job_params[4];
  515. };
  516. SortShaderRD shader;
  517. RID shader_version;
  518. RID pipelines[SORT_MODE_MAX];
  519. } sort;
  520. RID default_sampler;
  521. RID default_mipmap_sampler;
  522. RID index_buffer;
  523. RID index_array;
  524. Map<RID, RID> texture_to_uniform_set_cache;
  525. Map<RID, RID> image_to_uniform_set_cache;
  526. struct TexturePair {
  527. RID texture1;
  528. RID texture2;
  529. _FORCE_INLINE_ bool operator<(const TexturePair &p_pair) const {
  530. if (texture1 == p_pair.texture1) {
  531. return texture2 < p_pair.texture2;
  532. } else {
  533. return texture1 < p_pair.texture1;
  534. }
  535. }
  536. };
  537. struct TextureSamplerPair {
  538. RID texture;
  539. RID sampler;
  540. _FORCE_INLINE_ bool operator<(const TextureSamplerPair &p_pair) const {
  541. if (texture == p_pair.texture) {
  542. return sampler < p_pair.sampler;
  543. } else {
  544. return texture < p_pair.texture;
  545. }
  546. }
  547. };
  548. Map<RID, RID> texture_to_compute_uniform_set_cache;
  549. Map<TexturePair, RID> texture_pair_to_compute_uniform_set_cache;
  550. Map<TexturePair, RID> image_pair_to_compute_uniform_set_cache;
  551. Map<TextureSamplerPair, RID> texture_sampler_to_compute_uniform_set_cache;
  552. RID _get_uniform_set_from_image(RID p_texture);
  553. RID _get_uniform_set_from_texture(RID p_texture, bool p_use_mipmaps = false);
  554. RID _get_compute_uniform_set_from_texture(RID p_texture, bool p_use_mipmaps = false);
  555. RID _get_compute_uniform_set_from_texture_and_sampler(RID p_texture, RID p_sampler);
  556. RID _get_compute_uniform_set_from_texture_pair(RID p_texture, RID p_texture2, bool p_use_mipmaps = false);
  557. RID _get_compute_uniform_set_from_image_pair(RID p_texture, RID p_texture2);
  558. public:
  559. 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());
  560. 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);
  561. 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);
  562. void copy_depth_to_rect(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2i &p_rect, bool p_flip_y = false);
  563. 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);
  564. 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);
  565. void gaussian_blur(RID p_source_rd_texture, RID p_texture, RID p_back_texture, const Rect2i &p_region, bool p_8bit_dst = false);
  566. void set_color(RID p_dest_texture, const Color &p_color, const Rect2i &p_region, bool p_8bit_dst = false);
  567. 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_treshold = 1.0, float p_hdr_bleed_scale = 1.0, RID p_auto_exposure = RID(), float p_auto_exposure_grey = 1.0);
  568. void cubemap_roughness(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);
  569. void make_mipmap(RID p_source_rd_texture, RID p_dest_texture, const Size2i &p_size);
  570. void copy_cubemap_to_dp(RID p_source_rd_texture, RID p_dest_texture, const Rect2 &p_rect, float p_z_near, float p_z_far, bool p_dp_flip);
  571. 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);
  572. void bokeh_dof(RID p_base_texture, RID p_depth_texture, const Size2i &p_base_texture_size, RID p_secondary_texture, RID p_bokeh_texture1, RID p_bokeh_texture2, 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);
  573. struct TonemapSettings {
  574. bool use_glow = false;
  575. enum GlowMode {
  576. GLOW_MODE_ADD,
  577. GLOW_MODE_SCREEN,
  578. GLOW_MODE_SOFTLIGHT,
  579. GLOW_MODE_REPLACE,
  580. GLOW_MODE_MIX
  581. };
  582. GlowMode glow_mode = GLOW_MODE_ADD;
  583. float glow_intensity = 1.0;
  584. float glow_levels[7] = { 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0 };
  585. Vector2i glow_texture_size;
  586. bool glow_use_bicubic_upscale = false;
  587. RID glow_texture;
  588. RS::EnvironmentToneMapper tonemap_mode = RS::ENV_TONE_MAPPER_LINEAR;
  589. float exposure = 1.0;
  590. float white = 1.0;
  591. bool use_auto_exposure = false;
  592. float auto_exposure_grey = 0.5;
  593. RID exposure_texture;
  594. bool use_bcs = false;
  595. float brightness = 1.0;
  596. float contrast = 1.0;
  597. float saturation = 1.0;
  598. bool use_color_correction = false;
  599. bool use_1d_color_correction = false;
  600. RID color_correction_texture;
  601. bool use_fxaa = false;
  602. bool use_debanding = false;
  603. Vector2i texture_size;
  604. };
  605. struct SSAOSettings {
  606. float radius = 1.0;
  607. float intensity = 2.0;
  608. float power = 1.5;
  609. float detail = 0.5;
  610. float horizon = 0.06;
  611. float sharpness = 0.98;
  612. RS::EnvironmentSSAOQuality quality = RS::ENV_SSAO_QUALITY_MEDIUM;
  613. bool half_size = false;
  614. float adaptive_target = 0.5;
  615. int blur_passes = 2;
  616. float fadeout_from = 50.0;
  617. float fadeout_to = 300.0;
  618. Size2i full_screen_size = Size2i();
  619. Size2i half_screen_size = Size2i();
  620. Size2i quarter_screen_size = Size2i();
  621. };
  622. void tonemapper(RID p_source_color, RID p_dst_framebuffer, const TonemapSettings &p_settings);
  623. void gather_ssao(RD::ComputeListID p_compute_list, const Vector<RID> p_ao_slices, const SSAOSettings &p_settings, bool p_adaptive_base_pass);
  624. 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);
  625. void roughness_limit(RID p_source_normal, RID p_roughness, const Size2i &p_size, float p_curve);
  626. void cubemap_downsample(RID p_source_cubemap, RID p_dest_cubemap, const Size2i &p_size);
  627. void cubemap_filter(RID p_source_cubemap, Vector<RID> p_dest_cubemap, bool p_use_array);
  628. void render_sky(RD::DrawListID p_list, float p_time, RID p_fb, RID p_samplers, RID p_fog, PipelineCacheRD *p_pipeline, RID p_uniform_set, RID p_texture_set, const CameraMatrix &p_camera, const Basis &p_orientation, float p_multiplier, const Vector3 &p_position);
  629. 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);
  630. void merge_specular(RID p_dest_framebuffer, RID p_specular, RID p_base, RID p_reflection);
  631. 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);
  632. void resolve_gi(RID p_source_depth, RID p_source_normal_roughness, RID p_source_giprobe, RID p_dest_depth, RID p_dest_normal_roughness, RID p_dest_giprobe, Vector2i p_screen_size, int p_samples, uint32_t p_barrier = RD::BARRIER_MASK_ALL);
  633. void sort_buffer(RID p_uniform_set, int p_size);
  634. EffectsRD();
  635. ~EffectsRD();
  636. };
  637. #endif // !RASTERIZER_EFFECTS_RD_H