voxel_gi.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. /*************************************************************************/
  2. /* voxel_gi.cpp */
  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. #include "voxel_gi.h"
  31. #include "mesh_instance_3d.h"
  32. #include "multimesh_instance_3d.h"
  33. #include "voxelizer.h"
  34. void VoxelGIData::_set_data(const Dictionary &p_data) {
  35. ERR_FAIL_COND(!p_data.has("bounds"));
  36. ERR_FAIL_COND(!p_data.has("octree_size"));
  37. ERR_FAIL_COND(!p_data.has("octree_cells"));
  38. ERR_FAIL_COND(!p_data.has("octree_data"));
  39. ERR_FAIL_COND(!p_data.has("octree_df") && !p_data.has("octree_df_png"));
  40. ERR_FAIL_COND(!p_data.has("level_counts"));
  41. ERR_FAIL_COND(!p_data.has("to_cell_xform"));
  42. AABB bounds = p_data["bounds"];
  43. Vector3 octree_size = p_data["octree_size"];
  44. Vector<uint8_t> octree_cells = p_data["octree_cells"];
  45. Vector<uint8_t> octree_data = p_data["octree_data"];
  46. Vector<uint8_t> octree_df;
  47. if (p_data.has("octree_df")) {
  48. octree_df = p_data["octree_df"];
  49. } else if (p_data.has("octree_df_png")) {
  50. Vector<uint8_t> octree_df_png = p_data["octree_df_png"];
  51. Ref<Image> img;
  52. img.instantiate();
  53. Error err = img->load_png_from_buffer(octree_df_png);
  54. ERR_FAIL_COND(err != OK);
  55. ERR_FAIL_COND(img->get_format() != Image::FORMAT_L8);
  56. octree_df = img->get_data();
  57. }
  58. Vector<int> octree_levels = p_data["level_counts"];
  59. Transform3D to_cell_xform = p_data["to_cell_xform"];
  60. allocate(to_cell_xform, bounds, octree_size, octree_cells, octree_data, octree_df, octree_levels);
  61. }
  62. Dictionary VoxelGIData::_get_data() const {
  63. Dictionary d;
  64. d["bounds"] = get_bounds();
  65. Vector3i otsize = get_octree_size();
  66. d["octree_size"] = Vector3(otsize);
  67. d["octree_cells"] = get_octree_cells();
  68. d["octree_data"] = get_data_cells();
  69. if (otsize != Vector3i()) {
  70. Ref<Image> img;
  71. img.instantiate();
  72. img->create(otsize.x * otsize.y, otsize.z, false, Image::FORMAT_L8, get_distance_field());
  73. Vector<uint8_t> df_png = img->save_png_to_buffer();
  74. ERR_FAIL_COND_V(df_png.size() == 0, Dictionary());
  75. d["octree_df_png"] = df_png;
  76. } else {
  77. d["octree_df"] = Vector<uint8_t>();
  78. }
  79. d["level_counts"] = get_level_counts();
  80. d["to_cell_xform"] = get_to_cell_xform();
  81. return d;
  82. }
  83. void VoxelGIData::allocate(const Transform3D &p_to_cell_xform, const AABB &p_aabb, const Vector3 &p_octree_size, const Vector<uint8_t> &p_octree_cells, const Vector<uint8_t> &p_data_cells, const Vector<uint8_t> &p_distance_field, const Vector<int> &p_level_counts) {
  84. RS::get_singleton()->voxel_gi_allocate_data(probe, p_to_cell_xform, p_aabb, p_octree_size, p_octree_cells, p_data_cells, p_distance_field, p_level_counts);
  85. bounds = p_aabb;
  86. to_cell_xform = p_to_cell_xform;
  87. octree_size = p_octree_size;
  88. }
  89. AABB VoxelGIData::get_bounds() const {
  90. return bounds;
  91. }
  92. Vector3 VoxelGIData::get_octree_size() const {
  93. return octree_size;
  94. }
  95. Vector<uint8_t> VoxelGIData::get_octree_cells() const {
  96. return RS::get_singleton()->voxel_gi_get_octree_cells(probe);
  97. }
  98. Vector<uint8_t> VoxelGIData::get_data_cells() const {
  99. return RS::get_singleton()->voxel_gi_get_data_cells(probe);
  100. }
  101. Vector<uint8_t> VoxelGIData::get_distance_field() const {
  102. return RS::get_singleton()->voxel_gi_get_distance_field(probe);
  103. }
  104. Vector<int> VoxelGIData::get_level_counts() const {
  105. return RS::get_singleton()->voxel_gi_get_level_counts(probe);
  106. }
  107. Transform3D VoxelGIData::get_to_cell_xform() const {
  108. return to_cell_xform;
  109. }
  110. void VoxelGIData::set_dynamic_range(float p_range) {
  111. RS::get_singleton()->voxel_gi_set_dynamic_range(probe, p_range);
  112. dynamic_range = p_range;
  113. }
  114. float VoxelGIData::get_dynamic_range() const {
  115. return dynamic_range;
  116. }
  117. void VoxelGIData::set_propagation(float p_propagation) {
  118. RS::get_singleton()->voxel_gi_set_propagation(probe, p_propagation);
  119. propagation = p_propagation;
  120. }
  121. float VoxelGIData::get_propagation() const {
  122. return propagation;
  123. }
  124. void VoxelGIData::set_energy(float p_energy) {
  125. RS::get_singleton()->voxel_gi_set_energy(probe, p_energy);
  126. energy = p_energy;
  127. }
  128. float VoxelGIData::get_energy() const {
  129. return energy;
  130. }
  131. void VoxelGIData::set_bias(float p_bias) {
  132. RS::get_singleton()->voxel_gi_set_bias(probe, p_bias);
  133. bias = p_bias;
  134. }
  135. float VoxelGIData::get_bias() const {
  136. return bias;
  137. }
  138. void VoxelGIData::set_normal_bias(float p_normal_bias) {
  139. RS::get_singleton()->voxel_gi_set_normal_bias(probe, p_normal_bias);
  140. normal_bias = p_normal_bias;
  141. }
  142. float VoxelGIData::get_normal_bias() const {
  143. return normal_bias;
  144. }
  145. void VoxelGIData::set_interior(bool p_enable) {
  146. RS::get_singleton()->voxel_gi_set_interior(probe, p_enable);
  147. interior = p_enable;
  148. }
  149. bool VoxelGIData::is_interior() const {
  150. return interior;
  151. }
  152. void VoxelGIData::set_use_two_bounces(bool p_enable) {
  153. RS::get_singleton()->voxel_gi_set_use_two_bounces(probe, p_enable);
  154. use_two_bounces = p_enable;
  155. }
  156. bool VoxelGIData::is_using_two_bounces() const {
  157. return use_two_bounces;
  158. }
  159. RID VoxelGIData::get_rid() const {
  160. return probe;
  161. }
  162. void VoxelGIData::_bind_methods() {
  163. ClassDB::bind_method(D_METHOD("allocate", "to_cell_xform", "aabb", "octree_size", "octree_cells", "data_cells", "distance_field", "level_counts"), &VoxelGIData::allocate);
  164. ClassDB::bind_method(D_METHOD("get_bounds"), &VoxelGIData::get_bounds);
  165. ClassDB::bind_method(D_METHOD("get_octree_size"), &VoxelGIData::get_octree_size);
  166. ClassDB::bind_method(D_METHOD("get_to_cell_xform"), &VoxelGIData::get_to_cell_xform);
  167. ClassDB::bind_method(D_METHOD("get_octree_cells"), &VoxelGIData::get_octree_cells);
  168. ClassDB::bind_method(D_METHOD("get_data_cells"), &VoxelGIData::get_data_cells);
  169. ClassDB::bind_method(D_METHOD("get_level_counts"), &VoxelGIData::get_level_counts);
  170. ClassDB::bind_method(D_METHOD("set_dynamic_range", "dynamic_range"), &VoxelGIData::set_dynamic_range);
  171. ClassDB::bind_method(D_METHOD("get_dynamic_range"), &VoxelGIData::get_dynamic_range);
  172. ClassDB::bind_method(D_METHOD("set_energy", "energy"), &VoxelGIData::set_energy);
  173. ClassDB::bind_method(D_METHOD("get_energy"), &VoxelGIData::get_energy);
  174. ClassDB::bind_method(D_METHOD("set_bias", "bias"), &VoxelGIData::set_bias);
  175. ClassDB::bind_method(D_METHOD("get_bias"), &VoxelGIData::get_bias);
  176. ClassDB::bind_method(D_METHOD("set_normal_bias", "bias"), &VoxelGIData::set_normal_bias);
  177. ClassDB::bind_method(D_METHOD("get_normal_bias"), &VoxelGIData::get_normal_bias);
  178. ClassDB::bind_method(D_METHOD("set_propagation", "propagation"), &VoxelGIData::set_propagation);
  179. ClassDB::bind_method(D_METHOD("get_propagation"), &VoxelGIData::get_propagation);
  180. ClassDB::bind_method(D_METHOD("set_interior", "interior"), &VoxelGIData::set_interior);
  181. ClassDB::bind_method(D_METHOD("is_interior"), &VoxelGIData::is_interior);
  182. ClassDB::bind_method(D_METHOD("set_use_two_bounces", "enable"), &VoxelGIData::set_use_two_bounces);
  183. ClassDB::bind_method(D_METHOD("is_using_two_bounces"), &VoxelGIData::is_using_two_bounces);
  184. ClassDB::bind_method(D_METHOD("_set_data", "data"), &VoxelGIData::_set_data);
  185. ClassDB::bind_method(D_METHOD("_get_data"), &VoxelGIData::_get_data);
  186. ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_data", "_get_data");
  187. ADD_PROPERTY(PropertyInfo(Variant::INT, "dynamic_range", PROPERTY_HINT_RANGE, "0,8,0.01"), "set_dynamic_range", "get_dynamic_range");
  188. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "energy", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_energy", "get_energy");
  189. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bias", PROPERTY_HINT_RANGE, "0,8,0.01"), "set_bias", "get_bias");
  190. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "normal_bias", PROPERTY_HINT_RANGE, "0,8,0.01"), "set_normal_bias", "get_normal_bias");
  191. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "propagation", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_propagation", "get_propagation");
  192. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_two_bounces"), "set_use_two_bounces", "is_using_two_bounces");
  193. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interior"), "set_interior", "is_interior");
  194. }
  195. VoxelGIData::VoxelGIData() {
  196. probe = RS::get_singleton()->voxel_gi_create();
  197. }
  198. VoxelGIData::~VoxelGIData() {
  199. RS::get_singleton()->free(probe);
  200. }
  201. //////////////////////
  202. //////////////////////
  203. void VoxelGI::set_probe_data(const Ref<VoxelGIData> &p_data) {
  204. if (p_data.is_valid()) {
  205. RS::get_singleton()->instance_set_base(get_instance(), p_data->get_rid());
  206. } else {
  207. RS::get_singleton()->instance_set_base(get_instance(), RID());
  208. }
  209. probe_data = p_data;
  210. }
  211. Ref<VoxelGIData> VoxelGI::get_probe_data() const {
  212. return probe_data;
  213. }
  214. void VoxelGI::set_subdiv(Subdiv p_subdiv) {
  215. ERR_FAIL_INDEX(p_subdiv, SUBDIV_MAX);
  216. subdiv = p_subdiv;
  217. update_gizmos();
  218. }
  219. VoxelGI::Subdiv VoxelGI::get_subdiv() const {
  220. return subdiv;
  221. }
  222. void VoxelGI::set_extents(const Vector3 &p_extents) {
  223. extents = p_extents;
  224. update_gizmos();
  225. }
  226. Vector3 VoxelGI::get_extents() const {
  227. return extents;
  228. }
  229. void VoxelGI::_find_meshes(Node *p_at_node, List<PlotMesh> &plot_meshes) {
  230. MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_at_node);
  231. if (mi && mi->get_gi_mode() == GeometryInstance3D::GI_MODE_BAKED && mi->is_visible_in_tree()) {
  232. Ref<Mesh> mesh = mi->get_mesh();
  233. if (mesh.is_valid()) {
  234. AABB aabb = mesh->get_aabb();
  235. Transform3D xf = get_global_transform().affine_inverse() * mi->get_global_transform();
  236. if (AABB(-extents, extents * 2).intersects(xf.xform(aabb))) {
  237. PlotMesh pm;
  238. pm.local_xform = xf;
  239. pm.mesh = mesh;
  240. for (int i = 0; i < mesh->get_surface_count(); i++) {
  241. pm.instance_materials.push_back(mi->get_surface_override_material(i));
  242. }
  243. pm.override_material = mi->get_material_override();
  244. plot_meshes.push_back(pm);
  245. }
  246. }
  247. }
  248. Node3D *s = Object::cast_to<Node3D>(p_at_node);
  249. if (s) {
  250. if (s->is_visible_in_tree()) {
  251. Array meshes = p_at_node->call("get_meshes");
  252. for (int i = 0; i < meshes.size(); i += 2) {
  253. Transform3D mxf = meshes[i];
  254. Ref<Mesh> mesh = meshes[i + 1];
  255. if (!mesh.is_valid()) {
  256. continue;
  257. }
  258. AABB aabb = mesh->get_aabb();
  259. Transform3D xf = get_global_transform().affine_inverse() * (s->get_global_transform() * mxf);
  260. if (AABB(-extents, extents * 2).intersects(xf.xform(aabb))) {
  261. PlotMesh pm;
  262. pm.local_xform = xf;
  263. pm.mesh = mesh;
  264. plot_meshes.push_back(pm);
  265. }
  266. }
  267. }
  268. }
  269. for (int i = 0; i < p_at_node->get_child_count(); i++) {
  270. Node *child = p_at_node->get_child(i);
  271. _find_meshes(child, plot_meshes);
  272. }
  273. }
  274. VoxelGI::BakeBeginFunc VoxelGI::bake_begin_function = nullptr;
  275. VoxelGI::BakeStepFunc VoxelGI::bake_step_function = nullptr;
  276. VoxelGI::BakeEndFunc VoxelGI::bake_end_function = nullptr;
  277. Vector3i VoxelGI::get_estimated_cell_size() const {
  278. static const int subdiv_value[SUBDIV_MAX] = { 6, 7, 8, 9 };
  279. int cell_subdiv = subdiv_value[subdiv];
  280. int axis_cell_size[3];
  281. AABB bounds = AABB(-extents, extents * 2.0);
  282. int longest_axis = bounds.get_longest_axis_index();
  283. axis_cell_size[longest_axis] = 1 << cell_subdiv;
  284. for (int i = 0; i < 3; i++) {
  285. if (i == longest_axis) {
  286. continue;
  287. }
  288. axis_cell_size[i] = axis_cell_size[longest_axis];
  289. float axis_size = bounds.size[longest_axis];
  290. //shrink until fit subdiv
  291. while (axis_size / 2.0 >= bounds.size[i]) {
  292. axis_size /= 2.0;
  293. axis_cell_size[i] >>= 1;
  294. }
  295. }
  296. return Vector3i(axis_cell_size[0], axis_cell_size[1], axis_cell_size[2]);
  297. }
  298. void VoxelGI::bake(Node *p_from_node, bool p_create_visual_debug) {
  299. static const int subdiv_value[SUBDIV_MAX] = { 6, 7, 8, 9 };
  300. p_from_node = p_from_node ? p_from_node : get_parent();
  301. ERR_FAIL_NULL(p_from_node);
  302. Voxelizer baker;
  303. baker.begin_bake(subdiv_value[subdiv], AABB(-extents, extents * 2.0));
  304. List<PlotMesh> mesh_list;
  305. _find_meshes(p_from_node, mesh_list);
  306. if (bake_begin_function) {
  307. bake_begin_function(mesh_list.size() + 1);
  308. }
  309. int pmc = 0;
  310. for (PlotMesh &E : mesh_list) {
  311. if (bake_step_function) {
  312. bake_step_function(pmc, RTR("Plotting Meshes") + " " + itos(pmc) + "/" + itos(mesh_list.size()));
  313. }
  314. pmc++;
  315. baker.plot_mesh(E.local_xform, E.mesh, E.instance_materials, E.override_material);
  316. }
  317. if (bake_step_function) {
  318. bake_step_function(pmc++, RTR("Finishing Plot"));
  319. }
  320. baker.end_bake();
  321. //create the data for rendering server
  322. if (p_create_visual_debug) {
  323. MultiMeshInstance3D *mmi = memnew(MultiMeshInstance3D);
  324. mmi->set_multimesh(baker.create_debug_multimesh());
  325. add_child(mmi);
  326. #ifdef TOOLS_ENABLED
  327. if (is_inside_tree() && get_tree()->get_edited_scene_root() == this) {
  328. mmi->set_owner(this);
  329. } else {
  330. mmi->set_owner(get_owner());
  331. }
  332. #else
  333. mmi->set_owner(get_owner());
  334. #endif
  335. } else {
  336. Ref<VoxelGIData> probe_data = get_probe_data();
  337. if (probe_data.is_null()) {
  338. probe_data.instantiate();
  339. }
  340. if (bake_step_function) {
  341. bake_step_function(pmc++, RTR("Generating Distance Field"));
  342. }
  343. Vector<uint8_t> df = baker.get_sdf_3d_image();
  344. probe_data->allocate(baker.get_to_cell_space_xform(), AABB(-extents, extents * 2.0), baker.get_voxel_gi_octree_size(), baker.get_voxel_gi_octree_cells(), baker.get_voxel_gi_data_cells(), df, baker.get_voxel_gi_level_cell_count());
  345. set_probe_data(probe_data);
  346. #ifdef TOOLS_ENABLED
  347. probe_data->set_edited(true); //so it gets saved
  348. #endif
  349. }
  350. if (bake_end_function) {
  351. bake_end_function();
  352. }
  353. notify_property_list_changed(); //bake property may have changed
  354. }
  355. void VoxelGI::_debug_bake() {
  356. bake(nullptr, true);
  357. }
  358. AABB VoxelGI::get_aabb() const {
  359. return AABB(-extents, extents * 2);
  360. }
  361. Vector<Face3> VoxelGI::get_faces(uint32_t p_usage_flags) const {
  362. return Vector<Face3>();
  363. }
  364. TypedArray<String> VoxelGI::get_configuration_warnings() const {
  365. TypedArray<String> warnings = Node::get_configuration_warnings();
  366. if (RenderingServer::get_singleton()->is_low_end()) {
  367. warnings.push_back(TTR("VoxelGIs are not supported by the GLES2 video driver.\nUse a LightmapGI instead."));
  368. } else if (probe_data.is_null()) {
  369. warnings.push_back(TTR("No VoxelGI data set, so this node is disabled. Bake static objects to enable GI."));
  370. }
  371. return warnings;
  372. }
  373. void VoxelGI::_bind_methods() {
  374. ClassDB::bind_method(D_METHOD("set_probe_data", "data"), &VoxelGI::set_probe_data);
  375. ClassDB::bind_method(D_METHOD("get_probe_data"), &VoxelGI::get_probe_data);
  376. ClassDB::bind_method(D_METHOD("set_subdiv", "subdiv"), &VoxelGI::set_subdiv);
  377. ClassDB::bind_method(D_METHOD("get_subdiv"), &VoxelGI::get_subdiv);
  378. ClassDB::bind_method(D_METHOD("set_extents", "extents"), &VoxelGI::set_extents);
  379. ClassDB::bind_method(D_METHOD("get_extents"), &VoxelGI::get_extents);
  380. ClassDB::bind_method(D_METHOD("bake", "from_node", "create_visual_debug"), &VoxelGI::bake, DEFVAL(Variant()), DEFVAL(false));
  381. ClassDB::bind_method(D_METHOD("debug_bake"), &VoxelGI::_debug_bake);
  382. ClassDB::set_method_flags(get_class_static(), _scs_create("debug_bake"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR);
  383. ADD_PROPERTY(PropertyInfo(Variant::INT, "subdiv", PROPERTY_HINT_ENUM, "64,128,256,512"), "set_subdiv", "get_subdiv");
  384. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "extents"), "set_extents", "get_extents");
  385. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "VoxelGIData", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE), "set_probe_data", "get_probe_data");
  386. BIND_ENUM_CONSTANT(SUBDIV_64);
  387. BIND_ENUM_CONSTANT(SUBDIV_128);
  388. BIND_ENUM_CONSTANT(SUBDIV_256);
  389. BIND_ENUM_CONSTANT(SUBDIV_512);
  390. BIND_ENUM_CONSTANT(SUBDIV_MAX);
  391. }
  392. VoxelGI::VoxelGI() {
  393. voxel_gi = RS::get_singleton()->voxel_gi_create();
  394. set_disable_scale(true);
  395. }
  396. VoxelGI::~VoxelGI() {
  397. RS::get_singleton()->free(voxel_gi);
  398. }