sky_box.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. /*************************************************************************/
  2. /* sky_box.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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 "sky_box.h"
  31. #include "core/io/image_loader.h"
  32. void Sky::set_radiance_size(RadianceSize p_size) {
  33. ERR_FAIL_INDEX(p_size, RADIANCE_SIZE_MAX);
  34. radiance_size = p_size;
  35. _radiance_changed();
  36. }
  37. Sky::RadianceSize Sky::get_radiance_size() const {
  38. return radiance_size;
  39. }
  40. void Sky::_bind_methods() {
  41. ClassDB::bind_method(D_METHOD("set_radiance_size", "size"), &Sky::set_radiance_size);
  42. ClassDB::bind_method(D_METHOD("get_radiance_size"), &Sky::get_radiance_size);
  43. ADD_PROPERTY(PropertyInfo(Variant::INT, "radiance_size", PROPERTY_HINT_ENUM, "32,64,128,256,512,1024,2048"), "set_radiance_size", "get_radiance_size");
  44. BIND_ENUM_CONSTANT(RADIANCE_SIZE_32);
  45. BIND_ENUM_CONSTANT(RADIANCE_SIZE_64);
  46. BIND_ENUM_CONSTANT(RADIANCE_SIZE_128);
  47. BIND_ENUM_CONSTANT(RADIANCE_SIZE_256);
  48. BIND_ENUM_CONSTANT(RADIANCE_SIZE_512);
  49. BIND_ENUM_CONSTANT(RADIANCE_SIZE_1024);
  50. BIND_ENUM_CONSTANT(RADIANCE_SIZE_2048);
  51. BIND_ENUM_CONSTANT(RADIANCE_SIZE_MAX);
  52. }
  53. Sky::Sky() {
  54. radiance_size = RADIANCE_SIZE_512;
  55. }
  56. /////////////////////////////////////////
  57. void PanoramaSky::_radiance_changed() {
  58. if (panorama.is_valid()) {
  59. static const int size[RADIANCE_SIZE_MAX] = {
  60. 32, 64, 128, 256, 512, 1024, 2048
  61. };
  62. VS::get_singleton()->sky_set_texture(sky, panorama->get_rid(), size[get_radiance_size()]);
  63. }
  64. }
  65. void PanoramaSky::set_panorama(const Ref<Texture> &p_panorama) {
  66. panorama = p_panorama;
  67. if (panorama.is_valid()) {
  68. _radiance_changed();
  69. } else {
  70. VS::get_singleton()->sky_set_texture(sky, RID(), 0);
  71. }
  72. }
  73. Ref<Texture> PanoramaSky::get_panorama() const {
  74. return panorama;
  75. }
  76. RID PanoramaSky::get_rid() const {
  77. return sky;
  78. }
  79. void PanoramaSky::_bind_methods() {
  80. ClassDB::bind_method(D_METHOD("set_panorama", "texture"), &PanoramaSky::set_panorama);
  81. ClassDB::bind_method(D_METHOD("get_panorama"), &PanoramaSky::get_panorama);
  82. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "panorama", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_panorama", "get_panorama");
  83. }
  84. PanoramaSky::PanoramaSky() {
  85. sky = VS::get_singleton()->sky_create();
  86. }
  87. PanoramaSky::~PanoramaSky() {
  88. VS::get_singleton()->free(sky);
  89. }
  90. //////////////////////////////////
  91. void ProceduralSky::_radiance_changed() {
  92. if (update_queued)
  93. return; //do nothing yet
  94. static const int size[RADIANCE_SIZE_MAX] = {
  95. 32, 64, 128, 256, 512, 1024, 2048
  96. };
  97. VS::get_singleton()->sky_set_texture(sky, texture, size[get_radiance_size()]);
  98. }
  99. Ref<Image> ProceduralSky::_generate_sky() {
  100. update_queued = false;
  101. PoolVector<uint8_t> imgdata;
  102. static const int size[TEXTURE_SIZE_MAX] = {
  103. 256, 512, 1024, 2048, 4096
  104. };
  105. int w = size[texture_size];
  106. int h = w / 2;
  107. imgdata.resize(w * h * 4); //RGBE
  108. {
  109. PoolVector<uint8_t>::Write dataw = imgdata.write();
  110. uint32_t *ptr = (uint32_t *)dataw.ptr();
  111. Color sky_top_linear = sky_top_color.to_linear();
  112. Color sky_horizon_linear = sky_horizon_color.to_linear();
  113. Color ground_bottom_linear = ground_bottom_color.to_linear();
  114. Color ground_horizon_linear = ground_horizon_color.to_linear();
  115. //Color sun_linear = sun_color.to_linear();
  116. Vector3 sun(0, 0, -1);
  117. sun = Basis(Vector3(1, 0, 0), Math::deg2rad(sun_latitude)).xform(sun);
  118. sun = Basis(Vector3(0, 1, 0), Math::deg2rad(sun_longitude)).xform(sun);
  119. sun.normalize();
  120. for (int i = 0; i < w; i++) {
  121. float u = float(i) / (w - 1);
  122. float phi = u * 2.0 * Math_PI;
  123. for (int j = 0; j < h; j++) {
  124. float v = float(j) / (h - 1);
  125. float theta = v * Math_PI;
  126. Vector3 normal(
  127. Math::sin(phi) * Math::sin(theta) * -1.0,
  128. Math::cos(theta),
  129. Math::cos(phi) * Math::sin(theta) * -1.0);
  130. normal.normalize();
  131. float v_angle = Math::acos(CLAMP(normal.y, -1.0, 1.0));
  132. Color color;
  133. if (normal.y < 0) {
  134. //ground
  135. float c = (v_angle - (Math_PI * 0.5)) / (Math_PI * 0.5);
  136. color = ground_horizon_linear.linear_interpolate(ground_bottom_linear, Math::ease(c, ground_curve));
  137. color.r *= ground_energy;
  138. color.g *= ground_energy;
  139. color.b *= ground_energy;
  140. } else {
  141. float c = v_angle / (Math_PI * 0.5);
  142. color = sky_horizon_linear.linear_interpolate(sky_top_linear, Math::ease(1.0 - c, sky_curve));
  143. color.r *= sky_energy;
  144. color.g *= sky_energy;
  145. color.b *= sky_energy;
  146. float sun_angle = Math::rad2deg(Math::acos(CLAMP(sun.dot(normal), -1.0, 1.0)));
  147. if (sun_angle < sun_angle_min) {
  148. color = color.blend(sun_color);
  149. } else if (sun_angle < sun_angle_max) {
  150. float c2 = (sun_angle - sun_angle_min) / (sun_angle_max - sun_angle_min);
  151. c2 = Math::ease(c2, sun_curve);
  152. color = color.blend(sun_color).linear_interpolate(color, c2);
  153. }
  154. }
  155. ptr[j * w + i] = color.to_rgbe9995();
  156. }
  157. }
  158. }
  159. Ref<Image> image;
  160. image.instance();
  161. image->create(w, h, false, Image::FORMAT_RGBE9995, imgdata);
  162. return image;
  163. }
  164. void ProceduralSky::set_sky_top_color(const Color &p_sky_top) {
  165. sky_top_color = p_sky_top;
  166. _queue_update();
  167. }
  168. Color ProceduralSky::get_sky_top_color() const {
  169. return sky_top_color;
  170. }
  171. void ProceduralSky::set_sky_horizon_color(const Color &p_sky_horizon) {
  172. sky_horizon_color = p_sky_horizon;
  173. _queue_update();
  174. }
  175. Color ProceduralSky::get_sky_horizon_color() const {
  176. return sky_horizon_color;
  177. }
  178. void ProceduralSky::set_sky_curve(float p_curve) {
  179. sky_curve = p_curve;
  180. _queue_update();
  181. }
  182. float ProceduralSky::get_sky_curve() const {
  183. return sky_curve;
  184. }
  185. void ProceduralSky::set_sky_energy(float p_energy) {
  186. sky_energy = p_energy;
  187. _queue_update();
  188. }
  189. float ProceduralSky::get_sky_energy() const {
  190. return sky_energy;
  191. }
  192. void ProceduralSky::set_ground_bottom_color(const Color &p_ground_bottom) {
  193. ground_bottom_color = p_ground_bottom;
  194. _queue_update();
  195. }
  196. Color ProceduralSky::get_ground_bottom_color() const {
  197. return ground_bottom_color;
  198. }
  199. void ProceduralSky::set_ground_horizon_color(const Color &p_ground_horizon) {
  200. ground_horizon_color = p_ground_horizon;
  201. _queue_update();
  202. }
  203. Color ProceduralSky::get_ground_horizon_color() const {
  204. return ground_horizon_color;
  205. }
  206. void ProceduralSky::set_ground_curve(float p_curve) {
  207. ground_curve = p_curve;
  208. _queue_update();
  209. }
  210. float ProceduralSky::get_ground_curve() const {
  211. return ground_curve;
  212. }
  213. void ProceduralSky::set_ground_energy(float p_energy) {
  214. ground_energy = p_energy;
  215. _queue_update();
  216. }
  217. float ProceduralSky::get_ground_energy() const {
  218. return ground_energy;
  219. }
  220. void ProceduralSky::set_sun_color(const Color &p_sun) {
  221. sun_color = p_sun;
  222. _queue_update();
  223. }
  224. Color ProceduralSky::get_sun_color() const {
  225. return sun_color;
  226. }
  227. void ProceduralSky::set_sun_latitude(float p_angle) {
  228. sun_latitude = p_angle;
  229. _queue_update();
  230. }
  231. float ProceduralSky::get_sun_latitude() const {
  232. return sun_latitude;
  233. }
  234. void ProceduralSky::set_sun_longitude(float p_angle) {
  235. sun_longitude = p_angle;
  236. _queue_update();
  237. }
  238. float ProceduralSky::get_sun_longitude() const {
  239. return sun_longitude;
  240. }
  241. void ProceduralSky::set_sun_angle_min(float p_angle) {
  242. sun_angle_min = p_angle;
  243. _queue_update();
  244. }
  245. float ProceduralSky::get_sun_angle_min() const {
  246. return sun_angle_min;
  247. }
  248. void ProceduralSky::set_sun_angle_max(float p_angle) {
  249. sun_angle_max = p_angle;
  250. _queue_update();
  251. }
  252. float ProceduralSky::get_sun_angle_max() const {
  253. return sun_angle_max;
  254. }
  255. void ProceduralSky::set_sun_curve(float p_curve) {
  256. sun_curve = p_curve;
  257. _queue_update();
  258. }
  259. float ProceduralSky::get_sun_curve() const {
  260. return sun_curve;
  261. }
  262. void ProceduralSky::set_sun_energy(float p_energy) {
  263. sun_energy = p_energy;
  264. _queue_update();
  265. }
  266. float ProceduralSky::get_sun_energy() const {
  267. return sun_energy;
  268. }
  269. void ProceduralSky::set_texture_size(TextureSize p_size) {
  270. ERR_FAIL_INDEX(p_size, TEXTURE_SIZE_MAX);
  271. texture_size = p_size;
  272. _queue_update();
  273. }
  274. ProceduralSky::TextureSize ProceduralSky::get_texture_size() const {
  275. return texture_size;
  276. }
  277. RID ProceduralSky::get_rid() const {
  278. return sky;
  279. }
  280. void ProceduralSky::_update_sky() {
  281. bool use_thread = true;
  282. if (first_time) {
  283. use_thread = false;
  284. first_time = false;
  285. }
  286. #ifdef NO_THREADS
  287. use_thread = false;
  288. #endif
  289. if (use_thread) {
  290. if (!sky_thread) {
  291. sky_thread = Thread::create(_thread_function, this);
  292. regen_queued = false;
  293. } else {
  294. regen_queued = true;
  295. }
  296. } else {
  297. Ref<Image> image = _generate_sky();
  298. VS::get_singleton()->texture_allocate(texture, image->get_width(), image->get_height(), 0, Image::FORMAT_RGBE9995, VS::TEXTURE_TYPE_2D, VS::TEXTURE_FLAG_FILTER | VS::TEXTURE_FLAG_REPEAT);
  299. VS::get_singleton()->texture_set_data(texture, image);
  300. _radiance_changed();
  301. }
  302. }
  303. void ProceduralSky::_queue_update() {
  304. if (update_queued)
  305. return;
  306. update_queued = true;
  307. call_deferred("_update_sky");
  308. }
  309. void ProceduralSky::_thread_done(const Ref<Image> &p_image) {
  310. VS::get_singleton()->texture_allocate(texture, p_image->get_width(), p_image->get_height(), 0, Image::FORMAT_RGBE9995, VS::TEXTURE_TYPE_2D, VS::TEXTURE_FLAG_FILTER | VS::TEXTURE_FLAG_REPEAT);
  311. VS::get_singleton()->texture_set_data(texture, p_image);
  312. _radiance_changed();
  313. Thread::wait_to_finish(sky_thread);
  314. memdelete(sky_thread);
  315. sky_thread = NULL;
  316. if (regen_queued) {
  317. sky_thread = Thread::create(_thread_function, this);
  318. regen_queued = false;
  319. }
  320. }
  321. void ProceduralSky::_thread_function(void *p_ud) {
  322. ProceduralSky *psky = (ProceduralSky *)p_ud;
  323. psky->call_deferred("_thread_done", psky->_generate_sky());
  324. }
  325. void ProceduralSky::_bind_methods() {
  326. ClassDB::bind_method(D_METHOD("_update_sky"), &ProceduralSky::_update_sky);
  327. ClassDB::bind_method(D_METHOD("set_sky_top_color", "color"), &ProceduralSky::set_sky_top_color);
  328. ClassDB::bind_method(D_METHOD("get_sky_top_color"), &ProceduralSky::get_sky_top_color);
  329. ClassDB::bind_method(D_METHOD("set_sky_horizon_color", "color"), &ProceduralSky::set_sky_horizon_color);
  330. ClassDB::bind_method(D_METHOD("get_sky_horizon_color"), &ProceduralSky::get_sky_horizon_color);
  331. ClassDB::bind_method(D_METHOD("set_sky_curve", "curve"), &ProceduralSky::set_sky_curve);
  332. ClassDB::bind_method(D_METHOD("get_sky_curve"), &ProceduralSky::get_sky_curve);
  333. ClassDB::bind_method(D_METHOD("set_sky_energy", "energy"), &ProceduralSky::set_sky_energy);
  334. ClassDB::bind_method(D_METHOD("get_sky_energy"), &ProceduralSky::get_sky_energy);
  335. ClassDB::bind_method(D_METHOD("set_ground_bottom_color", "color"), &ProceduralSky::set_ground_bottom_color);
  336. ClassDB::bind_method(D_METHOD("get_ground_bottom_color"), &ProceduralSky::get_ground_bottom_color);
  337. ClassDB::bind_method(D_METHOD("set_ground_horizon_color", "color"), &ProceduralSky::set_ground_horizon_color);
  338. ClassDB::bind_method(D_METHOD("get_ground_horizon_color"), &ProceduralSky::get_ground_horizon_color);
  339. ClassDB::bind_method(D_METHOD("set_ground_curve", "curve"), &ProceduralSky::set_ground_curve);
  340. ClassDB::bind_method(D_METHOD("get_ground_curve"), &ProceduralSky::get_ground_curve);
  341. ClassDB::bind_method(D_METHOD("set_ground_energy", "energy"), &ProceduralSky::set_ground_energy);
  342. ClassDB::bind_method(D_METHOD("get_ground_energy"), &ProceduralSky::get_ground_energy);
  343. ClassDB::bind_method(D_METHOD("set_sun_color", "color"), &ProceduralSky::set_sun_color);
  344. ClassDB::bind_method(D_METHOD("get_sun_color"), &ProceduralSky::get_sun_color);
  345. ClassDB::bind_method(D_METHOD("set_sun_latitude", "degrees"), &ProceduralSky::set_sun_latitude);
  346. ClassDB::bind_method(D_METHOD("get_sun_latitude"), &ProceduralSky::get_sun_latitude);
  347. ClassDB::bind_method(D_METHOD("set_sun_longitude", "degrees"), &ProceduralSky::set_sun_longitude);
  348. ClassDB::bind_method(D_METHOD("get_sun_longitude"), &ProceduralSky::get_sun_longitude);
  349. ClassDB::bind_method(D_METHOD("set_sun_angle_min", "degrees"), &ProceduralSky::set_sun_angle_min);
  350. ClassDB::bind_method(D_METHOD("get_sun_angle_min"), &ProceduralSky::get_sun_angle_min);
  351. ClassDB::bind_method(D_METHOD("set_sun_angle_max", "degrees"), &ProceduralSky::set_sun_angle_max);
  352. ClassDB::bind_method(D_METHOD("get_sun_angle_max"), &ProceduralSky::get_sun_angle_max);
  353. ClassDB::bind_method(D_METHOD("set_sun_curve", "curve"), &ProceduralSky::set_sun_curve);
  354. ClassDB::bind_method(D_METHOD("get_sun_curve"), &ProceduralSky::get_sun_curve);
  355. ClassDB::bind_method(D_METHOD("set_sun_energy", "energy"), &ProceduralSky::set_sun_energy);
  356. ClassDB::bind_method(D_METHOD("get_sun_energy"), &ProceduralSky::get_sun_energy);
  357. ClassDB::bind_method(D_METHOD("set_texture_size", "size"), &ProceduralSky::set_texture_size);
  358. ClassDB::bind_method(D_METHOD("get_texture_size"), &ProceduralSky::get_texture_size);
  359. ClassDB::bind_method(D_METHOD("_thread_done", "image"), &ProceduralSky::_thread_done);
  360. ADD_GROUP("Sky", "sky_");
  361. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "sky_top_color"), "set_sky_top_color", "get_sky_top_color");
  362. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "sky_horizon_color"), "set_sky_horizon_color", "get_sky_horizon_color");
  363. ADD_PROPERTY(PropertyInfo(Variant::REAL, "sky_curve", PROPERTY_HINT_EXP_EASING), "set_sky_curve", "get_sky_curve");
  364. ADD_PROPERTY(PropertyInfo(Variant::REAL, "sky_energy", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_sky_energy", "get_sky_energy");
  365. ADD_GROUP("Ground", "ground_");
  366. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "ground_bottom_color"), "set_ground_bottom_color", "get_ground_bottom_color");
  367. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "ground_horizon_color"), "set_ground_horizon_color", "get_ground_horizon_color");
  368. ADD_PROPERTY(PropertyInfo(Variant::REAL, "ground_curve", PROPERTY_HINT_EXP_EASING), "set_ground_curve", "get_ground_curve");
  369. ADD_PROPERTY(PropertyInfo(Variant::REAL, "ground_energy", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_ground_energy", "get_ground_energy");
  370. ADD_GROUP("Sun", "sun_");
  371. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "sun_color"), "set_sun_color", "get_sun_color");
  372. ADD_PROPERTY(PropertyInfo(Variant::REAL, "sun_latitude", PROPERTY_HINT_RANGE, "-180,180,0.01"), "set_sun_latitude", "get_sun_latitude");
  373. ADD_PROPERTY(PropertyInfo(Variant::REAL, "sun_longitude", PROPERTY_HINT_RANGE, "-180,180,0.01"), "set_sun_longitude", "get_sun_longitude");
  374. ADD_PROPERTY(PropertyInfo(Variant::REAL, "sun_angle_min", PROPERTY_HINT_RANGE, "0,360,0.01"), "set_sun_angle_min", "get_sun_angle_min");
  375. ADD_PROPERTY(PropertyInfo(Variant::REAL, "sun_angle_max", PROPERTY_HINT_RANGE, "0,360,0.01"), "set_sun_angle_max", "get_sun_angle_max");
  376. ADD_PROPERTY(PropertyInfo(Variant::REAL, "sun_curve", PROPERTY_HINT_EXP_EASING), "set_sun_curve", "get_sun_curve");
  377. ADD_PROPERTY(PropertyInfo(Variant::REAL, "sun_energy", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_sun_energy", "get_sun_energy");
  378. ADD_GROUP("Texture", "texture_");
  379. ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_size", PROPERTY_HINT_ENUM, "256,512,1024,2048,4096"), "set_texture_size", "get_texture_size");
  380. BIND_ENUM_CONSTANT(TEXTURE_SIZE_256);
  381. BIND_ENUM_CONSTANT(TEXTURE_SIZE_512);
  382. BIND_ENUM_CONSTANT(TEXTURE_SIZE_1024);
  383. BIND_ENUM_CONSTANT(TEXTURE_SIZE_2048);
  384. BIND_ENUM_CONSTANT(TEXTURE_SIZE_4096);
  385. BIND_ENUM_CONSTANT(TEXTURE_SIZE_MAX);
  386. }
  387. ProceduralSky::ProceduralSky() {
  388. sky = VS::get_singleton()->sky_create();
  389. texture = VS::get_singleton()->texture_create();
  390. update_queued = false;
  391. sky_top_color = Color::hex(0xa5d6f1ff);
  392. sky_horizon_color = Color::hex(0xd6eafaff);
  393. sky_curve = 0.09;
  394. sky_energy = 1;
  395. ground_bottom_color = Color::hex(0x282f36ff);
  396. ground_horizon_color = Color::hex(0x6c655fff);
  397. ground_curve = 0.02;
  398. ground_energy = 1;
  399. sun_color = Color(1, 1, 1);
  400. sun_latitude = 35;
  401. sun_longitude = 0;
  402. sun_angle_min = 1;
  403. sun_angle_max = 100;
  404. sun_curve = 0.05;
  405. sun_energy = 16;
  406. texture_size = TEXTURE_SIZE_1024;
  407. sky_thread = NULL;
  408. regen_queued = false;
  409. first_time = true;
  410. _queue_update();
  411. }
  412. ProceduralSky::~ProceduralSky() {
  413. if (sky_thread) {
  414. Thread::wait_to_finish(sky_thread);
  415. memdelete(sky_thread);
  416. sky_thread = NULL;
  417. }
  418. VS::get_singleton()->free(sky);
  419. VS::get_singleton()->free(texture);
  420. }