renderer_scene_gi_rd.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. /*************************************************************************/
  2. /* renderer_scene_gi_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 RENDERING_SERVER_SCENE_GI_RD_H
  31. #define RENDERING_SERVER_SCENE_GI_RD_H
  32. #include "core/templates/local_vector.h"
  33. #include "core/templates/rid_owner.h"
  34. #include "servers/rendering/renderer_compositor.h"
  35. #include "servers/rendering/renderer_rd/renderer_scene_environment_rd.h"
  36. #include "servers/rendering/renderer_rd/renderer_scene_sky_rd.h"
  37. #include "servers/rendering/renderer_rd/renderer_storage_rd.h"
  38. #include "servers/rendering/renderer_rd/shaders/gi.glsl.gen.h"
  39. #include "servers/rendering/renderer_rd/shaders/giprobe.glsl.gen.h"
  40. #include "servers/rendering/renderer_rd/shaders/giprobe_debug.glsl.gen.h"
  41. #include "servers/rendering/renderer_rd/shaders/sdfgi_debug.glsl.gen.h"
  42. #include "servers/rendering/renderer_rd/shaders/sdfgi_debug_probes.glsl.gen.h"
  43. #include "servers/rendering/renderer_rd/shaders/sdfgi_direct_light.glsl.gen.h"
  44. #include "servers/rendering/renderer_rd/shaders/sdfgi_integrate.glsl.gen.h"
  45. #include "servers/rendering/renderer_rd/shaders/sdfgi_preprocess.glsl.gen.h"
  46. #include "servers/rendering/renderer_scene_render.h"
  47. #include "servers/rendering/rendering_device.h"
  48. // Forward declare RendererSceneRenderRD so we can pass it into some of our methods, these classes are pretty tightly bound
  49. class RendererSceneRenderRD;
  50. class RendererSceneGIRD {
  51. private:
  52. RendererStorageRD *storage;
  53. /* GIPROBE INSTANCE */
  54. struct GIProbeLight {
  55. uint32_t type;
  56. float energy;
  57. float radius;
  58. float attenuation;
  59. float color[3];
  60. float cos_spot_angle;
  61. float position[3];
  62. float inv_spot_attenuation;
  63. float direction[3];
  64. uint32_t has_shadow;
  65. };
  66. struct GIProbePushConstant {
  67. int32_t limits[3];
  68. uint32_t stack_size;
  69. float emission_scale;
  70. float propagation;
  71. float dynamic_range;
  72. uint32_t light_count;
  73. uint32_t cell_offset;
  74. uint32_t cell_count;
  75. float aniso_strength;
  76. uint32_t pad;
  77. };
  78. struct GIProbeDynamicPushConstant {
  79. int32_t limits[3];
  80. uint32_t light_count;
  81. int32_t x_dir[3];
  82. float z_base;
  83. int32_t y_dir[3];
  84. float z_sign;
  85. int32_t z_dir[3];
  86. float pos_multiplier;
  87. uint32_t rect_pos[2];
  88. uint32_t rect_size[2];
  89. uint32_t prev_rect_ofs[2];
  90. uint32_t prev_rect_size[2];
  91. uint32_t flip_x;
  92. uint32_t flip_y;
  93. float dynamic_range;
  94. uint32_t on_mipmap;
  95. float propagation;
  96. float pad[3];
  97. };
  98. GIProbeLight *gi_probe_lights;
  99. uint32_t gi_probe_max_lights;
  100. RID gi_probe_lights_uniform;
  101. enum {
  102. GI_PROBE_SHADER_VERSION_COMPUTE_LIGHT,
  103. GI_PROBE_SHADER_VERSION_COMPUTE_SECOND_BOUNCE,
  104. GI_PROBE_SHADER_VERSION_COMPUTE_MIPMAP,
  105. GI_PROBE_SHADER_VERSION_WRITE_TEXTURE,
  106. GI_PROBE_SHADER_VERSION_DYNAMIC_OBJECT_LIGHTING,
  107. GI_PROBE_SHADER_VERSION_DYNAMIC_SHRINK_WRITE,
  108. GI_PROBE_SHADER_VERSION_DYNAMIC_SHRINK_PLOT,
  109. GI_PROBE_SHADER_VERSION_DYNAMIC_SHRINK_WRITE_PLOT,
  110. GI_PROBE_SHADER_VERSION_MAX
  111. };
  112. GiprobeShaderRD giprobe_shader;
  113. RID giprobe_lighting_shader_version;
  114. RID giprobe_lighting_shader_version_shaders[GI_PROBE_SHADER_VERSION_MAX];
  115. RID giprobe_lighting_shader_version_pipelines[GI_PROBE_SHADER_VERSION_MAX];
  116. enum {
  117. GI_PROBE_DEBUG_COLOR,
  118. GI_PROBE_DEBUG_LIGHT,
  119. GI_PROBE_DEBUG_EMISSION,
  120. GI_PROBE_DEBUG_LIGHT_FULL,
  121. GI_PROBE_DEBUG_MAX
  122. };
  123. struct GIProbeDebugPushConstant {
  124. float projection[16];
  125. uint32_t cell_offset;
  126. float dynamic_range;
  127. float alpha;
  128. uint32_t level;
  129. int32_t bounds[3];
  130. uint32_t pad;
  131. };
  132. GiprobeDebugShaderRD giprobe_debug_shader;
  133. RID giprobe_debug_shader_version;
  134. RID giprobe_debug_shader_version_shaders[GI_PROBE_DEBUG_MAX];
  135. PipelineCacheRD giprobe_debug_shader_version_pipelines[GI_PROBE_DEBUG_MAX];
  136. RID giprobe_debug_uniform_set;
  137. /* SDFGI */
  138. struct SDFGIShader {
  139. enum SDFGIPreprocessShaderVersion {
  140. PRE_PROCESS_SCROLL,
  141. PRE_PROCESS_SCROLL_OCCLUSION,
  142. PRE_PROCESS_JUMP_FLOOD_INITIALIZE,
  143. PRE_PROCESS_JUMP_FLOOD_INITIALIZE_HALF,
  144. PRE_PROCESS_JUMP_FLOOD,
  145. PRE_PROCESS_JUMP_FLOOD_OPTIMIZED,
  146. PRE_PROCESS_JUMP_FLOOD_UPSCALE,
  147. PRE_PROCESS_OCCLUSION,
  148. PRE_PROCESS_STORE,
  149. PRE_PROCESS_MAX
  150. };
  151. struct PreprocessPushConstant {
  152. int32_t scroll[3];
  153. int32_t grid_size;
  154. int32_t probe_offset[3];
  155. int32_t step_size;
  156. int32_t half_size;
  157. uint32_t occlusion_index;
  158. int32_t cascade;
  159. uint32_t pad;
  160. };
  161. SdfgiPreprocessShaderRD preprocess;
  162. RID preprocess_shader;
  163. RID preprocess_pipeline[PRE_PROCESS_MAX];
  164. struct DebugPushConstant {
  165. float grid_size[3];
  166. uint32_t max_cascades;
  167. int32_t screen_size[2];
  168. uint32_t use_occlusion;
  169. float y_mult;
  170. float cam_extent[3];
  171. uint32_t probe_axis_size;
  172. float cam_transform[16];
  173. };
  174. SdfgiDebugShaderRD debug;
  175. RID debug_shader;
  176. RID debug_shader_version;
  177. RID debug_pipeline;
  178. enum ProbeDebugMode {
  179. PROBE_DEBUG_PROBES,
  180. PROBE_DEBUG_VISIBILITY,
  181. PROBE_DEBUG_MAX
  182. };
  183. struct DebugProbesPushConstant {
  184. float projection[16];
  185. uint32_t band_power;
  186. uint32_t sections_in_band;
  187. uint32_t band_mask;
  188. float section_arc;
  189. float grid_size[3];
  190. uint32_t cascade;
  191. uint32_t pad;
  192. float y_mult;
  193. int32_t probe_debug_index;
  194. int32_t probe_axis_size;
  195. };
  196. SdfgiDebugProbesShaderRD debug_probes;
  197. RID debug_probes_shader;
  198. RID debug_probes_shader_version;
  199. PipelineCacheRD debug_probes_pipeline[PROBE_DEBUG_MAX];
  200. struct Light {
  201. float color[3];
  202. float energy;
  203. float direction[3];
  204. uint32_t has_shadow;
  205. float position[3];
  206. float attenuation;
  207. uint32_t type;
  208. float cos_spot_angle;
  209. float inv_spot_attenuation;
  210. float radius;
  211. float shadow_color[4];
  212. };
  213. struct DirectLightPushConstant {
  214. float grid_size[3];
  215. uint32_t max_cascades;
  216. uint32_t cascade;
  217. uint32_t light_count;
  218. uint32_t process_offset;
  219. uint32_t process_increment;
  220. int32_t probe_axis_size;
  221. float bounce_feedback;
  222. float y_mult;
  223. uint32_t use_occlusion;
  224. };
  225. enum {
  226. DIRECT_LIGHT_MODE_STATIC,
  227. DIRECT_LIGHT_MODE_DYNAMIC,
  228. DIRECT_LIGHT_MODE_MAX
  229. };
  230. SdfgiDirectLightShaderRD direct_light;
  231. RID direct_light_shader;
  232. RID direct_light_pipeline[DIRECT_LIGHT_MODE_MAX];
  233. enum {
  234. INTEGRATE_MODE_PROCESS,
  235. INTEGRATE_MODE_STORE,
  236. INTEGRATE_MODE_SCROLL,
  237. INTEGRATE_MODE_SCROLL_STORE,
  238. INTEGRATE_MODE_MAX
  239. };
  240. struct IntegratePushConstant {
  241. enum {
  242. SKY_MODE_DISABLED,
  243. SKY_MODE_COLOR,
  244. SKY_MODE_SKY,
  245. };
  246. float grid_size[3];
  247. uint32_t max_cascades;
  248. uint32_t probe_axis_size;
  249. uint32_t cascade;
  250. uint32_t history_index;
  251. uint32_t history_size;
  252. uint32_t ray_count;
  253. float ray_bias;
  254. int32_t image_size[2];
  255. int32_t world_offset[3];
  256. uint32_t sky_mode;
  257. int32_t scroll[3];
  258. float sky_energy;
  259. float sky_color[3];
  260. float y_mult;
  261. uint32_t store_ambient_texture;
  262. uint32_t pad[3];
  263. };
  264. SdfgiIntegrateShaderRD integrate;
  265. RID integrate_shader;
  266. RID integrate_pipeline[INTEGRATE_MODE_MAX];
  267. RID integrate_default_sky_uniform_set;
  268. } sdfgi_shader;
  269. public:
  270. /* GIPROBE INSTANCE */
  271. //@TODO GIProbeInstance is still directly used in the render code, we'll address this when we refactor the render code itself.
  272. struct GIProbeInstance {
  273. // access to our containers
  274. RendererStorageRD *storage;
  275. RendererSceneGIRD *gi;
  276. RID probe;
  277. RID texture;
  278. RID write_buffer;
  279. struct Mipmap {
  280. RID texture;
  281. RID uniform_set;
  282. RID second_bounce_uniform_set;
  283. RID write_uniform_set;
  284. uint32_t level;
  285. uint32_t cell_offset;
  286. uint32_t cell_count;
  287. };
  288. Vector<Mipmap> mipmaps;
  289. struct DynamicMap {
  290. RID texture; //color normally, or emission on first pass
  291. RID fb_depth; //actual depth buffer for the first pass, float depth for later passes
  292. RID depth; //actual depth buffer for the first pass, float depth for later passes
  293. RID normal; //normal buffer for the first pass
  294. RID albedo; //emission buffer for the first pass
  295. RID orm; //orm buffer for the first pass
  296. RID fb; //used for rendering, only valid on first map
  297. RID uniform_set;
  298. uint32_t size;
  299. int mipmap; // mipmap to write to, -1 if no mipmap assigned
  300. };
  301. Vector<DynamicMap> dynamic_maps;
  302. int slot = -1;
  303. uint32_t last_probe_version = 0;
  304. uint32_t last_probe_data_version = 0;
  305. //uint64_t last_pass = 0;
  306. uint32_t render_index = 0;
  307. bool has_dynamic_object_data = false;
  308. Transform transform;
  309. void update(bool p_update_light_instances, const Vector<RID> &p_light_instances, const PagedArray<RendererSceneRender::GeometryInstance *> &p_dynamic_objects, RendererSceneRenderRD *p_scene_render);
  310. void debug(RD::DrawListID p_draw_list, RID p_framebuffer, const CameraMatrix &p_camera_with_transform, bool p_lighting, bool p_emission, float p_alpha);
  311. };
  312. mutable RID_Owner<GIProbeInstance> gi_probe_instance_owner;
  313. _FORCE_INLINE_ GIProbeInstance *get_probe_instance(RID p_probe) const {
  314. return gi_probe_instance_owner.getornull(p_probe);
  315. };
  316. _FORCE_INLINE_ RID gi_probe_instance_get_texture(RID p_probe) {
  317. GIProbeInstance *gi_probe = get_probe_instance(p_probe);
  318. ERR_FAIL_COND_V(!gi_probe, RID());
  319. return gi_probe->texture;
  320. };
  321. RS::GIProbeQuality gi_probe_quality = RS::GI_PROBE_QUALITY_HIGH;
  322. /* SDFGI */
  323. struct SDFGI {
  324. enum {
  325. MAX_CASCADES = 8,
  326. CASCADE_SIZE = 128,
  327. PROBE_DIVISOR = 16,
  328. ANISOTROPY_SIZE = 6,
  329. MAX_DYNAMIC_LIGHTS = 128,
  330. MAX_STATIC_LIGHTS = 1024,
  331. LIGHTPROBE_OCT_SIZE = 6,
  332. SH_SIZE = 16
  333. };
  334. struct Cascade {
  335. struct UBO {
  336. float offset[3];
  337. float to_cell;
  338. int32_t probe_offset[3];
  339. uint32_t pad;
  340. };
  341. //cascade blocks are full-size for volume (128^3), half size for albedo/emission
  342. RID sdf_tex;
  343. RID light_tex;
  344. RID light_aniso_0_tex;
  345. RID light_aniso_1_tex;
  346. RID light_data;
  347. RID light_aniso_0_data;
  348. RID light_aniso_1_data;
  349. struct SolidCell { // this struct is unused, but remains as reference for size
  350. uint32_t position;
  351. uint32_t albedo;
  352. uint32_t static_light;
  353. uint32_t static_light_aniso;
  354. };
  355. RID solid_cell_dispatch_buffer; //buffer for indirect compute dispatch
  356. RID solid_cell_buffer;
  357. RID lightprobe_history_tex;
  358. RID lightprobe_average_tex;
  359. float cell_size;
  360. Vector3i position;
  361. static const Vector3i DIRTY_ALL;
  362. Vector3i dirty_regions; //(0,0,0 is not dirty, negative is refresh from the end, DIRTY_ALL is refresh all.
  363. RID sdf_store_uniform_set;
  364. RID sdf_direct_light_uniform_set;
  365. RID scroll_uniform_set;
  366. RID scroll_occlusion_uniform_set;
  367. RID integrate_uniform_set;
  368. RID lights_buffer;
  369. bool all_dynamic_lights_dirty = true;
  370. };
  371. // access to our containers
  372. RendererStorageRD *storage;
  373. RendererSceneGIRD *gi;
  374. // used for rendering (voxelization)
  375. RID render_albedo;
  376. RID render_emission;
  377. RID render_emission_aniso;
  378. RID render_occlusion[8];
  379. RID render_geom_facing;
  380. RID render_sdf[2];
  381. RID render_sdf_half[2];
  382. // used for ping pong processing in cascades
  383. RID sdf_initialize_uniform_set;
  384. RID sdf_initialize_half_uniform_set;
  385. RID jump_flood_uniform_set[2];
  386. RID jump_flood_half_uniform_set[2];
  387. RID sdf_upscale_uniform_set;
  388. int upscale_jfa_uniform_set_index;
  389. RID occlusion_uniform_set;
  390. uint32_t cascade_size = 128;
  391. LocalVector<Cascade> cascades;
  392. RID lightprobe_texture;
  393. RID lightprobe_data;
  394. RID occlusion_texture;
  395. RID occlusion_data;
  396. RID ambient_texture; //integrates with volumetric fog
  397. RID lightprobe_history_scroll; //used for scrolling lightprobes
  398. RID lightprobe_average_scroll; //used for scrolling lightprobes
  399. uint32_t history_size = 0;
  400. float solid_cell_ratio = 0;
  401. uint32_t solid_cell_count = 0;
  402. RS::EnvironmentSDFGICascades cascade_mode;
  403. float min_cell_size = 0;
  404. uint32_t probe_axis_count = 0; //amount of probes per axis, this is an odd number because it encloses endpoints
  405. RID debug_uniform_set;
  406. RID debug_probes_uniform_set;
  407. RID cascades_ubo;
  408. bool uses_occlusion = false;
  409. float bounce_feedback = 0.0;
  410. bool reads_sky = false;
  411. float energy = 1.0;
  412. float normal_bias = 1.1;
  413. float probe_bias = 1.1;
  414. RS::EnvironmentSDFGIYScale y_scale_mode = RS::ENV_SDFGI_Y_SCALE_DISABLED;
  415. float y_mult = 1.0;
  416. uint32_t render_pass = 0;
  417. int32_t cascade_dynamic_light_count[SDFGI::MAX_CASCADES]; //used dynamically
  418. RID integrate_sky_uniform_set;
  419. void create(RendererSceneEnvironmentRD *p_env, const Vector3 &p_world_position, uint32_t p_requested_history_size, RendererSceneGIRD *p_gi);
  420. void erase();
  421. void update(RendererSceneEnvironmentRD *p_env, const Vector3 &p_world_position);
  422. void update_light();
  423. void update_probes(RendererSceneEnvironmentRD *p_env, RendererSceneSkyRD::Sky *p_sky);
  424. void store_probes();
  425. int get_pending_region_data(int p_region, Vector3i &r_local_offset, Vector3i &r_local_size, AABB &r_bounds) const;
  426. void update_cascades();
  427. void debug_draw(const CameraMatrix &p_projection, const Transform &p_transform, int p_width, int p_height, RID p_render_target, RID p_texture);
  428. void debug_probes(RD::DrawListID p_draw_list, RID p_framebuffer, const CameraMatrix &p_camera_with_transform);
  429. void pre_process_gi(const Transform &p_transform, RendererSceneRenderRD *p_scene_render);
  430. void render_region(RID p_render_buffers, int p_region, const PagedArray<RendererSceneRender::GeometryInstance *> &p_instances, RendererSceneRenderRD *p_scene_render);
  431. void render_static_lights(RID p_render_buffers, uint32_t p_cascade_count, const uint32_t *p_cascade_indices, const PagedArray<RID> *p_positional_light_cull_result, RendererSceneRenderRD *p_scene_render);
  432. };
  433. RS::EnvironmentSDFGIRayCount sdfgi_ray_count = RS::ENV_SDFGI_RAY_COUNT_16;
  434. RS::EnvironmentSDFGIFramesToConverge sdfgi_frames_to_converge = RS::ENV_SDFGI_CONVERGE_IN_10_FRAMES;
  435. RS::EnvironmentSDFGIFramesToUpdateLight sdfgi_frames_to_update_light = RS::ENV_SDFGI_UPDATE_LIGHT_IN_4_FRAMES;
  436. float sdfgi_solid_cell_ratio = 0.25;
  437. Vector3 sdfgi_debug_probe_pos;
  438. Vector3 sdfgi_debug_probe_dir;
  439. bool sdfgi_debug_probe_enabled = false;
  440. Vector3i sdfgi_debug_probe_index;
  441. /* SDFGI UPDATE */
  442. int sdfgi_get_lightprobe_octahedron_size() const { return SDFGI::LIGHTPROBE_OCT_SIZE; }
  443. /* GI */
  444. enum {
  445. MAX_GIPROBES = 8
  446. };
  447. // Struct for use in render buffer
  448. struct RenderBuffersGI {
  449. RID giprobe_textures[MAX_GIPROBES];
  450. RID giprobe_buffer;
  451. RID full_buffer;
  452. RID full_dispatch;
  453. RID full_mask;
  454. RID uniform_set;
  455. bool using_half_size_gi = false;
  456. };
  457. struct SDFGIData {
  458. float grid_size[3];
  459. uint32_t max_cascades;
  460. uint32_t use_occlusion;
  461. int32_t probe_axis_size;
  462. float probe_to_uvw;
  463. float normal_bias;
  464. float lightprobe_tex_pixel_size[3];
  465. float energy;
  466. float lightprobe_uv_offset[3];
  467. float y_mult;
  468. float occlusion_clamp[3];
  469. uint32_t pad3;
  470. float occlusion_renormalize[3];
  471. uint32_t pad4;
  472. float cascade_probe_size[3];
  473. uint32_t pad5;
  474. struct ProbeCascadeData {
  475. float position[3]; //offset of (0,0,0) in world coordinates
  476. float to_probe; // 1/bounds * grid_size
  477. int32_t probe_world_offset[3];
  478. float to_cell; // 1/bounds * grid_size
  479. };
  480. ProbeCascadeData cascades[SDFGI::MAX_CASCADES];
  481. };
  482. struct GIProbeData {
  483. float xform[16];
  484. float bounds[3];
  485. float dynamic_range;
  486. float bias;
  487. float normal_bias;
  488. uint32_t blend_ambient;
  489. uint32_t texture_slot;
  490. float anisotropy_strength;
  491. float ao;
  492. float ao_size;
  493. uint32_t mipmaps;
  494. };
  495. struct PushConstant {
  496. int32_t screen_size[2];
  497. float z_near;
  498. float z_far;
  499. float proj_info[4];
  500. float ao_color[3];
  501. uint32_t max_giprobes;
  502. uint32_t high_quality_vct;
  503. uint32_t orthogonal;
  504. uint32_t pad[2];
  505. float cam_rotation[12];
  506. };
  507. RID sdfgi_ubo;
  508. enum Mode {
  509. MODE_GIPROBE,
  510. MODE_SDFGI,
  511. MODE_COMBINED,
  512. MODE_HALF_RES_GIPROBE,
  513. MODE_HALF_RES_SDFGI,
  514. MODE_HALF_RES_COMBINED,
  515. MODE_MAX
  516. };
  517. RID default_giprobe_buffer;
  518. bool half_resolution = false;
  519. GiShaderRD shader;
  520. RID shader_version;
  521. RID pipelines[MODE_MAX];
  522. RendererSceneGIRD();
  523. ~RendererSceneGIRD();
  524. void init(RendererStorageRD *p_storage, RendererSceneSkyRD *p_sky);
  525. void free();
  526. SDFGI *create_sdfgi(RendererSceneEnvironmentRD *p_env, const Vector3 &p_world_position, uint32_t p_requested_history_size);
  527. void setup_giprobes(RID p_render_buffers, const Transform &p_transform, const PagedArray<RID> &p_gi_probes, uint32_t &r_gi_probes_used, RendererSceneRenderRD *p_scene_render);
  528. void process_gi(RID p_render_buffers, RID p_normal_roughness_buffer, RID p_gi_probe_buffer, RID p_environment, const CameraMatrix &p_projection, const Transform &p_transform, const PagedArray<RID> &p_gi_probes, RendererSceneRenderRD *p_scene_render);
  529. RID gi_probe_instance_create(RID p_base);
  530. void gi_probe_instance_set_transform_to_data(RID p_probe, const Transform &p_xform);
  531. bool gi_probe_needs_update(RID p_probe) const;
  532. void gi_probe_update(RID p_probe, bool p_update_light_instances, const Vector<RID> &p_light_instances, const PagedArray<RendererSceneRender::GeometryInstance *> &p_dynamic_objects, RendererSceneRenderRD *p_scene_render);
  533. void debug_giprobe(RID p_gi_probe, RD::DrawListID p_draw_list, RID p_framebuffer, const CameraMatrix &p_camera_with_transform, bool p_lighting, bool p_emission, float p_alpha);
  534. };
  535. #endif /* !RENDERING_SERVER_SCENE_GI_RD_H */