sky.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. /*************************************************************************/
  2. /* sky.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.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;
  116. sun_linear.r = sun_color.r * sun_energy;
  117. sun_linear.g = sun_color.g * sun_energy;
  118. sun_linear.b = sun_color.b * sun_energy;
  119. Vector3 sun(0, 0, -1);
  120. sun = Basis(Vector3(1, 0, 0), Math::deg2rad(sun_latitude)).xform(sun);
  121. sun = Basis(Vector3(0, 1, 0), Math::deg2rad(sun_longitude)).xform(sun);
  122. sun.normalize();
  123. for (int i = 0; i < w; i++) {
  124. float u = float(i) / (w - 1);
  125. float phi = u * 2.0 * Math_PI;
  126. for (int j = 0; j < h; j++) {
  127. float v = float(j) / (h - 1);
  128. float theta = v * Math_PI;
  129. Vector3 normal(
  130. Math::sin(phi) * Math::sin(theta) * -1.0,
  131. Math::cos(theta),
  132. Math::cos(phi) * Math::sin(theta) * -1.0);
  133. normal.normalize();
  134. float v_angle = Math::acos(CLAMP(normal.y, -1.0, 1.0));
  135. Color color;
  136. if (normal.y < 0) {
  137. //ground
  138. float c = (v_angle - (Math_PI * 0.5)) / (Math_PI * 0.5);
  139. color = ground_horizon_linear.linear_interpolate(ground_bottom_linear, Math::ease(c, ground_curve));
  140. color.r *= ground_energy;
  141. color.g *= ground_energy;
  142. color.b *= ground_energy;
  143. } else {
  144. float c = v_angle / (Math_PI * 0.5);
  145. color = sky_horizon_linear.linear_interpolate(sky_top_linear, Math::ease(1.0 - c, sky_curve));
  146. color.r *= sky_energy;
  147. color.g *= sky_energy;
  148. color.b *= sky_energy;
  149. float sun_angle = Math::rad2deg(Math::acos(CLAMP(sun.dot(normal), -1.0, 1.0)));
  150. if (sun_angle < sun_angle_min) {
  151. color = color.blend(sun_linear);
  152. } else if (sun_angle < sun_angle_max) {
  153. float c2 = (sun_angle - sun_angle_min) / (sun_angle_max - sun_angle_min);
  154. c2 = Math::ease(c2, sun_curve);
  155. color = color.blend(sun_linear).linear_interpolate(color, c2);
  156. }
  157. }
  158. ptr[j * w + i] = color.to_rgbe9995();
  159. }
  160. }
  161. }
  162. Ref<Image> image;
  163. image.instance();
  164. image->create(w, h, false, Image::FORMAT_RGBE9995, imgdata);
  165. return image;
  166. }
  167. void ProceduralSky::set_sky_top_color(const Color &p_sky_top) {
  168. sky_top_color = p_sky_top;
  169. _queue_update();
  170. }
  171. Color ProceduralSky::get_sky_top_color() const {
  172. return sky_top_color;
  173. }
  174. void ProceduralSky::set_sky_horizon_color(const Color &p_sky_horizon) {
  175. sky_horizon_color = p_sky_horizon;
  176. _queue_update();
  177. }
  178. Color ProceduralSky::get_sky_horizon_color() const {
  179. return sky_horizon_color;
  180. }
  181. void ProceduralSky::set_sky_curve(float p_curve) {
  182. sky_curve = p_curve;
  183. _queue_update();
  184. }
  185. float ProceduralSky::get_sky_curve() const {
  186. return sky_curve;
  187. }
  188. void ProceduralSky::set_sky_energy(float p_energy) {
  189. sky_energy = p_energy;
  190. _queue_update();
  191. }
  192. float ProceduralSky::get_sky_energy() const {
  193. return sky_energy;
  194. }
  195. void ProceduralSky::set_ground_bottom_color(const Color &p_ground_bottom) {
  196. ground_bottom_color = p_ground_bottom;
  197. _queue_update();
  198. }
  199. Color ProceduralSky::get_ground_bottom_color() const {
  200. return ground_bottom_color;
  201. }
  202. void ProceduralSky::set_ground_horizon_color(const Color &p_ground_horizon) {
  203. ground_horizon_color = p_ground_horizon;
  204. _queue_update();
  205. }
  206. Color ProceduralSky::get_ground_horizon_color() const {
  207. return ground_horizon_color;
  208. }
  209. void ProceduralSky::set_ground_curve(float p_curve) {
  210. ground_curve = p_curve;
  211. _queue_update();
  212. }
  213. float ProceduralSky::get_ground_curve() const {
  214. return ground_curve;
  215. }
  216. void ProceduralSky::set_ground_energy(float p_energy) {
  217. ground_energy = p_energy;
  218. _queue_update();
  219. }
  220. float ProceduralSky::get_ground_energy() const {
  221. return ground_energy;
  222. }
  223. void ProceduralSky::set_sun_color(const Color &p_sun) {
  224. sun_color = p_sun;
  225. _queue_update();
  226. }
  227. Color ProceduralSky::get_sun_color() const {
  228. return sun_color;
  229. }
  230. void ProceduralSky::set_sun_latitude(float p_angle) {
  231. sun_latitude = p_angle;
  232. _queue_update();
  233. }
  234. float ProceduralSky::get_sun_latitude() const {
  235. return sun_latitude;
  236. }
  237. void ProceduralSky::set_sun_longitude(float p_angle) {
  238. sun_longitude = p_angle;
  239. _queue_update();
  240. }
  241. float ProceduralSky::get_sun_longitude() const {
  242. return sun_longitude;
  243. }
  244. void ProceduralSky::set_sun_angle_min(float p_angle) {
  245. sun_angle_min = p_angle;
  246. _queue_update();
  247. }
  248. float ProceduralSky::get_sun_angle_min() const {
  249. return sun_angle_min;
  250. }
  251. void ProceduralSky::set_sun_angle_max(float p_angle) {
  252. sun_angle_max = p_angle;
  253. _queue_update();
  254. }
  255. float ProceduralSky::get_sun_angle_max() const {
  256. return sun_angle_max;
  257. }
  258. void ProceduralSky::set_sun_curve(float p_curve) {
  259. sun_curve = p_curve;
  260. _queue_update();
  261. }
  262. float ProceduralSky::get_sun_curve() const {
  263. return sun_curve;
  264. }
  265. void ProceduralSky::set_sun_energy(float p_energy) {
  266. sun_energy = p_energy;
  267. _queue_update();
  268. }
  269. float ProceduralSky::get_sun_energy() const {
  270. return sun_energy;
  271. }
  272. void ProceduralSky::set_texture_size(TextureSize p_size) {
  273. ERR_FAIL_INDEX(p_size, TEXTURE_SIZE_MAX);
  274. texture_size = p_size;
  275. _queue_update();
  276. }
  277. ProceduralSky::TextureSize ProceduralSky::get_texture_size() const {
  278. return texture_size;
  279. }
  280. RID ProceduralSky::get_rid() const {
  281. return sky;
  282. }
  283. void ProceduralSky::_update_sky() {
  284. bool use_thread = true;
  285. if (first_time) {
  286. use_thread = false;
  287. first_time = false;
  288. }
  289. #ifdef NO_THREADS
  290. use_thread = false;
  291. #endif
  292. if (use_thread) {
  293. if (!sky_thread) {
  294. sky_thread = Thread::create(_thread_function, this);
  295. regen_queued = false;
  296. } else {
  297. regen_queued = true;
  298. }
  299. } else {
  300. Ref<Image> image = _generate_sky();
  301. 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);
  302. VS::get_singleton()->texture_set_data(texture, image);
  303. _radiance_changed();
  304. }
  305. }
  306. void ProceduralSky::_queue_update() {
  307. if (update_queued)
  308. return;
  309. update_queued = true;
  310. call_deferred("_update_sky");
  311. }
  312. void ProceduralSky::_thread_done(const Ref<Image> &p_image) {
  313. 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);
  314. VS::get_singleton()->texture_set_data(texture, p_image);
  315. _radiance_changed();
  316. Thread::wait_to_finish(sky_thread);
  317. memdelete(sky_thread);
  318. sky_thread = NULL;
  319. if (regen_queued) {
  320. sky_thread = Thread::create(_thread_function, this);
  321. regen_queued = false;
  322. }
  323. }
  324. void ProceduralSky::_thread_function(void *p_ud) {
  325. ProceduralSky *psky = (ProceduralSky *)p_ud;
  326. psky->call_deferred("_thread_done", psky->_generate_sky());
  327. }
  328. void ProceduralSky::_bind_methods() {
  329. ClassDB::bind_method(D_METHOD("_update_sky"), &ProceduralSky::_update_sky);
  330. ClassDB::bind_method(D_METHOD("set_sky_top_color", "color"), &ProceduralSky::set_sky_top_color);
  331. ClassDB::bind_method(D_METHOD("get_sky_top_color"), &ProceduralSky::get_sky_top_color);
  332. ClassDB::bind_method(D_METHOD("set_sky_horizon_color", "color"), &ProceduralSky::set_sky_horizon_color);
  333. ClassDB::bind_method(D_METHOD("get_sky_horizon_color"), &ProceduralSky::get_sky_horizon_color);
  334. ClassDB::bind_method(D_METHOD("set_sky_curve", "curve"), &ProceduralSky::set_sky_curve);
  335. ClassDB::bind_method(D_METHOD("get_sky_curve"), &ProceduralSky::get_sky_curve);
  336. ClassDB::bind_method(D_METHOD("set_sky_energy", "energy"), &ProceduralSky::set_sky_energy);
  337. ClassDB::bind_method(D_METHOD("get_sky_energy"), &ProceduralSky::get_sky_energy);
  338. ClassDB::bind_method(D_METHOD("set_ground_bottom_color", "color"), &ProceduralSky::set_ground_bottom_color);
  339. ClassDB::bind_method(D_METHOD("get_ground_bottom_color"), &ProceduralSky::get_ground_bottom_color);
  340. ClassDB::bind_method(D_METHOD("set_ground_horizon_color", "color"), &ProceduralSky::set_ground_horizon_color);
  341. ClassDB::bind_method(D_METHOD("get_ground_horizon_color"), &ProceduralSky::get_ground_horizon_color);
  342. ClassDB::bind_method(D_METHOD("set_ground_curve", "curve"), &ProceduralSky::set_ground_curve);
  343. ClassDB::bind_method(D_METHOD("get_ground_curve"), &ProceduralSky::get_ground_curve);
  344. ClassDB::bind_method(D_METHOD("set_ground_energy", "energy"), &ProceduralSky::set_ground_energy);
  345. ClassDB::bind_method(D_METHOD("get_ground_energy"), &ProceduralSky::get_ground_energy);
  346. ClassDB::bind_method(D_METHOD("set_sun_color", "color"), &ProceduralSky::set_sun_color);
  347. ClassDB::bind_method(D_METHOD("get_sun_color"), &ProceduralSky::get_sun_color);
  348. ClassDB::bind_method(D_METHOD("set_sun_latitude", "degrees"), &ProceduralSky::set_sun_latitude);
  349. ClassDB::bind_method(D_METHOD("get_sun_latitude"), &ProceduralSky::get_sun_latitude);
  350. ClassDB::bind_method(D_METHOD("set_sun_longitude", "degrees"), &ProceduralSky::set_sun_longitude);
  351. ClassDB::bind_method(D_METHOD("get_sun_longitude"), &ProceduralSky::get_sun_longitude);
  352. ClassDB::bind_method(D_METHOD("set_sun_angle_min", "degrees"), &ProceduralSky::set_sun_angle_min);
  353. ClassDB::bind_method(D_METHOD("get_sun_angle_min"), &ProceduralSky::get_sun_angle_min);
  354. ClassDB::bind_method(D_METHOD("set_sun_angle_max", "degrees"), &ProceduralSky::set_sun_angle_max);
  355. ClassDB::bind_method(D_METHOD("get_sun_angle_max"), &ProceduralSky::get_sun_angle_max);
  356. ClassDB::bind_method(D_METHOD("set_sun_curve", "curve"), &ProceduralSky::set_sun_curve);
  357. ClassDB::bind_method(D_METHOD("get_sun_curve"), &ProceduralSky::get_sun_curve);
  358. ClassDB::bind_method(D_METHOD("set_sun_energy", "energy"), &ProceduralSky::set_sun_energy);
  359. ClassDB::bind_method(D_METHOD("get_sun_energy"), &ProceduralSky::get_sun_energy);
  360. ClassDB::bind_method(D_METHOD("set_texture_size", "size"), &ProceduralSky::set_texture_size);
  361. ClassDB::bind_method(D_METHOD("get_texture_size"), &ProceduralSky::get_texture_size);
  362. ClassDB::bind_method(D_METHOD("_thread_done", "image"), &ProceduralSky::_thread_done);
  363. ADD_GROUP("Sky", "sky_");
  364. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "sky_top_color"), "set_sky_top_color", "get_sky_top_color");
  365. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "sky_horizon_color"), "set_sky_horizon_color", "get_sky_horizon_color");
  366. ADD_PROPERTY(PropertyInfo(Variant::REAL, "sky_curve", PROPERTY_HINT_EXP_EASING), "set_sky_curve", "get_sky_curve");
  367. ADD_PROPERTY(PropertyInfo(Variant::REAL, "sky_energy", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_sky_energy", "get_sky_energy");
  368. ADD_GROUP("Ground", "ground_");
  369. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "ground_bottom_color"), "set_ground_bottom_color", "get_ground_bottom_color");
  370. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "ground_horizon_color"), "set_ground_horizon_color", "get_ground_horizon_color");
  371. ADD_PROPERTY(PropertyInfo(Variant::REAL, "ground_curve", PROPERTY_HINT_EXP_EASING), "set_ground_curve", "get_ground_curve");
  372. ADD_PROPERTY(PropertyInfo(Variant::REAL, "ground_energy", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_ground_energy", "get_ground_energy");
  373. ADD_GROUP("Sun", "sun_");
  374. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "sun_color"), "set_sun_color", "get_sun_color");
  375. ADD_PROPERTY(PropertyInfo(Variant::REAL, "sun_latitude", PROPERTY_HINT_RANGE, "-180,180,0.01"), "set_sun_latitude", "get_sun_latitude");
  376. ADD_PROPERTY(PropertyInfo(Variant::REAL, "sun_longitude", PROPERTY_HINT_RANGE, "-180,180,0.01"), "set_sun_longitude", "get_sun_longitude");
  377. ADD_PROPERTY(PropertyInfo(Variant::REAL, "sun_angle_min", PROPERTY_HINT_RANGE, "0,360,0.01"), "set_sun_angle_min", "get_sun_angle_min");
  378. ADD_PROPERTY(PropertyInfo(Variant::REAL, "sun_angle_max", PROPERTY_HINT_RANGE, "0,360,0.01"), "set_sun_angle_max", "get_sun_angle_max");
  379. ADD_PROPERTY(PropertyInfo(Variant::REAL, "sun_curve", PROPERTY_HINT_EXP_EASING), "set_sun_curve", "get_sun_curve");
  380. ADD_PROPERTY(PropertyInfo(Variant::REAL, "sun_energy", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_sun_energy", "get_sun_energy");
  381. ADD_GROUP("Texture", "texture_");
  382. ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_size", PROPERTY_HINT_ENUM, "256,512,1024,2048,4096"), "set_texture_size", "get_texture_size");
  383. BIND_ENUM_CONSTANT(TEXTURE_SIZE_256);
  384. BIND_ENUM_CONSTANT(TEXTURE_SIZE_512);
  385. BIND_ENUM_CONSTANT(TEXTURE_SIZE_1024);
  386. BIND_ENUM_CONSTANT(TEXTURE_SIZE_2048);
  387. BIND_ENUM_CONSTANT(TEXTURE_SIZE_4096);
  388. BIND_ENUM_CONSTANT(TEXTURE_SIZE_MAX);
  389. }
  390. ProceduralSky::ProceduralSky(bool p_desaturate) {
  391. sky = VS::get_singleton()->sky_create();
  392. texture = VS::get_singleton()->texture_create();
  393. update_queued = false;
  394. sky_top_color = Color::hex(0xa5d6f1ff);
  395. sky_horizon_color = Color::hex(0xd6eafaff);
  396. sky_curve = 0.09;
  397. sky_energy = 1;
  398. ground_bottom_color = Color::hex(0x282f36ff);
  399. ground_horizon_color = Color::hex(0x6c655fff);
  400. ground_curve = 0.02;
  401. ground_energy = 1;
  402. if (p_desaturate) {
  403. sky_top_color.set_hsv(sky_top_color.get_h(),0,sky_top_color.get_v());
  404. sky_horizon_color.set_hsv(sky_horizon_color.get_h(),0,sky_horizon_color.get_v());
  405. ground_bottom_color.set_hsv(ground_bottom_color.get_h(),0,ground_bottom_color.get_v());
  406. ground_horizon_color.set_hsv(ground_horizon_color.get_h(),0,ground_horizon_color.get_v());
  407. }
  408. sun_color = Color(1, 1, 1);
  409. sun_latitude = 35;
  410. sun_longitude = 0;
  411. sun_angle_min = 1;
  412. sun_angle_max = 100;
  413. sun_curve = 0.05;
  414. sun_energy = 1;
  415. texture_size = TEXTURE_SIZE_1024;
  416. sky_thread = NULL;
  417. regen_queued = false;
  418. first_time = true;
  419. _queue_update();
  420. }
  421. ProceduralSky::~ProceduralSky() {
  422. if (sky_thread) {
  423. Thread::wait_to_finish(sky_thread);
  424. memdelete(sky_thread);
  425. sky_thread = NULL;
  426. }
  427. VS::get_singleton()->free(sky);
  428. VS::get_singleton()->free(texture);
  429. }