rasterizer_effects_rd.cpp 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502
  1. /*************************************************************************/
  2. /* rasterizer_effects_rd.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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. #include "rasterizer_effects_rd.h"
  31. #include "core/os/os.h"
  32. #include "core/project_settings.h"
  33. #include "thirdparty/misc/cubemap_coeffs.h"
  34. static _FORCE_INLINE_ void store_transform_3x3(const Basis &p_basis, float *p_array) {
  35. p_array[0] = p_basis.elements[0][0];
  36. p_array[1] = p_basis.elements[1][0];
  37. p_array[2] = p_basis.elements[2][0];
  38. p_array[3] = 0;
  39. p_array[4] = p_basis.elements[0][1];
  40. p_array[5] = p_basis.elements[1][1];
  41. p_array[6] = p_basis.elements[2][1];
  42. p_array[7] = 0;
  43. p_array[8] = p_basis.elements[0][2];
  44. p_array[9] = p_basis.elements[1][2];
  45. p_array[10] = p_basis.elements[2][2];
  46. p_array[11] = 0;
  47. }
  48. static _FORCE_INLINE_ void store_camera(const CameraMatrix &p_mtx, float *p_array) {
  49. for (int i = 0; i < 4; i++) {
  50. for (int j = 0; j < 4; j++) {
  51. p_array[i * 4 + j] = p_mtx.matrix[i][j];
  52. }
  53. }
  54. }
  55. RID RasterizerEffectsRD::_get_uniform_set_from_image(RID p_image) {
  56. if (image_to_uniform_set_cache.has(p_image)) {
  57. RID uniform_set = image_to_uniform_set_cache[p_image];
  58. if (RD::get_singleton()->uniform_set_is_valid(uniform_set)) {
  59. return uniform_set;
  60. }
  61. }
  62. Vector<RD::Uniform> uniforms;
  63. RD::Uniform u;
  64. u.type = RD::UNIFORM_TYPE_IMAGE;
  65. u.binding = 0;
  66. u.ids.push_back(p_image);
  67. uniforms.push_back(u);
  68. //any thing with the same configuration (one texture in binding 0 for set 0), is good
  69. RID uniform_set = RD::get_singleton()->uniform_set_create(uniforms, luminance_reduce.shader.version_get_shader(luminance_reduce.shader_version, 0), 1);
  70. image_to_uniform_set_cache[p_image] = uniform_set;
  71. return uniform_set;
  72. }
  73. RID RasterizerEffectsRD::_get_uniform_set_from_texture(RID p_texture, bool p_use_mipmaps) {
  74. if (texture_to_uniform_set_cache.has(p_texture)) {
  75. RID uniform_set = texture_to_uniform_set_cache[p_texture];
  76. if (RD::get_singleton()->uniform_set_is_valid(uniform_set)) {
  77. return uniform_set;
  78. }
  79. }
  80. Vector<RD::Uniform> uniforms;
  81. RD::Uniform u;
  82. u.type = RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE;
  83. u.binding = 0;
  84. u.ids.push_back(p_use_mipmaps ? default_mipmap_sampler : default_sampler);
  85. u.ids.push_back(p_texture);
  86. uniforms.push_back(u);
  87. //any thing with the same configuration (one texture in binding 0 for set 0), is good
  88. RID uniform_set = RD::get_singleton()->uniform_set_create(uniforms, blur.shader.version_get_shader(blur.shader_version, 0), 0);
  89. texture_to_uniform_set_cache[p_texture] = uniform_set;
  90. return uniform_set;
  91. }
  92. RID RasterizerEffectsRD::_get_compute_uniform_set_from_texture(RID p_texture, bool p_use_mipmaps) {
  93. if (texture_to_compute_uniform_set_cache.has(p_texture)) {
  94. RID uniform_set = texture_to_compute_uniform_set_cache[p_texture];
  95. if (RD::get_singleton()->uniform_set_is_valid(uniform_set)) {
  96. return uniform_set;
  97. }
  98. }
  99. Vector<RD::Uniform> uniforms;
  100. RD::Uniform u;
  101. u.type = RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE;
  102. u.binding = 0;
  103. u.ids.push_back(p_use_mipmaps ? default_mipmap_sampler : default_sampler);
  104. u.ids.push_back(p_texture);
  105. uniforms.push_back(u);
  106. //any thing with the same configuration (one texture in binding 0 for set 0), is good
  107. RID uniform_set = RD::get_singleton()->uniform_set_create(uniforms, luminance_reduce.shader.version_get_shader(luminance_reduce.shader_version, 0), 0);
  108. texture_to_compute_uniform_set_cache[p_texture] = uniform_set;
  109. return uniform_set;
  110. }
  111. RID RasterizerEffectsRD::_get_compute_uniform_set_from_texture_pair(RID p_texture1, RID p_texture2, bool p_use_mipmaps) {
  112. TexturePair tp;
  113. tp.texture1 = p_texture1;
  114. tp.texture2 = p_texture2;
  115. if (texture_pair_to_compute_uniform_set_cache.has(tp)) {
  116. RID uniform_set = texture_pair_to_compute_uniform_set_cache[tp];
  117. if (RD::get_singleton()->uniform_set_is_valid(uniform_set)) {
  118. return uniform_set;
  119. }
  120. }
  121. Vector<RD::Uniform> uniforms;
  122. {
  123. RD::Uniform u;
  124. u.type = RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE;
  125. u.binding = 0;
  126. u.ids.push_back(p_use_mipmaps ? default_mipmap_sampler : default_sampler);
  127. u.ids.push_back(p_texture1);
  128. uniforms.push_back(u);
  129. }
  130. {
  131. RD::Uniform u;
  132. u.type = RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE;
  133. u.binding = 1;
  134. u.ids.push_back(p_use_mipmaps ? default_mipmap_sampler : default_sampler);
  135. u.ids.push_back(p_texture2);
  136. uniforms.push_back(u);
  137. }
  138. //any thing with the same configuration (one texture in binding 0 for set 0), is good
  139. RID uniform_set = RD::get_singleton()->uniform_set_create(uniforms, ssr_scale.shader.version_get_shader(ssr_scale.shader_version, 0), 1);
  140. texture_pair_to_compute_uniform_set_cache[tp] = uniform_set;
  141. return uniform_set;
  142. }
  143. RID RasterizerEffectsRD::_get_compute_uniform_set_from_image_pair(RID p_texture1, RID p_texture2) {
  144. TexturePair tp;
  145. tp.texture1 = p_texture1;
  146. tp.texture2 = p_texture2;
  147. if (image_pair_to_compute_uniform_set_cache.has(tp)) {
  148. RID uniform_set = image_pair_to_compute_uniform_set_cache[tp];
  149. if (RD::get_singleton()->uniform_set_is_valid(uniform_set)) {
  150. return uniform_set;
  151. }
  152. }
  153. Vector<RD::Uniform> uniforms;
  154. {
  155. RD::Uniform u;
  156. u.type = RD::UNIFORM_TYPE_IMAGE;
  157. u.binding = 0;
  158. u.ids.push_back(p_texture1);
  159. uniforms.push_back(u);
  160. }
  161. {
  162. RD::Uniform u;
  163. u.type = RD::UNIFORM_TYPE_IMAGE;
  164. u.binding = 1;
  165. u.ids.push_back(p_texture2);
  166. uniforms.push_back(u);
  167. }
  168. //any thing with the same configuration (one texture in binding 0 for set 0), is good
  169. RID uniform_set = RD::get_singleton()->uniform_set_create(uniforms, ssr_scale.shader.version_get_shader(ssr_scale.shader_version, 0), 3);
  170. image_pair_to_compute_uniform_set_cache[tp] = uniform_set;
  171. return uniform_set;
  172. }
  173. void RasterizerEffectsRD::copy_to_rect_and_linearize(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2 &p_rect, bool p_flip_y, float p_z_near, float p_z_far) {
  174. zeromem(&blur.push_constant, sizeof(BlurPushConstant));
  175. if (p_flip_y) {
  176. blur.push_constant.flags |= BLUR_FLAG_FLIP_Y;
  177. }
  178. blur.push_constant.camera_z_near = p_z_near;
  179. blur.push_constant.camera_z_far = p_z_far;
  180. RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dest_framebuffer, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD, Vector<Color>(), 1.0, 0, p_rect);
  181. RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, blur.pipelines[BLUR_MODE_LINEARIZE_DEPTH].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dest_framebuffer)));
  182. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, _get_uniform_set_from_texture(p_source_rd_texture), 0);
  183. RD::get_singleton()->draw_list_bind_index_array(draw_list, index_array);
  184. RD::get_singleton()->draw_list_set_push_constant(draw_list, &blur.push_constant, sizeof(BlurPushConstant));
  185. RD::get_singleton()->draw_list_draw(draw_list, true);
  186. RD::get_singleton()->draw_list_end();
  187. }
  188. void RasterizerEffectsRD::copy_to_rect(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2 &p_rect, bool p_flip_y, bool p_force_luminance) {
  189. zeromem(&blur.push_constant, sizeof(BlurPushConstant));
  190. if (p_flip_y) {
  191. blur.push_constant.flags |= BLUR_FLAG_FLIP_Y;
  192. }
  193. if (p_force_luminance) {
  194. blur.push_constant.flags |= BLUR_COPY_FORCE_LUMINANCE;
  195. }
  196. RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dest_framebuffer, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD, Vector<Color>(), 1.0, 0, p_rect);
  197. RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, blur.pipelines[BLUR_MODE_SIMPLY_COPY].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dest_framebuffer)));
  198. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, _get_uniform_set_from_texture(p_source_rd_texture), 0);
  199. RD::get_singleton()->draw_list_bind_index_array(draw_list, index_array);
  200. RD::get_singleton()->draw_list_set_push_constant(draw_list, &blur.push_constant, sizeof(BlurPushConstant));
  201. RD::get_singleton()->draw_list_draw(draw_list, true);
  202. RD::get_singleton()->draw_list_end();
  203. }
  204. void RasterizerEffectsRD::region_copy(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2 &p_region) {
  205. zeromem(&blur.push_constant, sizeof(BlurPushConstant));
  206. if (p_region != Rect2()) {
  207. blur.push_constant.flags = BLUR_FLAG_USE_BLUR_SECTION;
  208. blur.push_constant.section[0] = p_region.position.x;
  209. blur.push_constant.section[1] = p_region.position.y;
  210. blur.push_constant.section[2] = p_region.size.width;
  211. blur.push_constant.section[3] = p_region.size.height;
  212. }
  213. RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dest_framebuffer, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD);
  214. RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, blur.pipelines[BLUR_MODE_SIMPLY_COPY].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dest_framebuffer)));
  215. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, _get_uniform_set_from_texture(p_source_rd_texture), 0);
  216. RD::get_singleton()->draw_list_bind_index_array(draw_list, index_array);
  217. RD::get_singleton()->draw_list_set_push_constant(draw_list, &blur.push_constant, sizeof(BlurPushConstant));
  218. RD::get_singleton()->draw_list_draw(draw_list, true);
  219. RD::get_singleton()->draw_list_end();
  220. }
  221. void RasterizerEffectsRD::gaussian_blur(RID p_source_rd_texture, RID p_framebuffer_half, RID p_rd_texture_half, RID p_dest_framebuffer, const Vector2 &p_pixel_size, const Rect2 &p_region) {
  222. zeromem(&blur.push_constant, sizeof(BlurPushConstant));
  223. uint32_t base_flags = 0;
  224. if (p_region != Rect2()) {
  225. base_flags = BLUR_FLAG_USE_BLUR_SECTION;
  226. blur.push_constant.section[0] = p_region.position.x;
  227. blur.push_constant.section[1] = p_region.position.y;
  228. blur.push_constant.section[2] = p_region.size.width;
  229. blur.push_constant.section[3] = p_region.size.height;
  230. }
  231. blur.push_constant.pixel_size[0] = p_pixel_size.x;
  232. blur.push_constant.pixel_size[1] = p_pixel_size.y;
  233. //HORIZONTAL
  234. RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_framebuffer_half, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD);
  235. RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, blur.pipelines[BLUR_MODE_GAUSSIAN_BLUR].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_framebuffer_half)));
  236. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, _get_uniform_set_from_texture(p_source_rd_texture), 0);
  237. RD::get_singleton()->draw_list_bind_index_array(draw_list, index_array);
  238. blur.push_constant.flags = base_flags | BLUR_FLAG_HORIZONTAL;
  239. RD::get_singleton()->draw_list_set_push_constant(draw_list, &blur.push_constant, sizeof(BlurPushConstant));
  240. RD::get_singleton()->draw_list_draw(draw_list, true);
  241. RD::get_singleton()->draw_list_end();
  242. //VERTICAL
  243. draw_list = RD::get_singleton()->draw_list_begin(p_dest_framebuffer, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD);
  244. RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, blur.pipelines[BLUR_MODE_GAUSSIAN_BLUR].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dest_framebuffer)));
  245. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, _get_uniform_set_from_texture(p_rd_texture_half), 0);
  246. RD::get_singleton()->draw_list_bind_index_array(draw_list, index_array);
  247. blur.push_constant.flags = base_flags;
  248. RD::get_singleton()->draw_list_set_push_constant(draw_list, &blur.push_constant, sizeof(BlurPushConstant));
  249. RD::get_singleton()->draw_list_draw(draw_list, true);
  250. RD::get_singleton()->draw_list_end();
  251. }
  252. void RasterizerEffectsRD::gaussian_glow(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, bool p_first_pass, float p_luminance_cap, float p_exposure, float p_bloom, float p_hdr_bleed_treshold, float p_hdr_bleed_scale, RID p_auto_exposure, float p_auto_exposure_grey) {
  253. zeromem(&blur.push_constant, sizeof(BlurPushConstant));
  254. BlurMode blur_mode = p_first_pass && p_auto_exposure.is_valid() ? BLUR_MODE_GAUSSIAN_GLOW_AUTO_EXPOSURE : BLUR_MODE_GAUSSIAN_GLOW;
  255. uint32_t base_flags = 0;
  256. blur.push_constant.pixel_size[0] = p_pixel_size.x;
  257. blur.push_constant.pixel_size[1] = p_pixel_size.y;
  258. blur.push_constant.glow_strength = p_strength;
  259. blur.push_constant.glow_bloom = p_bloom;
  260. blur.push_constant.glow_hdr_threshold = p_hdr_bleed_treshold;
  261. blur.push_constant.glow_hdr_scale = p_hdr_bleed_scale;
  262. blur.push_constant.glow_exposure = p_exposure;
  263. blur.push_constant.glow_white = 0; //actually unused
  264. blur.push_constant.glow_luminance_cap = p_luminance_cap;
  265. blur.push_constant.glow_auto_exposure_grey = p_auto_exposure_grey; //unused also
  266. //HORIZONTAL
  267. RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_framebuffer_half, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD);
  268. RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, blur.pipelines[blur_mode].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_framebuffer_half)));
  269. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, _get_uniform_set_from_texture(p_source_rd_texture), 0);
  270. if (p_auto_exposure.is_valid() && p_first_pass) {
  271. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, _get_uniform_set_from_texture(p_auto_exposure), 1);
  272. }
  273. RD::get_singleton()->draw_list_bind_index_array(draw_list, index_array);
  274. blur.push_constant.flags = base_flags | BLUR_FLAG_HORIZONTAL | (p_first_pass ? BLUR_FLAG_GLOW_FIRST_PASS : 0);
  275. RD::get_singleton()->draw_list_set_push_constant(draw_list, &blur.push_constant, sizeof(BlurPushConstant));
  276. RD::get_singleton()->draw_list_draw(draw_list, true);
  277. RD::get_singleton()->draw_list_end();
  278. blur_mode = BLUR_MODE_GAUSSIAN_GLOW;
  279. //VERTICAL
  280. draw_list = RD::get_singleton()->draw_list_begin(p_dest_framebuffer, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD);
  281. RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, blur.pipelines[blur_mode].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dest_framebuffer)));
  282. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, _get_uniform_set_from_texture(p_rd_texture_half), 0);
  283. RD::get_singleton()->draw_list_bind_index_array(draw_list, index_array);
  284. blur.push_constant.flags = base_flags;
  285. RD::get_singleton()->draw_list_set_push_constant(draw_list, &blur.push_constant, sizeof(BlurPushConstant));
  286. RD::get_singleton()->draw_list_draw(draw_list, true);
  287. RD::get_singleton()->draw_list_end();
  288. }
  289. void RasterizerEffectsRD::screen_space_reflection(RID p_diffuse, RID p_normal, RenderingServer::EnvironmentSSRRoughnessQuality p_roughness_quality, RID p_roughness, 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) {
  290. RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
  291. int32_t x_groups = (p_screen_size.width - 1) / 8 + 1;
  292. int32_t y_groups = (p_screen_size.height - 1) / 8 + 1;
  293. { //scale color and depth to half
  294. ssr_scale.push_constant.camera_z_far = p_camera.get_z_far();
  295. ssr_scale.push_constant.camera_z_near = p_camera.get_z_near();
  296. ssr_scale.push_constant.orthogonal = p_camera.is_orthogonal();
  297. ssr_scale.push_constant.filter = false; //enabling causes arctifacts
  298. ssr_scale.push_constant.screen_size[0] = p_screen_size.x;
  299. ssr_scale.push_constant.screen_size[1] = p_screen_size.y;
  300. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, ssr_scale.pipeline);
  301. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_diffuse), 0);
  302. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture_pair(p_depth, p_normal), 1);
  303. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_output_blur), 2);
  304. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_image_pair(p_scale_depth, p_scale_normal), 3);
  305. RD::get_singleton()->compute_list_set_push_constant(compute_list, &ssr_scale.push_constant, sizeof(ScreenSpaceReflectionScalePushConstant));
  306. RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, 1);
  307. RD::get_singleton()->compute_list_add_barrier(compute_list);
  308. }
  309. {
  310. ssr.push_constant.camera_z_far = p_camera.get_z_far();
  311. ssr.push_constant.camera_z_near = p_camera.get_z_near();
  312. ssr.push_constant.orthogonal = p_camera.is_orthogonal();
  313. ssr.push_constant.screen_size[0] = p_screen_size.x;
  314. ssr.push_constant.screen_size[1] = p_screen_size.y;
  315. ssr.push_constant.curve_fade_in = p_fade_in;
  316. ssr.push_constant.distance_fade = p_fade_out;
  317. ssr.push_constant.num_steps = p_max_steps;
  318. ssr.push_constant.depth_tolerance = p_tolerance;
  319. ssr.push_constant.use_half_res = true;
  320. ssr.push_constant.proj_info[0] = -2.0f / (p_screen_size.width * p_camera.matrix[0][0]);
  321. ssr.push_constant.proj_info[1] = -2.0f / (p_screen_size.height * p_camera.matrix[1][1]);
  322. ssr.push_constant.proj_info[2] = (1.0f - p_camera.matrix[0][2]) / p_camera.matrix[0][0];
  323. ssr.push_constant.proj_info[3] = (1.0f + p_camera.matrix[1][2]) / p_camera.matrix[1][1];
  324. ssr.push_constant.metallic_mask[0] = CLAMP(p_metallic_mask.r * 255.0, 0, 255);
  325. ssr.push_constant.metallic_mask[1] = CLAMP(p_metallic_mask.g * 255.0, 0, 255);
  326. ssr.push_constant.metallic_mask[2] = CLAMP(p_metallic_mask.b * 255.0, 0, 255);
  327. ssr.push_constant.metallic_mask[3] = CLAMP(p_metallic_mask.a * 255.0, 0, 255);
  328. store_camera(p_camera, ssr.push_constant.projection);
  329. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, ssr.pipelines[(p_roughness_quality != RS::ENV_SSR_ROUGNESS_QUALITY_DISABLED) ? SCREEN_SPACE_REFLECTION_ROUGH : SCREEN_SPACE_REFLECTION_NORMAL]);
  330. RD::get_singleton()->compute_list_set_push_constant(compute_list, &ssr.push_constant, sizeof(ScreenSpaceReflectionPushConstant));
  331. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_image_pair(p_output_blur, p_scale_depth), 0);
  332. if (p_roughness_quality != RS::ENV_SSR_ROUGNESS_QUALITY_DISABLED) {
  333. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_image_pair(p_output, p_blur_radius), 1);
  334. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture_pair(p_metallic, p_roughness), 3);
  335. } else {
  336. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_output), 1);
  337. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_metallic), 3);
  338. }
  339. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_scale_normal), 2);
  340. RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, 1);
  341. }
  342. if (p_roughness_quality != RS::ENV_SSR_ROUGNESS_QUALITY_DISABLED) {
  343. //blurr
  344. RD::get_singleton()->compute_list_add_barrier(compute_list);
  345. ssr_filter.push_constant.orthogonal = p_camera.is_orthogonal();
  346. ssr_filter.push_constant.edge_tolerance = Math::sin(Math::deg2rad(15.0));
  347. ssr_filter.push_constant.proj_info[0] = -2.0f / (p_screen_size.width * p_camera.matrix[0][0]);
  348. ssr_filter.push_constant.proj_info[1] = -2.0f / (p_screen_size.height * p_camera.matrix[1][1]);
  349. ssr_filter.push_constant.proj_info[2] = (1.0f - p_camera.matrix[0][2]) / p_camera.matrix[0][0];
  350. ssr_filter.push_constant.proj_info[3] = (1.0f + p_camera.matrix[1][2]) / p_camera.matrix[1][1];
  351. ssr_filter.push_constant.vertical = 0;
  352. if (p_roughness_quality == RS::ENV_SSR_ROUGNESS_QUALITY_LOW) {
  353. ssr_filter.push_constant.steps = p_max_steps / 3;
  354. ssr_filter.push_constant.increment = 3;
  355. } else if (p_roughness_quality == RS::ENV_SSR_ROUGNESS_QUALITY_MEDIUM) {
  356. ssr_filter.push_constant.steps = p_max_steps / 2;
  357. ssr_filter.push_constant.increment = 2;
  358. } else {
  359. ssr_filter.push_constant.steps = p_max_steps;
  360. ssr_filter.push_constant.increment = 1;
  361. }
  362. ssr_filter.push_constant.screen_size[0] = p_screen_size.width;
  363. ssr_filter.push_constant.screen_size[1] = p_screen_size.height;
  364. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, ssr_filter.pipelines[SCREEN_SPACE_REFLECTION_FILTER_HORIZONTAL]);
  365. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_image_pair(p_output, p_blur_radius), 0);
  366. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_scale_normal), 1);
  367. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_image_pair(p_output_blur, p_blur_radius2), 2);
  368. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_scale_depth), 3);
  369. RD::get_singleton()->compute_list_set_push_constant(compute_list, &ssr_filter.push_constant, sizeof(ScreenSpaceReflectionFilterPushConstant));
  370. RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, 1);
  371. RD::get_singleton()->compute_list_add_barrier(compute_list);
  372. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, ssr_filter.pipelines[SCREEN_SPACE_REFLECTION_FILTER_VERTICAL]);
  373. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_image_pair(p_output_blur, p_blur_radius2), 0);
  374. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_scale_normal), 1);
  375. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_output), 2);
  376. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_scale_depth), 3);
  377. ssr_filter.push_constant.vertical = 1;
  378. RD::get_singleton()->compute_list_set_push_constant(compute_list, &ssr_filter.push_constant, sizeof(ScreenSpaceReflectionFilterPushConstant));
  379. RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, 1);
  380. }
  381. RD::get_singleton()->compute_list_end();
  382. }
  383. void RasterizerEffectsRD::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, RenderingServer::SubSurfaceScatteringQuality p_quality) {
  384. RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
  385. int32_t x_groups = (p_screen_size.width - 1) / 8 + 1;
  386. int32_t y_groups = (p_screen_size.height - 1) / 8 + 1;
  387. Plane p = p_camera.xform4(Plane(1, 0, -1, 1));
  388. p.normal /= p.d;
  389. float unit_size = p.normal.x;
  390. { //scale color and depth to half
  391. sss.push_constant.camera_z_far = p_camera.get_z_far();
  392. sss.push_constant.camera_z_near = p_camera.get_z_near();
  393. sss.push_constant.orthogonal = p_camera.is_orthogonal();
  394. sss.push_constant.unit_size = unit_size;
  395. sss.push_constant.screen_size[0] = p_screen_size.x;
  396. sss.push_constant.screen_size[1] = p_screen_size.y;
  397. sss.push_constant.vertical = false;
  398. sss.push_constant.scale = p_scale;
  399. sss.push_constant.depth_scale = p_depth_scale;
  400. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, sss.pipelines[p_quality - 1]);
  401. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_diffuse), 0);
  402. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_diffuse2), 1);
  403. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_depth), 2);
  404. RD::get_singleton()->compute_list_set_push_constant(compute_list, &sss.push_constant, sizeof(SubSurfaceScatteringPushConstant));
  405. RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, 1);
  406. RD::get_singleton()->compute_list_add_barrier(compute_list);
  407. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_diffuse2), 0);
  408. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_diffuse), 1);
  409. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_depth), 2);
  410. sss.push_constant.vertical = true;
  411. RD::get_singleton()->compute_list_set_push_constant(compute_list, &sss.push_constant, sizeof(SubSurfaceScatteringPushConstant));
  412. RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, 1);
  413. RD::get_singleton()->compute_list_end();
  414. }
  415. }
  416. void RasterizerEffectsRD::merge_specular(RID p_dest_framebuffer, RID p_specular, RID p_base, RID p_reflection) {
  417. RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dest_framebuffer, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD, Vector<Color>());
  418. if (p_reflection.is_valid()) {
  419. if (p_base.is_valid()) {
  420. RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, specular_merge.pipelines[SPECULAR_MERGE_SSR].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dest_framebuffer)));
  421. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, _get_uniform_set_from_texture(p_base), 2);
  422. } else {
  423. RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, specular_merge.pipelines[SPECULAR_MERGE_ADDITIVE_SSR].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dest_framebuffer)));
  424. }
  425. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, _get_uniform_set_from_texture(p_specular), 0);
  426. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, _get_uniform_set_from_texture(p_reflection), 1);
  427. } else {
  428. if (p_base.is_valid()) {
  429. RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, specular_merge.pipelines[SPECULAR_MERGE_ADD].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dest_framebuffer)));
  430. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, _get_uniform_set_from_texture(p_base), 2);
  431. } else {
  432. RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, specular_merge.pipelines[SPECULAR_MERGE_ADDITIVE_ADD].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dest_framebuffer)));
  433. }
  434. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, _get_uniform_set_from_texture(p_specular), 0);
  435. }
  436. RD::get_singleton()->draw_list_bind_index_array(draw_list, index_array);
  437. RD::get_singleton()->draw_list_draw(draw_list, true);
  438. RD::get_singleton()->draw_list_end();
  439. }
  440. void RasterizerEffectsRD::make_mipmap(RID p_source_rd_texture, RID p_dest_framebuffer, const Vector2 &p_pixel_size) {
  441. zeromem(&blur.push_constant, sizeof(BlurPushConstant));
  442. blur.push_constant.pixel_size[0] = p_pixel_size.x;
  443. blur.push_constant.pixel_size[1] = p_pixel_size.y;
  444. RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dest_framebuffer, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD);
  445. RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, blur.pipelines[BLUR_MODE_MIPMAP].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dest_framebuffer)));
  446. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, _get_uniform_set_from_texture(p_source_rd_texture), 0);
  447. RD::get_singleton()->draw_list_bind_index_array(draw_list, index_array);
  448. RD::get_singleton()->draw_list_set_push_constant(draw_list, &blur.push_constant, sizeof(BlurPushConstant));
  449. RD::get_singleton()->draw_list_draw(draw_list, true);
  450. RD::get_singleton()->draw_list_end();
  451. }
  452. void RasterizerEffectsRD::copy_cubemap_to_dp(RID p_source_rd_texture, RID p_dest_framebuffer, const Rect2 &p_rect, float p_z_near, float p_z_far, float p_bias, bool p_dp_flip) {
  453. CopyToDPPushConstant push_constant;
  454. push_constant.bias = p_bias;
  455. push_constant.z_far = p_z_far;
  456. push_constant.z_near = p_z_near;
  457. push_constant.z_flip = p_dp_flip;
  458. RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dest_framebuffer, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD, Vector<Color>(), 1.0, 0, p_rect);
  459. RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, copy.pipelines[COPY_MODE_CUBE_TO_DP].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dest_framebuffer)));
  460. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, _get_uniform_set_from_texture(p_source_rd_texture), 0);
  461. RD::get_singleton()->draw_list_bind_index_array(draw_list, index_array);
  462. RD::get_singleton()->draw_list_set_push_constant(draw_list, &push_constant, sizeof(CopyToDPPushConstant));
  463. RD::get_singleton()->draw_list_draw(draw_list, true);
  464. RD::get_singleton()->draw_list_end();
  465. }
  466. void RasterizerEffectsRD::tonemapper(RID p_source_color, RID p_dst_framebuffer, const TonemapSettings &p_settings) {
  467. zeromem(&tonemap.push_constant, sizeof(TonemapPushConstant));
  468. tonemap.push_constant.use_bcs = p_settings.use_bcs;
  469. tonemap.push_constant.bcs[0] = p_settings.brightness;
  470. tonemap.push_constant.bcs[1] = p_settings.contrast;
  471. tonemap.push_constant.bcs[2] = p_settings.saturation;
  472. tonemap.push_constant.use_glow = p_settings.use_glow;
  473. tonemap.push_constant.glow_intensity = p_settings.glow_intensity;
  474. tonemap.push_constant.glow_level_flags = p_settings.glow_level_flags;
  475. tonemap.push_constant.glow_texture_size[0] = p_settings.glow_texture_size.x;
  476. tonemap.push_constant.glow_texture_size[1] = p_settings.glow_texture_size.y;
  477. tonemap.push_constant.glow_mode = p_settings.glow_mode;
  478. TonemapMode mode = p_settings.glow_use_bicubic_upscale ? TONEMAP_MODE_BICUBIC_GLOW_FILTER : TONEMAP_MODE_NORMAL;
  479. tonemap.push_constant.tonemapper = p_settings.tonemap_mode;
  480. tonemap.push_constant.use_auto_exposure = p_settings.use_auto_exposure;
  481. tonemap.push_constant.exposure = p_settings.exposure;
  482. tonemap.push_constant.white = p_settings.white;
  483. tonemap.push_constant.auto_exposure_grey = p_settings.auto_exposure_grey;
  484. tonemap.push_constant.use_color_correction = p_settings.use_color_correction;
  485. RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(p_dst_framebuffer, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_KEEP, RD::FINAL_ACTION_DISCARD);
  486. RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, tonemap.pipelines[mode].get_render_pipeline(RD::INVALID_ID, RD::get_singleton()->framebuffer_get_format(p_dst_framebuffer)));
  487. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, _get_uniform_set_from_texture(p_source_color), 0);
  488. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, _get_uniform_set_from_texture(p_settings.exposure_texture), 1);
  489. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, _get_uniform_set_from_texture(p_settings.glow_texture, true), 2);
  490. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, _get_uniform_set_from_texture(p_settings.color_correction_texture), 3);
  491. RD::get_singleton()->draw_list_bind_index_array(draw_list, index_array);
  492. RD::get_singleton()->draw_list_set_push_constant(draw_list, &tonemap.push_constant, sizeof(TonemapPushConstant));
  493. RD::get_singleton()->draw_list_draw(draw_list, true);
  494. RD::get_singleton()->draw_list_end();
  495. }
  496. void RasterizerEffectsRD::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) {
  497. luminance_reduce.push_constant.source_size[0] = p_source_size.x;
  498. luminance_reduce.push_constant.source_size[1] = p_source_size.y;
  499. luminance_reduce.push_constant.max_luminance = p_max_luminance;
  500. luminance_reduce.push_constant.min_luminance = p_min_luminance;
  501. luminance_reduce.push_constant.exposure_adjust = p_adjust;
  502. RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
  503. for (int i = 0; i < p_reduce.size(); i++) {
  504. if (i == 0) {
  505. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, luminance_reduce.pipelines[LUMINANCE_REDUCE_READ]);
  506. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_source_texture), 0);
  507. } else {
  508. RD::get_singleton()->compute_list_add_barrier(compute_list); //needs barrier, wait until previous is done
  509. if (i == p_reduce.size() - 1 && !p_set) {
  510. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, luminance_reduce.pipelines[LUMINANCE_REDUCE_WRITE]);
  511. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_prev_luminance), 2);
  512. } else {
  513. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, luminance_reduce.pipelines[LUMINANCE_REDUCE]);
  514. }
  515. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_reduce[i - 1]), 0);
  516. }
  517. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_reduce[i]), 1);
  518. RD::get_singleton()->compute_list_set_push_constant(compute_list, &luminance_reduce.push_constant, sizeof(LuminanceReducePushConstant));
  519. int32_t x_groups = (luminance_reduce.push_constant.source_size[0] - 1) / 8 + 1;
  520. int32_t y_groups = (luminance_reduce.push_constant.source_size[1] - 1) / 8 + 1;
  521. RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, 1);
  522. luminance_reduce.push_constant.source_size[0] = MAX(luminance_reduce.push_constant.source_size[0] / 8, 1);
  523. luminance_reduce.push_constant.source_size[1] = MAX(luminance_reduce.push_constant.source_size[1] / 8, 1);
  524. }
  525. RD::get_singleton()->compute_list_end();
  526. }
  527. void RasterizerEffectsRD::bokeh_dof(RID p_base_texture, RID p_depth_texture, const Size2i &p_base_texture_size, RID p_secondary_texture, RID p_halfsize_texture1, RID p_halfsize_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, RenderingServer::DOFBokehShape p_bokeh_shape, RS::DOFBlurQuality p_quality, bool p_use_jitter, float p_cam_znear, float p_cam_zfar, bool p_cam_orthogonal) {
  528. bokeh.push_constant.blur_far_active = p_dof_far;
  529. bokeh.push_constant.blur_far_begin = p_dof_far_begin;
  530. bokeh.push_constant.blur_far_end = p_dof_far_begin + p_dof_far_size;
  531. bokeh.push_constant.blur_near_active = p_dof_near;
  532. bokeh.push_constant.blur_near_begin = p_dof_near_begin;
  533. bokeh.push_constant.blur_near_end = MAX(0, p_dof_near_begin - p_dof_near_size);
  534. bokeh.push_constant.use_jitter = p_use_jitter;
  535. bokeh.push_constant.jitter_seed = Math::randf() * 1000.0;
  536. bokeh.push_constant.z_near = p_cam_znear;
  537. bokeh.push_constant.z_far = p_cam_zfar;
  538. bokeh.push_constant.orthogonal = p_cam_orthogonal;
  539. bokeh.push_constant.blur_size = p_bokeh_size;
  540. bokeh.push_constant.second_pass = false;
  541. bokeh.push_constant.half_size = false;
  542. bokeh.push_constant.blur_scale = 0.5;
  543. RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
  544. /* FIRST PASS */
  545. // The alpha channel of the source color texture is filled with the expected circle size
  546. // If used for DOF far, the size is positive, if used for near, its negative.
  547. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, bokeh.pipelines[BOKEH_GEN_BLUR_SIZE]);
  548. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_base_texture), 0);
  549. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_depth_texture), 1);
  550. int32_t x_groups = (p_base_texture_size.x - 1) / 8 + 1;
  551. int32_t y_groups = (p_base_texture_size.y - 1) / 8 + 1;
  552. bokeh.push_constant.size[0] = p_base_texture_size.x;
  553. bokeh.push_constant.size[1] = p_base_texture_size.y;
  554. RD::get_singleton()->compute_list_set_push_constant(compute_list, &bokeh.push_constant, sizeof(BokehPushConstant));
  555. RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, 1);
  556. RD::get_singleton()->compute_list_add_barrier(compute_list);
  557. if (p_bokeh_shape == RS::DOF_BOKEH_BOX || p_bokeh_shape == RS::DOF_BOKEH_HEXAGON) {
  558. //second pass
  559. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, bokeh.pipelines[p_bokeh_shape == RS::DOF_BOKEH_BOX ? BOKEH_GEN_BOKEH_BOX : BOKEH_GEN_BOKEH_HEXAGONAL]);
  560. static const int quality_samples[4] = { 6, 12, 12, 24 };
  561. bokeh.push_constant.steps = quality_samples[p_quality];
  562. if (p_quality == RS::DOF_BLUR_QUALITY_VERY_LOW || p_quality == RS::DOF_BLUR_QUALITY_LOW) {
  563. //box and hexagon are more or less the same, and they can work in either half (very low and low quality) or full (medium and high quality_ sizes)
  564. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_halfsize_texture1), 0);
  565. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_base_texture), 1);
  566. x_groups = ((p_base_texture_size.x >> 1) - 1) / 8 + 1;
  567. y_groups = ((p_base_texture_size.y >> 1) - 1) / 8 + 1;
  568. bokeh.push_constant.size[0] = p_base_texture_size.x >> 1;
  569. bokeh.push_constant.size[1] = p_base_texture_size.y >> 1;
  570. bokeh.push_constant.half_size = true;
  571. bokeh.push_constant.blur_size *= 0.5;
  572. } else {
  573. //medium and high quality use full size
  574. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_secondary_texture), 0);
  575. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_base_texture), 1);
  576. }
  577. RD::get_singleton()->compute_list_set_push_constant(compute_list, &bokeh.push_constant, sizeof(BokehPushConstant));
  578. RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, 1);
  579. RD::get_singleton()->compute_list_add_barrier(compute_list);
  580. //third pass
  581. bokeh.push_constant.second_pass = true;
  582. if (p_quality == RS::DOF_BLUR_QUALITY_VERY_LOW || p_quality == RS::DOF_BLUR_QUALITY_LOW) {
  583. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_halfsize_texture2), 0);
  584. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_halfsize_texture1), 1);
  585. } else {
  586. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_base_texture), 0);
  587. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_secondary_texture), 1);
  588. }
  589. RD::get_singleton()->compute_list_set_push_constant(compute_list, &bokeh.push_constant, sizeof(BokehPushConstant));
  590. RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, 1);
  591. RD::get_singleton()->compute_list_add_barrier(compute_list);
  592. if (p_quality == RS::DOF_BLUR_QUALITY_VERY_LOW || p_quality == RS::DOF_BLUR_QUALITY_LOW) {
  593. //forth pass, upscale for low quality
  594. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, bokeh.pipelines[BOKEH_COMPOSITE]);
  595. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_base_texture), 0);
  596. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_halfsize_texture2), 1);
  597. x_groups = (p_base_texture_size.x - 1) / 8 + 1;
  598. y_groups = (p_base_texture_size.y - 1) / 8 + 1;
  599. bokeh.push_constant.size[0] = p_base_texture_size.x;
  600. bokeh.push_constant.size[1] = p_base_texture_size.y;
  601. bokeh.push_constant.half_size = false;
  602. bokeh.push_constant.second_pass = false;
  603. RD::get_singleton()->compute_list_set_push_constant(compute_list, &bokeh.push_constant, sizeof(BokehPushConstant));
  604. RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, 1);
  605. }
  606. } else {
  607. //circle
  608. //second pass
  609. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, bokeh.pipelines[BOKEH_GEN_BOKEH_CIRCULAR]);
  610. static const float quality_scale[4] = { 8.0, 4.0, 1.0, 0.5 };
  611. bokeh.push_constant.steps = 0;
  612. bokeh.push_constant.blur_scale = quality_scale[p_quality];
  613. //circle always runs in half size, otherwise too expensive
  614. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_halfsize_texture1), 0);
  615. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_base_texture), 1);
  616. x_groups = ((p_base_texture_size.x >> 1) - 1) / 8 + 1;
  617. y_groups = ((p_base_texture_size.y >> 1) - 1) / 8 + 1;
  618. bokeh.push_constant.size[0] = p_base_texture_size.x >> 1;
  619. bokeh.push_constant.size[1] = p_base_texture_size.y >> 1;
  620. bokeh.push_constant.half_size = true;
  621. RD::get_singleton()->compute_list_set_push_constant(compute_list, &bokeh.push_constant, sizeof(BokehPushConstant));
  622. RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, 1);
  623. RD::get_singleton()->compute_list_add_barrier(compute_list);
  624. //circle is just one pass, then upscale
  625. // upscale
  626. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, bokeh.pipelines[BOKEH_COMPOSITE]);
  627. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_base_texture), 0);
  628. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_halfsize_texture1), 1);
  629. x_groups = (p_base_texture_size.x - 1) / 8 + 1;
  630. y_groups = (p_base_texture_size.y - 1) / 8 + 1;
  631. bokeh.push_constant.size[0] = p_base_texture_size.x;
  632. bokeh.push_constant.size[1] = p_base_texture_size.y;
  633. bokeh.push_constant.half_size = false;
  634. bokeh.push_constant.second_pass = false;
  635. RD::get_singleton()->compute_list_set_push_constant(compute_list, &bokeh.push_constant, sizeof(BokehPushConstant));
  636. RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, 1);
  637. }
  638. RD::get_singleton()->compute_list_end();
  639. }
  640. void RasterizerEffectsRD::generate_ssao(RID p_depth_buffer, RID p_normal_buffer, const Size2i &p_depth_buffer_size, RID p_depth_mipmaps_texture, const Vector<RID> &depth_mipmaps, RID p_ao1, bool p_half_size, RID p_ao2, RID p_upscale_buffer, float p_intensity, float p_radius, float p_bias, const CameraMatrix &p_projection, RS::EnvironmentSSAOQuality p_quality, RS::EnvironmentSSAOBlur p_blur, float p_edge_sharpness) {
  641. //minify first
  642. ssao.minify_push_constant.orthogonal = p_projection.is_orthogonal();
  643. ssao.minify_push_constant.z_near = p_projection.get_z_near();
  644. ssao.minify_push_constant.z_far = p_projection.get_z_far();
  645. ssao.minify_push_constant.pixel_size[0] = 1.0 / p_depth_buffer_size.x;
  646. ssao.minify_push_constant.pixel_size[1] = 1.0 / p_depth_buffer_size.y;
  647. ssao.minify_push_constant.source_size[0] = p_depth_buffer_size.x;
  648. ssao.minify_push_constant.source_size[1] = p_depth_buffer_size.y;
  649. RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
  650. /* FIRST PASS */
  651. // Minify the depth buffer.
  652. for (int i = 0; i < depth_mipmaps.size(); i++) {
  653. if (i == 0) {
  654. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, ssao.pipelines[SSAO_MINIFY_FIRST]);
  655. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_depth_buffer), 0);
  656. } else {
  657. if (i == 1) {
  658. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, ssao.pipelines[SSAO_MINIFY_MIPMAP]);
  659. }
  660. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(depth_mipmaps[i - 1]), 0);
  661. }
  662. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(depth_mipmaps[i]), 1);
  663. RD::get_singleton()->compute_list_set_push_constant(compute_list, &ssao.minify_push_constant, sizeof(SSAOMinifyPushConstant));
  664. // shrink after set
  665. ssao.minify_push_constant.source_size[0] = MAX(1, ssao.minify_push_constant.source_size[0] >> 1);
  666. ssao.minify_push_constant.source_size[1] = MAX(1, ssao.minify_push_constant.source_size[1] >> 1);
  667. int x_groups = (ssao.minify_push_constant.source_size[0] - 1) / 8 + 1;
  668. int y_groups = (ssao.minify_push_constant.source_size[1] - 1) / 8 + 1;
  669. RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, 1);
  670. RD::get_singleton()->compute_list_add_barrier(compute_list);
  671. }
  672. /* SECOND PASS */
  673. // Gather samples
  674. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, ssao.pipelines[(SSAO_GATHER_LOW + p_quality) + (p_half_size ? 4 : 0)]);
  675. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_depth_mipmaps_texture), 0);
  676. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_ao1), 1);
  677. if (!p_half_size) {
  678. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_depth_buffer), 2);
  679. }
  680. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_normal_buffer), 3);
  681. ssao.gather_push_constant.screen_size[0] = p_depth_buffer_size.x;
  682. ssao.gather_push_constant.screen_size[1] = p_depth_buffer_size.y;
  683. if (p_half_size) {
  684. ssao.gather_push_constant.screen_size[0] >>= 1;
  685. ssao.gather_push_constant.screen_size[1] >>= 1;
  686. }
  687. ssao.gather_push_constant.z_far = p_projection.get_z_far();
  688. ssao.gather_push_constant.z_near = p_projection.get_z_near();
  689. ssao.gather_push_constant.orthogonal = p_projection.is_orthogonal();
  690. ssao.gather_push_constant.proj_info[0] = -2.0f / (ssao.gather_push_constant.screen_size[0] * p_projection.matrix[0][0]);
  691. ssao.gather_push_constant.proj_info[1] = -2.0f / (ssao.gather_push_constant.screen_size[1] * p_projection.matrix[1][1]);
  692. ssao.gather_push_constant.proj_info[2] = (1.0f - p_projection.matrix[0][2]) / p_projection.matrix[0][0];
  693. ssao.gather_push_constant.proj_info[3] = (1.0f + p_projection.matrix[1][2]) / p_projection.matrix[1][1];
  694. //ssao.gather_push_constant.proj_info[2] = (1.0f - p_projection.matrix[0][2]) / p_projection.matrix[0][0];
  695. //ssao.gather_push_constant.proj_info[3] = -(1.0f + p_projection.matrix[1][2]) / p_projection.matrix[1][1];
  696. ssao.gather_push_constant.radius = p_radius;
  697. ssao.gather_push_constant.proj_scale = float(p_projection.get_pixels_per_meter(ssao.gather_push_constant.screen_size[0]));
  698. ssao.gather_push_constant.bias = p_bias;
  699. ssao.gather_push_constant.intensity_div_r6 = p_intensity / pow(p_radius, 6.0f);
  700. ssao.gather_push_constant.pixel_size[0] = 1.0 / p_depth_buffer_size.x;
  701. ssao.gather_push_constant.pixel_size[1] = 1.0 / p_depth_buffer_size.y;
  702. RD::get_singleton()->compute_list_set_push_constant(compute_list, &ssao.gather_push_constant, sizeof(SSAOGatherPushConstant));
  703. int x_groups = (ssao.gather_push_constant.screen_size[0] - 1) / 8 + 1;
  704. int y_groups = (ssao.gather_push_constant.screen_size[1] - 1) / 8 + 1;
  705. RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, 1);
  706. RD::get_singleton()->compute_list_add_barrier(compute_list);
  707. /* THIRD PASS */
  708. // Blur horizontal
  709. ssao.blur_push_constant.edge_sharpness = p_edge_sharpness;
  710. ssao.blur_push_constant.filter_scale = p_blur;
  711. ssao.blur_push_constant.screen_size[0] = ssao.gather_push_constant.screen_size[0];
  712. ssao.blur_push_constant.screen_size[1] = ssao.gather_push_constant.screen_size[1];
  713. ssao.blur_push_constant.z_far = p_projection.get_z_far();
  714. ssao.blur_push_constant.z_near = p_projection.get_z_near();
  715. ssao.blur_push_constant.orthogonal = p_projection.is_orthogonal();
  716. ssao.blur_push_constant.axis[0] = 1;
  717. ssao.blur_push_constant.axis[1] = 0;
  718. if (p_blur != RS::ENV_SSAO_BLUR_DISABLED) {
  719. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, ssao.pipelines[p_half_size ? SSAO_BLUR_PASS_HALF : SSAO_BLUR_PASS]);
  720. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_ao1), 0);
  721. if (p_half_size) {
  722. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_depth_mipmaps_texture), 1);
  723. } else {
  724. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_depth_buffer), 1);
  725. }
  726. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_ao2), 3);
  727. RD::get_singleton()->compute_list_set_push_constant(compute_list, &ssao.blur_push_constant, sizeof(SSAOBlurPushConstant));
  728. RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, 1);
  729. RD::get_singleton()->compute_list_add_barrier(compute_list);
  730. /* THIRD PASS */
  731. // Blur vertical
  732. ssao.blur_push_constant.axis[0] = 0;
  733. ssao.blur_push_constant.axis[1] = 1;
  734. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_ao2), 0);
  735. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_ao1), 3);
  736. RD::get_singleton()->compute_list_set_push_constant(compute_list, &ssao.blur_push_constant, sizeof(SSAOBlurPushConstant));
  737. RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, 1);
  738. }
  739. if (p_half_size) { //must upscale
  740. /* FOURTH PASS */
  741. // upscale if half size
  742. //back to full size
  743. ssao.blur_push_constant.screen_size[0] = p_depth_buffer_size.x;
  744. ssao.blur_push_constant.screen_size[1] = p_depth_buffer_size.y;
  745. RD::get_singleton()->compute_list_add_barrier(compute_list);
  746. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, ssao.pipelines[SSAO_BLUR_UPSCALE]);
  747. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_ao1), 0);
  748. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_upscale_buffer), 3);
  749. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_depth_buffer), 1);
  750. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_depth_mipmaps_texture), 2);
  751. RD::get_singleton()->compute_list_set_push_constant(compute_list, &ssao.blur_push_constant, sizeof(SSAOBlurPushConstant)); //not used but set anyway
  752. x_groups = (p_depth_buffer_size.x - 1) / 8 + 1;
  753. y_groups = (p_depth_buffer_size.y - 1) / 8 + 1;
  754. RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, 1);
  755. }
  756. RD::get_singleton()->compute_list_end();
  757. }
  758. void RasterizerEffectsRD::roughness_limit(RID p_source_normal, RID p_roughness, const Size2i &p_size, float p_curve) {
  759. roughness_limiter.push_constant.screen_size[0] = p_size.x;
  760. roughness_limiter.push_constant.screen_size[1] = p_size.y;
  761. roughness_limiter.push_constant.curve = p_curve;
  762. RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
  763. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, roughness_limiter.pipeline);
  764. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_source_normal), 0);
  765. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_roughness), 1);
  766. int x_groups = (p_size.x - 1) / 8 + 1;
  767. int y_groups = (p_size.y - 1) / 8 + 1;
  768. RD::get_singleton()->compute_list_set_push_constant(compute_list, &roughness_limiter.push_constant, sizeof(RoughnessLimiterPushConstant)); //not used but set anyway
  769. RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, 1);
  770. RD::get_singleton()->compute_list_end();
  771. }
  772. void RasterizerEffectsRD::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) {
  773. zeromem(&roughness.push_constant, sizeof(CubemapRoughnessPushConstant));
  774. roughness.push_constant.face_id = p_face_id > 9 ? 0 : p_face_id;
  775. roughness.push_constant.roughness = p_roughness;
  776. roughness.push_constant.sample_count = p_sample_count;
  777. roughness.push_constant.use_direct_write = p_roughness == 0.0;
  778. roughness.push_constant.face_size = p_size;
  779. RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
  780. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, roughness.pipeline);
  781. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_source_rd_texture), 0);
  782. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_dest_framebuffer), 1);
  783. RD::get_singleton()->compute_list_set_push_constant(compute_list, &roughness.push_constant, sizeof(CubemapRoughnessPushConstant));
  784. int x_groups = (p_size - 1) / 8 + 1;
  785. int y_groups = (p_size - 1) / 8 + 1;
  786. RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, p_face_id > 9 ? 6 : 1);
  787. RD::get_singleton()->compute_list_end();
  788. }
  789. void RasterizerEffectsRD::cubemap_downsample(RID p_source_cubemap, RID p_dest_cubemap, const Size2i &p_size) {
  790. cubemap_downsampler.push_constant.face_size = p_size.x;
  791. RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
  792. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, cubemap_downsampler.pipeline);
  793. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_source_cubemap), 0);
  794. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_dest_cubemap), 1);
  795. int x_groups = (p_size.x - 1) / 8 + 1;
  796. int y_groups = (p_size.y - 1) / 8 + 1;
  797. RD::get_singleton()->compute_list_set_push_constant(compute_list, &cubemap_downsampler.push_constant, sizeof(CubemapDownsamplerPushConstant));
  798. RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, y_groups, 6); // one z_group for each face
  799. RD::get_singleton()->compute_list_end();
  800. }
  801. void RasterizerEffectsRD::cubemap_filter(RID p_source_cubemap, Vector<RID> p_dest_cubemap, bool p_use_array) {
  802. Vector<RD::Uniform> uniforms;
  803. for (int i = 0; i < p_dest_cubemap.size(); i++) {
  804. RD::Uniform u;
  805. u.type = RD::UNIFORM_TYPE_IMAGE;
  806. u.binding = i;
  807. u.ids.push_back(p_dest_cubemap[i]);
  808. uniforms.push_back(u);
  809. }
  810. if (RD::get_singleton()->uniform_set_is_valid(filter.image_uniform_set)) {
  811. RD::get_singleton()->free(filter.image_uniform_set);
  812. }
  813. filter.image_uniform_set = RD::get_singleton()->uniform_set_create(uniforms, filter.shader.version_get_shader(filter.shader_version, 0), 2);
  814. int pipeline = p_use_array ? FILTER_MODE_HIGH_QUALITY_ARRAY : FILTER_MODE_HIGH_QUALITY;
  815. pipeline = filter.use_high_quality ? pipeline : pipeline + 1;
  816. RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
  817. RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, filter.pipelines[pipeline]);
  818. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_source_cubemap, true), 0);
  819. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, filter.uniform_set, 1);
  820. RD::get_singleton()->compute_list_bind_uniform_set(compute_list, filter.image_uniform_set, 2);
  821. int x_groups = p_use_array ? 1792 : 342; // (128 * 128 * 7) / 64 : (128*128 + 64*64 + 32*32 + 16*16 + 8*8 + 4*4 + 2*2) / 64
  822. RD::get_singleton()->compute_list_dispatch(compute_list, x_groups, 6, 1); // one y_group for each face
  823. RD::get_singleton()->compute_list_end();
  824. }
  825. void RasterizerEffectsRD::render_sky(RD::DrawListID p_list, float p_time, RID p_fb, RID p_samplers, RID p_lights, RenderPipelineVertexFormatCacheRD *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) {
  826. SkyPushConstant sky_push_constant;
  827. zeromem(&sky_push_constant, sizeof(SkyPushConstant));
  828. sky_push_constant.proj[0] = p_camera.matrix[2][0];
  829. sky_push_constant.proj[1] = p_camera.matrix[0][0];
  830. sky_push_constant.proj[2] = p_camera.matrix[2][1];
  831. sky_push_constant.proj[3] = p_camera.matrix[1][1];
  832. sky_push_constant.position[0] = p_position.x;
  833. sky_push_constant.position[1] = p_position.y;
  834. sky_push_constant.position[2] = p_position.z;
  835. sky_push_constant.multiplier = p_multiplier;
  836. sky_push_constant.time = p_time;
  837. store_transform_3x3(p_orientation, sky_push_constant.orientation);
  838. RenderingDevice::FramebufferFormatID fb_format = RD::get_singleton()->framebuffer_get_format(p_fb);
  839. RD::DrawListID draw_list = p_list;
  840. RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, p_pipeline->get_render_pipeline(RD::INVALID_ID, fb_format));
  841. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, p_samplers, 0);
  842. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, p_uniform_set, 1);
  843. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, p_texture_set, 2);
  844. RD::get_singleton()->draw_list_bind_uniform_set(draw_list, p_lights, 3);
  845. RD::get_singleton()->draw_list_bind_index_array(draw_list, index_array);
  846. RD::get_singleton()->draw_list_set_push_constant(draw_list, &sky_push_constant, sizeof(SkyPushConstant));
  847. RD::get_singleton()->draw_list_draw(draw_list, true);
  848. }
  849. RasterizerEffectsRD::RasterizerEffectsRD() {
  850. { // Initialize blur
  851. Vector<String> blur_modes;
  852. blur_modes.push_back("\n#define MODE_GAUSSIAN_BLUR\n");
  853. blur_modes.push_back("\n#define MODE_GAUSSIAN_GLOW\n");
  854. blur_modes.push_back("\n#define MODE_GAUSSIAN_GLOW\n#define GLOW_USE_AUTO_EXPOSURE\n");
  855. blur_modes.push_back("\n#define MODE_DOF_NEAR_BLUR\n#define DOF_QUALITY_LOW\n");
  856. blur_modes.push_back("\n#define MODE_DOF_NEAR_BLUR\n#define DOF_QUALITY_MEDIUM\n");
  857. blur_modes.push_back("\n#define MODE_DOF_NEAR_BLUR\n#define DOF_QUALITY_HIGH\n");
  858. blur_modes.push_back("\n#define MODE_DOF_NEAR_BLUR\n#define DOF_QUALITY_LOW\n#define DOF_NEAR_BLUR_MERGE\n");
  859. blur_modes.push_back("\n#define MODE_DOF_NEAR_BLUR\n#define DOF_QUALITY_MEDIUM\n#define DOF_NEAR_BLUR_MERGE\n");
  860. blur_modes.push_back("\n#define MODE_DOF_NEAR_BLUR\n#define DOF_QUALITY_HIGH\n#define DOF_NEAR_BLUR_MERGE\n");
  861. blur_modes.push_back("\n#define MODE_DOF_FAR_BLUR\n#define DOF_QUALITY_LOW\n");
  862. blur_modes.push_back("\n#define MODE_DOF_FAR_BLUR\n#define DOF_QUALITY_MEDIUM\n");
  863. blur_modes.push_back("\n#define MODE_DOF_FAR_BLUR\n#define DOF_QUALITY_HIGH\n");
  864. blur_modes.push_back("\n#define MODE_SSAO_MERGE\n");
  865. blur_modes.push_back("\n#define MODE_SIMPLE_COPY\n");
  866. blur_modes.push_back("\n#define MODE_MIPMAP\n");
  867. blur_modes.push_back("\n#define MODE_LINEARIZE_DEPTH_COPY\n");
  868. blur.shader.initialize(blur_modes);
  869. zeromem(&blur.push_constant, sizeof(BlurPushConstant));
  870. blur.shader_version = blur.shader.version_create();
  871. for (int i = 0; i < BLUR_MODE_MAX; i++) {
  872. blur.pipelines[i].setup(blur.shader.version_get_shader(blur.shader_version, i), RD::RENDER_PRIMITIVE_TRIANGLES, RD::PipelineRasterizationState(), RD::PipelineMultisampleState(), RD::PipelineDepthStencilState(), RD::PipelineColorBlendState::create_disabled(), 0);
  873. }
  874. }
  875. {
  876. // Initialize roughness
  877. Vector<String> cubemap_roughness_modes;
  878. cubemap_roughness_modes.push_back("");
  879. roughness.shader.initialize(cubemap_roughness_modes);
  880. roughness.shader_version = roughness.shader.version_create();
  881. roughness.pipeline = RD::get_singleton()->compute_pipeline_create(roughness.shader.version_get_shader(roughness.shader_version, 0));
  882. }
  883. {
  884. // Initialize tonemapper
  885. Vector<String> tonemap_modes;
  886. tonemap_modes.push_back("\n");
  887. tonemap_modes.push_back("\n#define USE_GLOW_FILTER_BICUBIC\n");
  888. tonemap.shader.initialize(tonemap_modes);
  889. tonemap.shader_version = tonemap.shader.version_create();
  890. for (int i = 0; i < TONEMAP_MODE_MAX; i++) {
  891. tonemap.pipelines[i].setup(tonemap.shader.version_get_shader(tonemap.shader_version, i), RD::RENDER_PRIMITIVE_TRIANGLES, RD::PipelineRasterizationState(), RD::PipelineMultisampleState(), RD::PipelineDepthStencilState(), RD::PipelineColorBlendState::create_disabled(), 0);
  892. }
  893. }
  894. {
  895. // Initialize luminance_reduce
  896. Vector<String> luminance_reduce_modes;
  897. luminance_reduce_modes.push_back("\n#define READ_TEXTURE\n");
  898. luminance_reduce_modes.push_back("\n");
  899. luminance_reduce_modes.push_back("\n#define WRITE_LUMINANCE\n");
  900. luminance_reduce.shader.initialize(luminance_reduce_modes);
  901. luminance_reduce.shader_version = luminance_reduce.shader.version_create();
  902. for (int i = 0; i < LUMINANCE_REDUCE_MAX; i++) {
  903. luminance_reduce.pipelines[i] = RD::get_singleton()->compute_pipeline_create(luminance_reduce.shader.version_get_shader(luminance_reduce.shader_version, i));
  904. }
  905. }
  906. {
  907. // Initialize copier
  908. Vector<String> copy_modes;
  909. copy_modes.push_back("\n#define MODE_CUBE_TO_DP\n");
  910. copy.shader.initialize(copy_modes);
  911. copy.shader_version = copy.shader.version_create();
  912. for (int i = 0; i < COPY_MODE_MAX; i++) {
  913. copy.pipelines[i].setup(copy.shader.version_get_shader(copy.shader_version, i), RD::RENDER_PRIMITIVE_TRIANGLES, RD::PipelineRasterizationState(), RD::PipelineMultisampleState(), RD::PipelineDepthStencilState(), RD::PipelineColorBlendState::create_disabled(), 0);
  914. }
  915. }
  916. {
  917. // Initialize bokeh
  918. Vector<String> bokeh_modes;
  919. bokeh_modes.push_back("\n#define MODE_GEN_BLUR_SIZE\n");
  920. bokeh_modes.push_back("\n#define MODE_BOKEH_BOX\n");
  921. bokeh_modes.push_back("\n#define MODE_BOKEH_HEXAGONAL\n");
  922. bokeh_modes.push_back("\n#define MODE_BOKEH_CIRCULAR\n");
  923. bokeh_modes.push_back("\n#define MODE_COMPOSITE_BOKEH\n");
  924. bokeh.shader.initialize(bokeh_modes);
  925. bokeh.shader_version = bokeh.shader.version_create();
  926. for (int i = 0; i < BOKEH_MAX; i++) {
  927. bokeh.pipelines[i] = RD::get_singleton()->compute_pipeline_create(bokeh.shader.version_get_shader(bokeh.shader_version, i));
  928. }
  929. }
  930. {
  931. // Initialize ssao
  932. uint32_t pipeline = 0;
  933. {
  934. Vector<String> ssao_modes;
  935. ssao_modes.push_back("\n#define MINIFY_START\n");
  936. ssao_modes.push_back("\n");
  937. ssao.minify_shader.initialize(ssao_modes);
  938. ssao.minify_shader_version = ssao.minify_shader.version_create();
  939. for (int i = 0; i <= SSAO_MINIFY_MIPMAP; i++) {
  940. ssao.pipelines[pipeline] = RD::get_singleton()->compute_pipeline_create(ssao.minify_shader.version_get_shader(ssao.minify_shader_version, i));
  941. pipeline++;
  942. }
  943. }
  944. {
  945. Vector<String> ssao_modes;
  946. ssao_modes.push_back("\n#define SSAO_QUALITY_LOW\n");
  947. ssao_modes.push_back("\n");
  948. ssao_modes.push_back("\n#define SSAO_QUALITY_HIGH\n");
  949. ssao_modes.push_back("\n#define SSAO_QUALITY_ULTRA\n");
  950. ssao_modes.push_back("\n#define SSAO_QUALITY_LOW\n#define USE_HALF_SIZE\n");
  951. ssao_modes.push_back("\n#define USE_HALF_SIZE\n");
  952. ssao_modes.push_back("\n#define SSAO_QUALITY_HIGH\n#define USE_HALF_SIZE\n");
  953. ssao_modes.push_back("\n#define SSAO_QUALITY_ULTRA\n#define USE_HALF_SIZE\n");
  954. ssao.gather_shader.initialize(ssao_modes);
  955. ssao.gather_shader_version = ssao.gather_shader.version_create();
  956. for (int i = SSAO_GATHER_LOW; i <= SSAO_GATHER_ULTRA_HALF; i++) {
  957. ssao.pipelines[pipeline] = RD::get_singleton()->compute_pipeline_create(ssao.gather_shader.version_get_shader(ssao.gather_shader_version, i - SSAO_GATHER_LOW));
  958. pipeline++;
  959. }
  960. }
  961. {
  962. Vector<String> ssao_modes;
  963. ssao_modes.push_back("\n#define MODE_FULL_SIZE\n");
  964. ssao_modes.push_back("\n");
  965. ssao_modes.push_back("\n#define MODE_UPSCALE\n");
  966. ssao.blur_shader.initialize(ssao_modes);
  967. ssao.blur_shader_version = ssao.blur_shader.version_create();
  968. for (int i = SSAO_BLUR_PASS; i <= SSAO_BLUR_UPSCALE; i++) {
  969. ssao.pipelines[pipeline] = RD::get_singleton()->compute_pipeline_create(ssao.blur_shader.version_get_shader(ssao.blur_shader_version, i - SSAO_BLUR_PASS));
  970. pipeline++;
  971. }
  972. }
  973. ERR_FAIL_COND(pipeline != SSAO_MAX);
  974. }
  975. {
  976. // Initialize roughness limiter
  977. Vector<String> shader_modes;
  978. shader_modes.push_back("");
  979. roughness_limiter.shader.initialize(shader_modes);
  980. roughness_limiter.shader_version = roughness_limiter.shader.version_create();
  981. roughness_limiter.pipeline = RD::get_singleton()->compute_pipeline_create(roughness_limiter.shader.version_get_shader(roughness_limiter.shader_version, 0));
  982. }
  983. {
  984. //Initialize cubemap downsampler
  985. Vector<String> cubemap_downsampler_modes;
  986. cubemap_downsampler_modes.push_back("");
  987. cubemap_downsampler.shader.initialize(cubemap_downsampler_modes);
  988. cubemap_downsampler.shader_version = cubemap_downsampler.shader.version_create();
  989. cubemap_downsampler.pipeline = RD::get_singleton()->compute_pipeline_create(cubemap_downsampler.shader.version_get_shader(cubemap_downsampler.shader_version, 0));
  990. }
  991. {
  992. // Initialize cubemap filter
  993. filter.use_high_quality = GLOBAL_GET("rendering/quality/reflections/fast_filter_high_quality");
  994. Vector<String> cubemap_filter_modes;
  995. cubemap_filter_modes.push_back("\n#define USE_HIGH_QUALITY\n");
  996. cubemap_filter_modes.push_back("\n#define USE_LOW_QUALITY\n");
  997. cubemap_filter_modes.push_back("\n#define USE_HIGH_QUALITY\n#define USE_TEXTURE_ARRAY\n");
  998. cubemap_filter_modes.push_back("\n#define USE_LOW_QUALITY\n#define USE_TEXTURE_ARRAY\n");
  999. filter.shader.initialize(cubemap_filter_modes);
  1000. filter.shader_version = filter.shader.version_create();
  1001. for (int i = 0; i < FILTER_MODE_MAX; i++) {
  1002. filter.pipelines[i] = RD::get_singleton()->compute_pipeline_create(filter.shader.version_get_shader(filter.shader_version, i));
  1003. }
  1004. if (filter.use_high_quality) {
  1005. filter.coefficient_buffer = RD::get_singleton()->storage_buffer_create(sizeof(high_quality_coeffs));
  1006. RD::get_singleton()->buffer_update(filter.coefficient_buffer, 0, sizeof(high_quality_coeffs), &high_quality_coeffs[0], false);
  1007. } else {
  1008. filter.coefficient_buffer = RD::get_singleton()->storage_buffer_create(sizeof(low_quality_coeffs));
  1009. RD::get_singleton()->buffer_update(filter.coefficient_buffer, 0, sizeof(low_quality_coeffs), &low_quality_coeffs[0], false);
  1010. }
  1011. Vector<RD::Uniform> uniforms;
  1012. {
  1013. RD::Uniform u;
  1014. u.type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
  1015. u.binding = 0;
  1016. u.ids.push_back(filter.coefficient_buffer);
  1017. uniforms.push_back(u);
  1018. }
  1019. filter.uniform_set = RD::get_singleton()->uniform_set_create(uniforms, filter.shader.version_get_shader(filter.shader_version, filter.use_high_quality ? 0 : 1), 1);
  1020. }
  1021. {
  1022. Vector<String> specular_modes;
  1023. specular_modes.push_back("\n#define MODE_MERGE\n");
  1024. specular_modes.push_back("\n#define MODE_MERGE\n#define MODE_SSR\n");
  1025. specular_modes.push_back("\n");
  1026. specular_modes.push_back("\n#define MODE_SSR\n");
  1027. specular_merge.shader.initialize(specular_modes);
  1028. specular_merge.shader_version = specular_merge.shader.version_create();
  1029. //use additive
  1030. RD::PipelineColorBlendState::Attachment ba;
  1031. ba.enable_blend = true;
  1032. ba.src_color_blend_factor = RD::BLEND_FACTOR_ONE;
  1033. ba.dst_color_blend_factor = RD::BLEND_FACTOR_ONE;
  1034. ba.src_alpha_blend_factor = RD::BLEND_FACTOR_ONE;
  1035. ba.dst_alpha_blend_factor = RD::BLEND_FACTOR_ONE;
  1036. ba.color_blend_op = RD::BLEND_OP_ADD;
  1037. ba.alpha_blend_op = RD::BLEND_OP_ADD;
  1038. RD::PipelineColorBlendState blend_additive;
  1039. blend_additive.attachments.push_back(ba);
  1040. for (int i = 0; i < SPECULAR_MERGE_MAX; i++) {
  1041. RD::PipelineColorBlendState blend_state;
  1042. if (i == SPECULAR_MERGE_ADDITIVE_ADD || i == SPECULAR_MERGE_ADDITIVE_SSR) {
  1043. blend_state = blend_additive;
  1044. } else {
  1045. blend_state = RD::PipelineColorBlendState::create_disabled();
  1046. }
  1047. specular_merge.pipelines[i].setup(specular_merge.shader.version_get_shader(specular_merge.shader_version, i), RD::RENDER_PRIMITIVE_TRIANGLES, RD::PipelineRasterizationState(), RD::PipelineMultisampleState(), RD::PipelineDepthStencilState(), blend_state, 0);
  1048. }
  1049. }
  1050. {
  1051. Vector<String> ssr_modes;
  1052. ssr_modes.push_back("\n");
  1053. ssr_modes.push_back("\n#define MODE_ROUGH\n");
  1054. ssr.shader.initialize(ssr_modes);
  1055. ssr.shader_version = ssr.shader.version_create();
  1056. for (int i = 0; i < SCREEN_SPACE_REFLECTION_MAX; i++) {
  1057. ssr.pipelines[i] = RD::get_singleton()->compute_pipeline_create(ssr.shader.version_get_shader(ssr.shader_version, i));
  1058. }
  1059. }
  1060. {
  1061. Vector<String> ssr_filter_modes;
  1062. ssr_filter_modes.push_back("\n");
  1063. ssr_filter_modes.push_back("\n#define VERTICAL_PASS\n");
  1064. ssr_filter.shader.initialize(ssr_filter_modes);
  1065. ssr_filter.shader_version = ssr_filter.shader.version_create();
  1066. for (int i = 0; i < SCREEN_SPACE_REFLECTION_FILTER_MAX; i++) {
  1067. ssr_filter.pipelines[i] = RD::get_singleton()->compute_pipeline_create(ssr_filter.shader.version_get_shader(ssr_filter.shader_version, i));
  1068. }
  1069. }
  1070. {
  1071. Vector<String> ssr_scale_modes;
  1072. ssr_scale_modes.push_back("\n");
  1073. ssr_scale.shader.initialize(ssr_scale_modes);
  1074. ssr_scale.shader_version = ssr_scale.shader.version_create();
  1075. ssr_scale.pipeline = RD::get_singleton()->compute_pipeline_create(ssr_scale.shader.version_get_shader(ssr_scale.shader_version, 0));
  1076. }
  1077. {
  1078. Vector<String> sss_modes;
  1079. sss_modes.push_back("\n#define USE_11_SAMPLES\n");
  1080. sss_modes.push_back("\n#define USE_17_SAMPLES\n");
  1081. sss_modes.push_back("\n#define USE_25_SAMPLES\n");
  1082. sss.shader.initialize(sss_modes);
  1083. sss.shader_version = sss.shader.version_create();
  1084. for (int i = 0; i < sss_modes.size(); i++) {
  1085. sss.pipelines[i] = RD::get_singleton()->compute_pipeline_create(sss.shader.version_get_shader(sss.shader_version, i));
  1086. }
  1087. }
  1088. RD::SamplerState sampler;
  1089. sampler.mag_filter = RD::SAMPLER_FILTER_LINEAR;
  1090. sampler.min_filter = RD::SAMPLER_FILTER_LINEAR;
  1091. sampler.max_lod = 0;
  1092. default_sampler = RD::get_singleton()->sampler_create(sampler);
  1093. sampler.min_filter = RD::SAMPLER_FILTER_LINEAR;
  1094. sampler.mip_filter = RD::SAMPLER_FILTER_LINEAR;
  1095. sampler.max_lod = 1e20;
  1096. default_mipmap_sampler = RD::get_singleton()->sampler_create(sampler);
  1097. { //create index array for copy shaders
  1098. Vector<uint8_t> pv;
  1099. pv.resize(6 * 4);
  1100. {
  1101. uint8_t *w = pv.ptrw();
  1102. int *p32 = (int *)w;
  1103. p32[0] = 0;
  1104. p32[1] = 1;
  1105. p32[2] = 2;
  1106. p32[3] = 0;
  1107. p32[4] = 2;
  1108. p32[5] = 3;
  1109. }
  1110. index_buffer = RD::get_singleton()->index_buffer_create(6, RenderingDevice::INDEX_BUFFER_FORMAT_UINT32, pv);
  1111. index_array = RD::get_singleton()->index_array_create(index_buffer, 0, 6);
  1112. }
  1113. }
  1114. RasterizerEffectsRD::~RasterizerEffectsRD() {
  1115. if (RD::get_singleton()->uniform_set_is_valid(filter.image_uniform_set)) {
  1116. RD::get_singleton()->free(filter.image_uniform_set);
  1117. }
  1118. if (RD::get_singleton()->uniform_set_is_valid(filter.uniform_set)) {
  1119. RD::get_singleton()->free(filter.uniform_set);
  1120. }
  1121. RD::get_singleton()->free(default_sampler);
  1122. RD::get_singleton()->free(default_mipmap_sampler);
  1123. RD::get_singleton()->free(index_buffer); //array gets freed as dependency
  1124. RD::get_singleton()->free(filter.coefficient_buffer);
  1125. blur.shader.version_free(blur.shader_version);
  1126. bokeh.shader.version_free(bokeh.shader_version);
  1127. copy.shader.version_free(copy.shader_version);
  1128. cubemap_downsampler.shader.version_free(cubemap_downsampler.shader_version);
  1129. filter.shader.version_free(filter.shader_version);
  1130. luminance_reduce.shader.version_free(luminance_reduce.shader_version);
  1131. roughness.shader.version_free(roughness.shader_version);
  1132. roughness_limiter.shader.version_free(roughness_limiter.shader_version);
  1133. specular_merge.shader.version_free(specular_merge.shader_version);
  1134. ssao.blur_shader.version_free(ssao.blur_shader_version);
  1135. ssao.gather_shader.version_free(ssao.gather_shader_version);
  1136. ssao.minify_shader.version_free(ssao.minify_shader_version);
  1137. ssr.shader.version_free(ssr.shader_version);
  1138. ssr_filter.shader.version_free(ssr_filter.shader_version);
  1139. ssr_scale.shader.version_free(ssr_scale.shader_version);
  1140. sss.shader.version_free(sss.shader_version);
  1141. tonemap.shader.version_free(tonemap.shader_version);
  1142. }