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