baked_light.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. /*************************************************************************/
  2. /* baked_light.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 "baked_light.h"
  31. #include "servers/visual_server.h"
  32. void BakedLight::set_mode(Mode p_mode) {
  33. mode = p_mode;
  34. VS::get_singleton()->baked_light_set_mode(baked_light, (VS::BakedLightMode(p_mode)));
  35. }
  36. BakedLight::Mode BakedLight::get_mode() const {
  37. return mode;
  38. }
  39. void BakedLight::set_octree(const DVector<uint8_t> &p_octree) {
  40. VS::get_singleton()->baked_light_set_octree(baked_light, p_octree);
  41. }
  42. DVector<uint8_t> BakedLight::get_octree() const {
  43. return VS::get_singleton()->baked_light_get_octree(baked_light);
  44. }
  45. void BakedLight::set_light(const DVector<uint8_t> &p_light) {
  46. VS::get_singleton()->baked_light_set_light(baked_light, p_light);
  47. }
  48. DVector<uint8_t> BakedLight::get_light() const {
  49. return VS::get_singleton()->baked_light_get_light(baked_light);
  50. }
  51. void BakedLight::set_sampler_octree(const DVector<int> &p_sampler_octree) {
  52. VS::get_singleton()->baked_light_set_sampler_octree(baked_light, p_sampler_octree);
  53. }
  54. DVector<int> BakedLight::get_sampler_octree() const {
  55. return VS::get_singleton()->baked_light_get_sampler_octree(baked_light);
  56. }
  57. void BakedLight::add_lightmap(const Ref<Texture> &p_texture, Size2 p_gen_size) {
  58. LightMap lm;
  59. lm.texture = p_texture;
  60. lm.gen_size = p_gen_size;
  61. lightmaps.push_back(lm);
  62. _update_lightmaps();
  63. _change_notify();
  64. }
  65. void BakedLight::set_lightmap_gen_size(int p_idx, const Size2 &p_size) {
  66. ERR_FAIL_INDEX(p_idx, lightmaps.size());
  67. lightmaps[p_idx].gen_size = p_size;
  68. _update_lightmaps();
  69. }
  70. Size2 BakedLight::get_lightmap_gen_size(int p_idx) const {
  71. ERR_FAIL_INDEX_V(p_idx, lightmaps.size(), Size2());
  72. return lightmaps[p_idx].gen_size;
  73. }
  74. void BakedLight::set_lightmap_texture(int p_idx, const Ref<Texture> &p_texture) {
  75. ERR_FAIL_INDEX(p_idx, lightmaps.size());
  76. lightmaps[p_idx].texture = p_texture;
  77. _update_lightmaps();
  78. }
  79. Ref<Texture> BakedLight::get_lightmap_texture(int p_idx) const {
  80. ERR_FAIL_INDEX_V(p_idx, lightmaps.size(), Ref<Texture>());
  81. return lightmaps[p_idx].texture;
  82. }
  83. void BakedLight::erase_lightmap(int p_idx) {
  84. ERR_FAIL_INDEX(p_idx, lightmaps.size());
  85. lightmaps.remove(p_idx);
  86. _update_lightmaps();
  87. _change_notify();
  88. }
  89. int BakedLight::get_lightmaps_count() const {
  90. return lightmaps.size();
  91. }
  92. void BakedLight::clear_lightmaps() {
  93. lightmaps.clear();
  94. _update_lightmaps();
  95. _change_notify();
  96. }
  97. void BakedLight::_update_lightmaps() {
  98. VS::get_singleton()->baked_light_clear_lightmaps(baked_light);
  99. for (int i = 0; i < lightmaps.size(); i++) {
  100. RID tid;
  101. if (lightmaps[i].texture.is_valid())
  102. tid = lightmaps[i].texture->get_rid();
  103. VS::get_singleton()->baked_light_add_lightmap(baked_light, tid, i);
  104. }
  105. }
  106. RID BakedLight::get_rid() const {
  107. return baked_light;
  108. }
  109. Array BakedLight::_get_lightmap_data() const {
  110. Array ret;
  111. ret.resize(lightmaps.size() * 2);
  112. int idx = 0;
  113. for (int i = 0; i < lightmaps.size(); i++) {
  114. ret[idx++] = Size2(lightmaps[i].gen_size);
  115. ret[idx++] = lightmaps[i].texture;
  116. }
  117. return ret;
  118. }
  119. void BakedLight::_set_lightmap_data(Array p_array) {
  120. lightmaps.clear();
  121. for (int i = 0; i < p_array.size(); i += 2) {
  122. Size2 size = p_array[i];
  123. Ref<Texture> tex = p_array[i + 1];
  124. // ERR_CONTINUE(tex.is_null());
  125. LightMap lm;
  126. lm.gen_size = size;
  127. lm.texture = tex;
  128. lightmaps.push_back(lm);
  129. }
  130. _update_lightmaps();
  131. }
  132. void BakedLight::set_cell_subdivision(int p_subdiv) {
  133. cell_subdiv = p_subdiv;
  134. }
  135. int BakedLight::get_cell_subdivision() const {
  136. return cell_subdiv;
  137. }
  138. void BakedLight::set_initial_lattice_subdiv(int p_size) {
  139. lattice_subdiv = p_size;
  140. }
  141. int BakedLight::get_initial_lattice_subdiv() const {
  142. return lattice_subdiv;
  143. }
  144. void BakedLight::set_plot_size(float p_size) {
  145. plot_size = p_size;
  146. }
  147. float BakedLight::get_plot_size() const {
  148. return plot_size;
  149. }
  150. void BakedLight::set_bounces(int p_size) {
  151. bounces = p_size;
  152. }
  153. int BakedLight::get_bounces() const {
  154. return bounces;
  155. }
  156. void BakedLight::set_cell_extra_margin(float p_margin) {
  157. cell_extra_margin = p_margin;
  158. }
  159. float BakedLight::get_cell_extra_margin() const {
  160. return cell_extra_margin;
  161. }
  162. void BakedLight::set_edge_damp(float p_margin) {
  163. edge_damp = p_margin;
  164. }
  165. float BakedLight::get_edge_damp() const {
  166. return edge_damp;
  167. }
  168. void BakedLight::set_normal_damp(float p_margin) {
  169. normal_damp = p_margin;
  170. }
  171. float BakedLight::get_normal_damp() const {
  172. return normal_damp;
  173. }
  174. void BakedLight::set_tint(float p_margin) {
  175. tint = p_margin;
  176. }
  177. float BakedLight::get_tint() const {
  178. return tint;
  179. }
  180. void BakedLight::set_saturation(float p_margin) {
  181. saturation = p_margin;
  182. }
  183. float BakedLight::get_saturation() const {
  184. return saturation;
  185. }
  186. void BakedLight::set_ao_radius(float p_ao_radius) {
  187. ao_radius = p_ao_radius;
  188. }
  189. float BakedLight::get_ao_radius() const {
  190. return ao_radius;
  191. }
  192. void BakedLight::set_ao_strength(float p_ao_strength) {
  193. ao_strength = p_ao_strength;
  194. }
  195. float BakedLight::get_ao_strength() const {
  196. return ao_strength;
  197. }
  198. void BakedLight::set_realtime_color_enabled(const bool p_realtime_color_enabled) {
  199. VS::get_singleton()->baked_light_set_realtime_color_enabled(baked_light, p_realtime_color_enabled);
  200. }
  201. bool BakedLight::get_realtime_color_enabled() const {
  202. return VS::get_singleton()->baked_light_get_realtime_color_enabled(baked_light);
  203. }
  204. void BakedLight::set_realtime_color(const Color &p_realtime_color) {
  205. VS::get_singleton()->baked_light_set_realtime_color(baked_light, p_realtime_color);
  206. }
  207. Color BakedLight::get_realtime_color() const {
  208. return VS::get_singleton()->baked_light_get_realtime_color(baked_light);
  209. }
  210. void BakedLight::set_realtime_energy(const float p_realtime_energy) {
  211. VS::get_singleton()->baked_light_set_realtime_energy(baked_light, p_realtime_energy);
  212. }
  213. float BakedLight::get_realtime_energy() const {
  214. return VS::get_singleton()->baked_light_get_realtime_energy(baked_light);
  215. }
  216. void BakedLight::set_energy_multiplier(float p_multiplier) {
  217. energy_multiply = p_multiplier;
  218. }
  219. float BakedLight::get_energy_multiplier() const {
  220. return energy_multiply;
  221. }
  222. void BakedLight::set_gamma_adjust(float p_adjust) {
  223. gamma_adjust = p_adjust;
  224. }
  225. float BakedLight::get_gamma_adjust() const {
  226. return gamma_adjust;
  227. }
  228. void BakedLight::set_bake_flag(BakeFlags p_flags, bool p_enable) {
  229. flags[p_flags] = p_enable;
  230. }
  231. bool BakedLight::get_bake_flag(BakeFlags p_flags) const {
  232. return flags[p_flags];
  233. }
  234. void BakedLight::set_format(Format p_format) {
  235. format = p_format;
  236. VS::get_singleton()->baked_light_set_lightmap_multiplier(baked_light, format == FORMAT_HDR8 ? 8.0 : 1.0);
  237. }
  238. BakedLight::Format BakedLight::get_format() const {
  239. return format;
  240. }
  241. void BakedLight::set_transfer_lightmaps_only_to_uv2(bool p_enable) {
  242. transfer_only_uv2 = p_enable;
  243. }
  244. bool BakedLight::get_transfer_lightmaps_only_to_uv2() const {
  245. return transfer_only_uv2;
  246. }
  247. bool BakedLight::_set(const StringName &p_name, const Variant &p_value) {
  248. String n = p_name;
  249. if (!n.begins_with("lightmap"))
  250. return false;
  251. int idx = n.get_slicec('/', 1).to_int();
  252. ERR_FAIL_COND_V(idx < 0, false);
  253. ERR_FAIL_COND_V(idx > lightmaps.size(), false);
  254. String what = n.get_slicec('/', 2);
  255. Ref<Texture> tex;
  256. Size2 gens;
  257. if (what == "texture")
  258. tex = p_value;
  259. else if (what == "gen_size")
  260. gens = p_value;
  261. if (idx == lightmaps.size()) {
  262. if (tex.is_valid() || gens != Size2())
  263. add_lightmap(tex, gens);
  264. } else {
  265. if (tex.is_valid())
  266. set_lightmap_texture(idx, tex);
  267. else if (gens != Size2())
  268. set_lightmap_gen_size(idx, gens);
  269. }
  270. return true;
  271. }
  272. bool BakedLight::_get(const StringName &p_name, Variant &r_ret) const {
  273. String n = p_name;
  274. if (!n.begins_with("lightmap"))
  275. return false;
  276. int idx = n.get_slicec('/', 1).to_int();
  277. ERR_FAIL_COND_V(idx < 0, false);
  278. ERR_FAIL_COND_V(idx > lightmaps.size(), false);
  279. String what = n.get_slicec('/', 2);
  280. if (what == "texture") {
  281. if (idx == lightmaps.size())
  282. r_ret = Ref<Texture>();
  283. else
  284. r_ret = lightmaps[idx].texture;
  285. } else if (what == "gen_size") {
  286. if (idx == lightmaps.size())
  287. r_ret = Size2();
  288. else
  289. r_ret = Size2(lightmaps[idx].gen_size);
  290. } else
  291. return false;
  292. return true;
  293. }
  294. void BakedLight::_get_property_list(List<PropertyInfo> *p_list) const {
  295. for (int i = 0; i <= lightmaps.size(); i++) {
  296. p_list->push_back(PropertyInfo(Variant::VECTOR2, "lightmaps/" + itos(i) + "/gen_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR));
  297. p_list->push_back(PropertyInfo(Variant::OBJECT, "lightmaps/" + itos(i) + "/texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture", PROPERTY_USAGE_EDITOR));
  298. }
  299. }
  300. void BakedLight::_bind_methods() {
  301. ObjectTypeDB::bind_method(_MD("set_mode", "mode"), &BakedLight::set_mode);
  302. ObjectTypeDB::bind_method(_MD("get_mode"), &BakedLight::get_mode);
  303. ObjectTypeDB::bind_method(_MD("set_octree", "octree"), &BakedLight::set_octree);
  304. ObjectTypeDB::bind_method(_MD("get_octree"), &BakedLight::get_octree);
  305. ObjectTypeDB::bind_method(_MD("set_light", "light"), &BakedLight::set_light);
  306. ObjectTypeDB::bind_method(_MD("get_light"), &BakedLight::get_light);
  307. ObjectTypeDB::bind_method(_MD("set_sampler_octree", "sampler_octree"), &BakedLight::set_sampler_octree);
  308. ObjectTypeDB::bind_method(_MD("get_sampler_octree"), &BakedLight::get_sampler_octree);
  309. ObjectTypeDB::bind_method(_MD("add_lightmap", "texture:Texture", "gen_size"), &BakedLight::add_lightmap);
  310. ObjectTypeDB::bind_method(_MD("erase_lightmap", "id"), &BakedLight::erase_lightmap);
  311. ObjectTypeDB::bind_method(_MD("clear_lightmaps"), &BakedLight::clear_lightmaps);
  312. ObjectTypeDB::bind_method(_MD("_set_lightmap_data", "lightmap_data"), &BakedLight::_set_lightmap_data);
  313. ObjectTypeDB::bind_method(_MD("_get_lightmap_data"), &BakedLight::_get_lightmap_data);
  314. ObjectTypeDB::bind_method(_MD("set_cell_subdivision", "cell_subdivision"), &BakedLight::set_cell_subdivision);
  315. ObjectTypeDB::bind_method(_MD("get_cell_subdivision"), &BakedLight::get_cell_subdivision);
  316. ObjectTypeDB::bind_method(_MD("set_initial_lattice_subdiv", "cell_subdivision"), &BakedLight::set_initial_lattice_subdiv);
  317. ObjectTypeDB::bind_method(_MD("get_initial_lattice_subdiv", "cell_subdivision"), &BakedLight::get_initial_lattice_subdiv);
  318. ObjectTypeDB::bind_method(_MD("set_plot_size", "plot_size"), &BakedLight::set_plot_size);
  319. ObjectTypeDB::bind_method(_MD("get_plot_size"), &BakedLight::get_plot_size);
  320. ObjectTypeDB::bind_method(_MD("set_bounces", "bounces"), &BakedLight::set_bounces);
  321. ObjectTypeDB::bind_method(_MD("get_bounces"), &BakedLight::get_bounces);
  322. ObjectTypeDB::bind_method(_MD("set_cell_extra_margin", "cell_extra_margin"), &BakedLight::set_cell_extra_margin);
  323. ObjectTypeDB::bind_method(_MD("get_cell_extra_margin"), &BakedLight::get_cell_extra_margin);
  324. ObjectTypeDB::bind_method(_MD("set_edge_damp", "edge_damp"), &BakedLight::set_edge_damp);
  325. ObjectTypeDB::bind_method(_MD("get_edge_damp"), &BakedLight::get_edge_damp);
  326. ObjectTypeDB::bind_method(_MD("set_normal_damp", "normal_damp"), &BakedLight::set_normal_damp);
  327. ObjectTypeDB::bind_method(_MD("get_normal_damp"), &BakedLight::get_normal_damp);
  328. ObjectTypeDB::bind_method(_MD("set_tint", "tint"), &BakedLight::set_tint);
  329. ObjectTypeDB::bind_method(_MD("get_tint"), &BakedLight::get_tint);
  330. ObjectTypeDB::bind_method(_MD("set_saturation", "saturation"), &BakedLight::set_saturation);
  331. ObjectTypeDB::bind_method(_MD("get_saturation"), &BakedLight::get_saturation);
  332. ObjectTypeDB::bind_method(_MD("set_ao_radius", "ao_radius"), &BakedLight::set_ao_radius);
  333. ObjectTypeDB::bind_method(_MD("get_ao_radius"), &BakedLight::get_ao_radius);
  334. ObjectTypeDB::bind_method(_MD("set_ao_strength", "ao_strength"), &BakedLight::set_ao_strength);
  335. ObjectTypeDB::bind_method(_MD("get_ao_strength"), &BakedLight::get_ao_strength);
  336. ObjectTypeDB::bind_method(_MD("set_realtime_color_enabled", "enabled"), &BakedLight::set_realtime_color_enabled);
  337. ObjectTypeDB::bind_method(_MD("get_realtime_color_enabled"), &BakedLight::get_realtime_color_enabled);
  338. ObjectTypeDB::bind_method(_MD("set_realtime_color", "tint"), &BakedLight::set_realtime_color);
  339. ObjectTypeDB::bind_method(_MD("get_realtime_color"), &BakedLight::get_realtime_color);
  340. ObjectTypeDB::bind_method(_MD("set_realtime_energy", "energy"), &BakedLight::set_realtime_energy);
  341. ObjectTypeDB::bind_method(_MD("get_realtime_energy"), &BakedLight::get_realtime_energy);
  342. ObjectTypeDB::bind_method(_MD("set_format", "format"), &BakedLight::set_format);
  343. ObjectTypeDB::bind_method(_MD("get_format"), &BakedLight::get_format);
  344. ObjectTypeDB::bind_method(_MD("set_transfer_lightmaps_only_to_uv2", "enable"), &BakedLight::set_transfer_lightmaps_only_to_uv2);
  345. ObjectTypeDB::bind_method(_MD("get_transfer_lightmaps_only_to_uv2"), &BakedLight::get_transfer_lightmaps_only_to_uv2);
  346. ObjectTypeDB::bind_method(_MD("set_energy_multiplier", "energy_multiplier"), &BakedLight::set_energy_multiplier);
  347. ObjectTypeDB::bind_method(_MD("get_energy_multiplier"), &BakedLight::get_energy_multiplier);
  348. ObjectTypeDB::bind_method(_MD("set_gamma_adjust", "gamma_adjust"), &BakedLight::set_gamma_adjust);
  349. ObjectTypeDB::bind_method(_MD("get_gamma_adjust"), &BakedLight::get_gamma_adjust);
  350. ObjectTypeDB::bind_method(_MD("set_bake_flag", "flag", "enabled"), &BakedLight::set_bake_flag);
  351. ObjectTypeDB::bind_method(_MD("get_bake_flag", "flag"), &BakedLight::get_bake_flag);
  352. ADD_PROPERTY(PropertyInfo(Variant::INT, "mode/mode", PROPERTY_HINT_ENUM, "Octree,Lightmaps"), _SCS("set_mode"), _SCS("get_mode"));
  353. ADD_PROPERTY(PropertyInfo(Variant::INT, "baking/format", PROPERTY_HINT_ENUM, "RGB,HDR8,HDR16"), _SCS("set_format"), _SCS("get_format"));
  354. ADD_PROPERTY(PropertyInfo(Variant::INT, "baking/cell_subdiv", PROPERTY_HINT_RANGE, "4,14,1"), _SCS("set_cell_subdivision"), _SCS("get_cell_subdivision"));
  355. ADD_PROPERTY(PropertyInfo(Variant::INT, "baking/lattice_subdiv", PROPERTY_HINT_RANGE, "1,5,1"), _SCS("set_initial_lattice_subdiv"), _SCS("get_initial_lattice_subdiv"));
  356. ADD_PROPERTY(PropertyInfo(Variant::INT, "baking/light_bounces", PROPERTY_HINT_RANGE, "0,3,1"), _SCS("set_bounces"), _SCS("get_bounces"));
  357. ADD_PROPERTY(PropertyInfo(Variant::REAL, "baking/plot_size", PROPERTY_HINT_RANGE, "1.0,16.0,0.01"), _SCS("set_plot_size"), _SCS("get_plot_size"));
  358. ADD_PROPERTY(PropertyInfo(Variant::REAL, "baking/energy_mult", PROPERTY_HINT_RANGE, "0.01,4096.0,0.01"), _SCS("set_energy_multiplier"), _SCS("get_energy_multiplier"));
  359. ADD_PROPERTY(PropertyInfo(Variant::REAL, "baking/gamma_adjust", PROPERTY_HINT_EXP_EASING), _SCS("set_gamma_adjust"), _SCS("get_gamma_adjust"));
  360. ADD_PROPERTY(PropertyInfo(Variant::REAL, "baking/saturation", PROPERTY_HINT_RANGE, "0,8,0.01"), _SCS("set_saturation"), _SCS("get_saturation"));
  361. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "baking_flags/diffuse"), _SCS("set_bake_flag"), _SCS("get_bake_flag"), BAKE_DIFFUSE);
  362. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "baking_flags/specular"), _SCS("set_bake_flag"), _SCS("get_bake_flag"), BAKE_SPECULAR);
  363. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "baking_flags/translucent"), _SCS("set_bake_flag"), _SCS("get_bake_flag"), BAKE_TRANSLUCENT);
  364. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "baking_flags/conserve_energy"), _SCS("set_bake_flag"), _SCS("get_bake_flag"), BAKE_CONSERVE_ENERGY);
  365. ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "baking_flags/linear_color"), _SCS("set_bake_flag"), _SCS("get_bake_flag"), BAKE_LINEAR_COLOR);
  366. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "lightmap/use_only_uv2"), _SCS("set_transfer_lightmaps_only_to_uv2"), _SCS("get_transfer_lightmaps_only_to_uv2"));
  367. ADD_PROPERTY(PropertyInfo(Variant::RAW_ARRAY, "octree", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), _SCS("set_octree"), _SCS("get_octree"));
  368. ADD_PROPERTY(PropertyInfo(Variant::RAW_ARRAY, "light", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), _SCS("set_light"), _SCS("get_light"));
  369. ADD_PROPERTY(PropertyInfo(Variant::INT_ARRAY, "sampler_octree", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), _SCS("set_sampler_octree"), _SCS("get_sampler_octree"));
  370. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "lightmaps", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), _SCS("_set_lightmap_data"), _SCS("_get_lightmap_data"));
  371. ADD_PROPERTY(PropertyInfo(Variant::REAL, "advanced/cell_margin", PROPERTY_HINT_RANGE, "0.01,0.8,0.01"), _SCS("set_cell_extra_margin"), _SCS("get_cell_extra_margin"));
  372. ADD_PROPERTY(PropertyInfo(Variant::REAL, "advanced/edge_damp", PROPERTY_HINT_RANGE, "0.0,8.0,0.1"), _SCS("set_edge_damp"), _SCS("get_edge_damp"));
  373. ADD_PROPERTY(PropertyInfo(Variant::REAL, "advanced/normal_damp", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), _SCS("set_normal_damp"), _SCS("get_normal_damp"));
  374. ADD_PROPERTY(PropertyInfo(Variant::REAL, "advanced/light_tint", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), _SCS("set_tint"), _SCS("get_tint"));
  375. ADD_PROPERTY(PropertyInfo(Variant::REAL, "advanced/ao_radius", PROPERTY_HINT_RANGE, "0.0,16.0,0.01"), _SCS("set_ao_radius"), _SCS("get_ao_radius"));
  376. ADD_PROPERTY(PropertyInfo(Variant::REAL, "advanced/ao_strength", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), _SCS("set_ao_strength"), _SCS("get_ao_strength"));
  377. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "realtime/enabled"), _SCS("set_realtime_color_enabled"), _SCS("get_realtime_color_enabled"));
  378. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "realtime/color", PROPERTY_HINT_COLOR_NO_ALPHA), _SCS("set_realtime_color"), _SCS("get_realtime_color"));
  379. ADD_PROPERTY(PropertyInfo(Variant::REAL, "realtime/energy", PROPERTY_HINT_RANGE, "0.01,4096.0,0.01"), _SCS("set_realtime_energy"), _SCS("get_realtime_energy"));
  380. BIND_CONSTANT(MODE_OCTREE);
  381. BIND_CONSTANT(MODE_LIGHTMAPS);
  382. BIND_CONSTANT(BAKE_DIFFUSE);
  383. BIND_CONSTANT(BAKE_SPECULAR);
  384. BIND_CONSTANT(BAKE_TRANSLUCENT);
  385. BIND_CONSTANT(BAKE_CONSERVE_ENERGY);
  386. BIND_CONSTANT(BAKE_MAX);
  387. }
  388. BakedLight::BakedLight() {
  389. cell_subdiv = 8;
  390. lattice_subdiv = 4;
  391. plot_size = 2.5;
  392. bounces = 1;
  393. energy_multiply = 2.0;
  394. gamma_adjust = 0.7;
  395. cell_extra_margin = 0.05;
  396. edge_damp = 0.0;
  397. normal_damp = 0.0;
  398. saturation = 1;
  399. tint = 0.0;
  400. ao_radius = 2.5;
  401. ao_strength = 0.7;
  402. format = FORMAT_RGB;
  403. transfer_only_uv2 = false;
  404. flags[BAKE_DIFFUSE] = true;
  405. flags[BAKE_SPECULAR] = false;
  406. flags[BAKE_TRANSLUCENT] = true;
  407. flags[BAKE_CONSERVE_ENERGY] = false;
  408. flags[BAKE_LINEAR_COLOR] = false;
  409. mode = MODE_OCTREE;
  410. baked_light = VS::get_singleton()->baked_light_create();
  411. }
  412. BakedLight::~BakedLight() {
  413. VS::get_singleton()->free(baked_light);
  414. }