gi_probe.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. /**************************************************************************/
  2. /* gi_probe.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 "gi_probe.h"
  31. #include "core/os/os.h"
  32. #include "mesh_instance.h"
  33. #include "voxel_light_baker.h"
  34. void GIProbeData::set_bounds(const AABB &p_bounds) {
  35. VS::get_singleton()->gi_probe_set_bounds(probe, p_bounds);
  36. }
  37. AABB GIProbeData::get_bounds() const {
  38. return VS::get_singleton()->gi_probe_get_bounds(probe);
  39. }
  40. void GIProbeData::set_cell_size(float p_size) {
  41. VS::get_singleton()->gi_probe_set_cell_size(probe, p_size);
  42. }
  43. float GIProbeData::get_cell_size() const {
  44. return VS::get_singleton()->gi_probe_get_cell_size(probe);
  45. }
  46. void GIProbeData::set_to_cell_xform(const Transform &p_xform) {
  47. VS::get_singleton()->gi_probe_set_to_cell_xform(probe, p_xform);
  48. }
  49. Transform GIProbeData::get_to_cell_xform() const {
  50. return VS::get_singleton()->gi_probe_get_to_cell_xform(probe);
  51. }
  52. void GIProbeData::set_dynamic_data(const PoolVector<int> &p_data) {
  53. VS::get_singleton()->gi_probe_set_dynamic_data(probe, p_data);
  54. }
  55. PoolVector<int> GIProbeData::get_dynamic_data() const {
  56. return VS::get_singleton()->gi_probe_get_dynamic_data(probe);
  57. }
  58. void GIProbeData::set_dynamic_range(int p_range) {
  59. VS::get_singleton()->gi_probe_set_dynamic_range(probe, p_range);
  60. }
  61. void GIProbeData::set_energy(float p_range) {
  62. VS::get_singleton()->gi_probe_set_energy(probe, p_range);
  63. }
  64. float GIProbeData::get_energy() const {
  65. return VS::get_singleton()->gi_probe_get_energy(probe);
  66. }
  67. void GIProbeData::set_bias(float p_range) {
  68. VS::get_singleton()->gi_probe_set_bias(probe, p_range);
  69. }
  70. float GIProbeData::get_bias() const {
  71. return VS::get_singleton()->gi_probe_get_bias(probe);
  72. }
  73. void GIProbeData::set_normal_bias(float p_range) {
  74. VS::get_singleton()->gi_probe_set_normal_bias(probe, p_range);
  75. }
  76. float GIProbeData::get_normal_bias() const {
  77. return VS::get_singleton()->gi_probe_get_normal_bias(probe);
  78. }
  79. void GIProbeData::set_propagation(float p_range) {
  80. VS::get_singleton()->gi_probe_set_propagation(probe, p_range);
  81. }
  82. float GIProbeData::get_propagation() const {
  83. return VS::get_singleton()->gi_probe_get_propagation(probe);
  84. }
  85. void GIProbeData::set_interior(bool p_enable) {
  86. VS::get_singleton()->gi_probe_set_interior(probe, p_enable);
  87. }
  88. bool GIProbeData::is_interior() const {
  89. return VS::get_singleton()->gi_probe_is_interior(probe);
  90. }
  91. bool GIProbeData::is_compressed() const {
  92. return VS::get_singleton()->gi_probe_is_compressed(probe);
  93. }
  94. void GIProbeData::set_compress(bool p_enable) {
  95. VS::get_singleton()->gi_probe_set_compress(probe, p_enable);
  96. }
  97. int GIProbeData::get_dynamic_range() const {
  98. return VS::get_singleton()->gi_probe_get_dynamic_range(probe);
  99. }
  100. RID GIProbeData::get_rid() const {
  101. return probe;
  102. }
  103. void GIProbeData::_bind_methods() {
  104. ClassDB::bind_method(D_METHOD("set_bounds", "bounds"), &GIProbeData::set_bounds);
  105. ClassDB::bind_method(D_METHOD("get_bounds"), &GIProbeData::get_bounds);
  106. ClassDB::bind_method(D_METHOD("set_cell_size", "cell_size"), &GIProbeData::set_cell_size);
  107. ClassDB::bind_method(D_METHOD("get_cell_size"), &GIProbeData::get_cell_size);
  108. ClassDB::bind_method(D_METHOD("set_to_cell_xform", "to_cell_xform"), &GIProbeData::set_to_cell_xform);
  109. ClassDB::bind_method(D_METHOD("get_to_cell_xform"), &GIProbeData::get_to_cell_xform);
  110. ClassDB::bind_method(D_METHOD("set_dynamic_data", "dynamic_data"), &GIProbeData::set_dynamic_data);
  111. ClassDB::bind_method(D_METHOD("get_dynamic_data"), &GIProbeData::get_dynamic_data);
  112. ClassDB::bind_method(D_METHOD("set_dynamic_range", "dynamic_range"), &GIProbeData::set_dynamic_range);
  113. ClassDB::bind_method(D_METHOD("get_dynamic_range"), &GIProbeData::get_dynamic_range);
  114. ClassDB::bind_method(D_METHOD("set_energy", "energy"), &GIProbeData::set_energy);
  115. ClassDB::bind_method(D_METHOD("get_energy"), &GIProbeData::get_energy);
  116. ClassDB::bind_method(D_METHOD("set_bias", "bias"), &GIProbeData::set_bias);
  117. ClassDB::bind_method(D_METHOD("get_bias"), &GIProbeData::get_bias);
  118. ClassDB::bind_method(D_METHOD("set_normal_bias", "bias"), &GIProbeData::set_normal_bias);
  119. ClassDB::bind_method(D_METHOD("get_normal_bias"), &GIProbeData::get_normal_bias);
  120. ClassDB::bind_method(D_METHOD("set_propagation", "propagation"), &GIProbeData::set_propagation);
  121. ClassDB::bind_method(D_METHOD("get_propagation"), &GIProbeData::get_propagation);
  122. ClassDB::bind_method(D_METHOD("set_interior", "interior"), &GIProbeData::set_interior);
  123. ClassDB::bind_method(D_METHOD("is_interior"), &GIProbeData::is_interior);
  124. ClassDB::bind_method(D_METHOD("set_compress", "compress"), &GIProbeData::set_compress);
  125. ClassDB::bind_method(D_METHOD("is_compressed"), &GIProbeData::is_compressed);
  126. ADD_PROPERTY(PropertyInfo(Variant::AABB, "bounds", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_bounds", "get_bounds");
  127. ADD_PROPERTY(PropertyInfo(Variant::REAL, "cell_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_cell_size", "get_cell_size");
  128. ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "to_cell_xform", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_to_cell_xform", "get_to_cell_xform");
  129. ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "dynamic_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_dynamic_data", "get_dynamic_data");
  130. ADD_PROPERTY(PropertyInfo(Variant::INT, "dynamic_range", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_dynamic_range", "get_dynamic_range");
  131. ADD_PROPERTY(PropertyInfo(Variant::REAL, "energy", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_energy", "get_energy");
  132. ADD_PROPERTY(PropertyInfo(Variant::REAL, "bias", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_bias", "get_bias");
  133. ADD_PROPERTY(PropertyInfo(Variant::REAL, "normal_bias", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_normal_bias", "get_normal_bias");
  134. ADD_PROPERTY(PropertyInfo(Variant::REAL, "propagation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_propagation", "get_propagation");
  135. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interior", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_interior", "is_interior");
  136. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "compress", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_compress", "is_compressed");
  137. }
  138. GIProbeData::GIProbeData() {
  139. probe = RID_PRIME(VS::get_singleton()->gi_probe_create());
  140. }
  141. GIProbeData::~GIProbeData() {
  142. if (probe.is_valid()) {
  143. VS::get_singleton()->free(probe);
  144. }
  145. }
  146. //////////////////////
  147. //////////////////////
  148. void GIProbe::set_probe_data(const Ref<GIProbeData> &p_data) {
  149. if (p_data.is_valid()) {
  150. VS::get_singleton()->instance_set_base(get_instance(), p_data->get_rid());
  151. } else {
  152. VS::get_singleton()->instance_set_base(get_instance(), RID());
  153. }
  154. probe_data = p_data;
  155. }
  156. Ref<GIProbeData> GIProbe::get_probe_data() const {
  157. return probe_data;
  158. }
  159. void GIProbe::set_subdiv(Subdiv p_subdiv) {
  160. ERR_FAIL_INDEX(p_subdiv, SUBDIV_MAX);
  161. subdiv = p_subdiv;
  162. update_gizmo();
  163. }
  164. GIProbe::Subdiv GIProbe::get_subdiv() const {
  165. return subdiv;
  166. }
  167. void GIProbe::set_extents(const Vector3 &p_extents) {
  168. extents = p_extents;
  169. update_gizmo();
  170. _change_notify("extents");
  171. }
  172. Vector3 GIProbe::get_extents() const {
  173. return extents;
  174. }
  175. void GIProbe::set_dynamic_range(int p_dynamic_range) {
  176. dynamic_range = p_dynamic_range;
  177. }
  178. int GIProbe::get_dynamic_range() const {
  179. return dynamic_range;
  180. }
  181. void GIProbe::set_energy(float p_energy) {
  182. energy = p_energy;
  183. if (probe_data.is_valid()) {
  184. probe_data->set_energy(energy);
  185. }
  186. }
  187. float GIProbe::get_energy() const {
  188. return energy;
  189. }
  190. void GIProbe::set_bias(float p_bias) {
  191. bias = p_bias;
  192. if (probe_data.is_valid()) {
  193. probe_data->set_bias(bias);
  194. }
  195. }
  196. float GIProbe::get_bias() const {
  197. return bias;
  198. }
  199. void GIProbe::set_normal_bias(float p_normal_bias) {
  200. normal_bias = p_normal_bias;
  201. if (probe_data.is_valid()) {
  202. probe_data->set_normal_bias(normal_bias);
  203. }
  204. }
  205. float GIProbe::get_normal_bias() const {
  206. return normal_bias;
  207. }
  208. void GIProbe::set_propagation(float p_propagation) {
  209. propagation = p_propagation;
  210. if (probe_data.is_valid()) {
  211. probe_data->set_propagation(propagation);
  212. }
  213. }
  214. float GIProbe::get_propagation() const {
  215. return propagation;
  216. }
  217. void GIProbe::set_interior(bool p_enable) {
  218. interior = p_enable;
  219. if (probe_data.is_valid()) {
  220. probe_data->set_interior(p_enable);
  221. }
  222. }
  223. bool GIProbe::is_interior() const {
  224. return interior;
  225. }
  226. void GIProbe::set_compress(bool p_enable) {
  227. compress = p_enable;
  228. if (probe_data.is_valid()) {
  229. probe_data->set_compress(p_enable);
  230. }
  231. update_configuration_warning();
  232. }
  233. bool GIProbe::is_compressed() const {
  234. return compress;
  235. }
  236. void GIProbe::_find_meshes(Node *p_at_node, List<PlotMesh> &plot_meshes) {
  237. MeshInstance *mi = Object::cast_to<MeshInstance>(p_at_node);
  238. if (mi && mi->get_flag(GeometryInstance::FLAG_USE_BAKED_LIGHT) && mi->is_visible_in_tree()) {
  239. Ref<Mesh> mesh = mi->get_mesh();
  240. if (mesh.is_valid()) {
  241. AABB aabb = mesh->get_aabb();
  242. Transform xf = get_global_transform().affine_inverse() * mi->get_global_transform();
  243. if (AABB(-extents, extents * 2).intersects(xf.xform(aabb))) {
  244. PlotMesh pm;
  245. pm.local_xform = xf;
  246. pm.mesh = mesh;
  247. for (int i = 0; i < mesh->get_surface_count(); i++) {
  248. pm.instance_materials.push_back(mi->get_surface_material(i));
  249. }
  250. pm.override_material = mi->get_material_override();
  251. plot_meshes.push_back(pm);
  252. }
  253. }
  254. }
  255. Spatial *s = Object::cast_to<Spatial>(p_at_node);
  256. if (s) {
  257. if (s->is_visible_in_tree()) {
  258. Array meshes = p_at_node->call("get_meshes");
  259. for (int i = 0; i < meshes.size(); i += 2) {
  260. Transform mxf = meshes[i];
  261. Ref<Mesh> mesh = meshes[i + 1];
  262. if (!mesh.is_valid()) {
  263. continue;
  264. }
  265. AABB aabb = mesh->get_aabb();
  266. Transform xf = get_global_transform().affine_inverse() * (s->get_global_transform() * mxf);
  267. if (AABB(-extents, extents * 2).intersects(xf.xform(aabb))) {
  268. PlotMesh pm;
  269. pm.local_xform = xf;
  270. pm.mesh = mesh;
  271. plot_meshes.push_back(pm);
  272. }
  273. }
  274. }
  275. }
  276. for (int i = 0; i < p_at_node->get_child_count(); i++) {
  277. Node *child = p_at_node->get_child(i);
  278. _find_meshes(child, plot_meshes);
  279. }
  280. }
  281. GIProbe::BakeBeginFunc GIProbe::bake_begin_function = nullptr;
  282. GIProbe::BakeStepFunc GIProbe::bake_step_function = nullptr;
  283. GIProbe::BakeEndFunc GIProbe::bake_end_function = nullptr;
  284. void GIProbe::bake(Node *p_from_node, bool p_create_visual_debug) {
  285. static const int subdiv_value[SUBDIV_MAX] = { 7, 8, 9, 10 };
  286. p_from_node = p_from_node ? p_from_node : get_parent();
  287. ERR_FAIL_NULL(p_from_node);
  288. VoxelLightBaker baker;
  289. baker.begin_bake(subdiv_value[subdiv], AABB(-extents, extents * 2.0));
  290. List<PlotMesh> mesh_list;
  291. _find_meshes(p_from_node, mesh_list);
  292. if (bake_begin_function) {
  293. bake_begin_function(mesh_list.size() + 1);
  294. }
  295. int pmc = 0;
  296. for (List<PlotMesh>::Element *E = mesh_list.front(); E; E = E->next()) {
  297. if (bake_step_function) {
  298. bake_step_function(pmc, RTR("Plotting Meshes") + " " + itos(pmc) + "/" + itos(mesh_list.size()));
  299. }
  300. pmc++;
  301. baker.plot_mesh(E->get().local_xform, E->get().mesh, E->get().instance_materials, E->get().override_material);
  302. }
  303. if (bake_step_function) {
  304. bake_step_function(pmc++, RTR("Finishing Plot"));
  305. }
  306. baker.end_bake();
  307. //create the data for visual server
  308. PoolVector<int> data = baker.create_gi_probe_data();
  309. if (p_create_visual_debug) {
  310. MultiMeshInstance *mmi = memnew(MultiMeshInstance);
  311. mmi->set_multimesh(baker.create_debug_multimesh());
  312. add_child(mmi);
  313. #ifdef TOOLS_ENABLED
  314. if (is_inside_tree() && get_tree()->get_edited_scene_root() == this) {
  315. mmi->set_owner(this);
  316. } else {
  317. mmi->set_owner(get_owner());
  318. }
  319. #else
  320. mmi->set_owner(get_owner());
  321. #endif
  322. } else {
  323. Ref<GIProbeData> probe_data = get_probe_data();
  324. if (probe_data.is_null()) {
  325. probe_data.instance();
  326. }
  327. probe_data->set_bounds(AABB(-extents, extents * 2.0));
  328. probe_data->set_cell_size(baker.get_cell_size());
  329. probe_data->set_dynamic_data(data);
  330. probe_data->set_dynamic_range(dynamic_range);
  331. probe_data->set_energy(energy);
  332. probe_data->set_bias(bias);
  333. probe_data->set_normal_bias(normal_bias);
  334. probe_data->set_propagation(propagation);
  335. probe_data->set_interior(interior);
  336. probe_data->set_compress(compress);
  337. probe_data->set_to_cell_xform(baker.get_to_cell_space_xform());
  338. set_probe_data(probe_data);
  339. }
  340. if (bake_end_function) {
  341. bake_end_function();
  342. }
  343. }
  344. void GIProbe::_debug_bake() {
  345. bake(nullptr, true);
  346. }
  347. AABB GIProbe::get_aabb() const {
  348. return AABB(-extents, extents * 2);
  349. }
  350. PoolVector<Face3> GIProbe::get_faces(uint32_t p_usage_flags) const {
  351. return PoolVector<Face3>();
  352. }
  353. String GIProbe::get_configuration_warning() const {
  354. String warning = VisualInstance::get_configuration_warning();
  355. if (OS::get_singleton()->get_current_video_driver() == OS::VIDEO_DRIVER_GLES2) {
  356. if (warning != String()) {
  357. warning += "\n\n";
  358. }
  359. warning += TTR("GIProbes are not supported by the GLES2 video driver.\nUse a BakedLightmap instead.");
  360. }
  361. if (is_compressed()) {
  362. if (warning != String()) {
  363. warning += "\n\n";
  364. }
  365. warning += TTR("The GIProbe Compress property has been deprecated due to known bugs and no longer has any effect.\nTo remove this warning, disable the GIProbe's Compress property.");
  366. }
  367. return warning;
  368. }
  369. void GIProbe::_bind_methods() {
  370. ClassDB::bind_method(D_METHOD("set_probe_data", "data"), &GIProbe::set_probe_data);
  371. ClassDB::bind_method(D_METHOD("get_probe_data"), &GIProbe::get_probe_data);
  372. ClassDB::bind_method(D_METHOD("set_subdiv", "subdiv"), &GIProbe::set_subdiv);
  373. ClassDB::bind_method(D_METHOD("get_subdiv"), &GIProbe::get_subdiv);
  374. ClassDB::bind_method(D_METHOD("set_extents", "extents"), &GIProbe::set_extents);
  375. ClassDB::bind_method(D_METHOD("get_extents"), &GIProbe::get_extents);
  376. ClassDB::bind_method(D_METHOD("set_dynamic_range", "max"), &GIProbe::set_dynamic_range);
  377. ClassDB::bind_method(D_METHOD("get_dynamic_range"), &GIProbe::get_dynamic_range);
  378. ClassDB::bind_method(D_METHOD("set_energy", "max"), &GIProbe::set_energy);
  379. ClassDB::bind_method(D_METHOD("get_energy"), &GIProbe::get_energy);
  380. ClassDB::bind_method(D_METHOD("set_bias", "max"), &GIProbe::set_bias);
  381. ClassDB::bind_method(D_METHOD("get_bias"), &GIProbe::get_bias);
  382. ClassDB::bind_method(D_METHOD("set_normal_bias", "max"), &GIProbe::set_normal_bias);
  383. ClassDB::bind_method(D_METHOD("get_normal_bias"), &GIProbe::get_normal_bias);
  384. ClassDB::bind_method(D_METHOD("set_propagation", "max"), &GIProbe::set_propagation);
  385. ClassDB::bind_method(D_METHOD("get_propagation"), &GIProbe::get_propagation);
  386. ClassDB::bind_method(D_METHOD("set_interior", "enable"), &GIProbe::set_interior);
  387. ClassDB::bind_method(D_METHOD("is_interior"), &GIProbe::is_interior);
  388. ClassDB::bind_method(D_METHOD("set_compress", "enable"), &GIProbe::set_compress);
  389. ClassDB::bind_method(D_METHOD("is_compressed"), &GIProbe::is_compressed);
  390. ClassDB::bind_method(D_METHOD("bake", "from_node", "create_visual_debug"), &GIProbe::bake, DEFVAL(Variant()), DEFVAL(false));
  391. ClassDB::bind_method(D_METHOD("debug_bake"), &GIProbe::_debug_bake);
  392. ClassDB::set_method_flags(get_class_static(), _scs_create("debug_bake"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR);
  393. ADD_PROPERTY(PropertyInfo(Variant::INT, "subdiv", PROPERTY_HINT_ENUM, "64,128,256,512"), "set_subdiv", "get_subdiv");
  394. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "extents"), "set_extents", "get_extents");
  395. ADD_PROPERTY(PropertyInfo(Variant::INT, "dynamic_range", PROPERTY_HINT_RANGE, "1,16,1"), "set_dynamic_range", "get_dynamic_range");
  396. ADD_PROPERTY(PropertyInfo(Variant::REAL, "energy", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_energy", "get_energy");
  397. ADD_PROPERTY(PropertyInfo(Variant::REAL, "propagation", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_propagation", "get_propagation");
  398. ADD_PROPERTY(PropertyInfo(Variant::REAL, "bias", PROPERTY_HINT_RANGE, "0,4,0.001"), "set_bias", "get_bias");
  399. ADD_PROPERTY(PropertyInfo(Variant::REAL, "normal_bias", PROPERTY_HINT_RANGE, "0,4,0.001"), "set_normal_bias", "get_normal_bias");
  400. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interior"), "set_interior", "is_interior");
  401. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "compress"), "set_compress", "is_compressed");
  402. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "data", PROPERTY_HINT_RESOURCE_TYPE, "GIProbeData", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE), "set_probe_data", "get_probe_data");
  403. BIND_ENUM_CONSTANT(SUBDIV_64);
  404. BIND_ENUM_CONSTANT(SUBDIV_128);
  405. BIND_ENUM_CONSTANT(SUBDIV_256);
  406. BIND_ENUM_CONSTANT(SUBDIV_512);
  407. BIND_ENUM_CONSTANT(SUBDIV_MAX);
  408. }
  409. GIProbe::GIProbe() {
  410. subdiv = SUBDIV_128;
  411. dynamic_range = 4;
  412. energy = 1.0;
  413. bias = 1.5;
  414. normal_bias = 0.0;
  415. propagation = 0.7;
  416. extents = Vector3(10, 10, 10);
  417. interior = false;
  418. compress = false;
  419. gi_probe = RID_PRIME(VS::get_singleton()->gi_probe_create());
  420. set_disable_scale(true);
  421. }
  422. GIProbe::~GIProbe() {
  423. if (gi_probe.is_valid()) {
  424. VS::get_singleton()->free(gi_probe);
  425. }
  426. }