sky.cpp 18 KB

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