environment.cpp 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630
  1. /**************************************************************************/
  2. /* environment.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 "environment.h"
  31. #include "core/config/project_settings.h"
  32. #include "scene/resources/gradient_texture.h"
  33. #include "servers/rendering_server.h"
  34. RID Environment::get_rid() const {
  35. return environment;
  36. }
  37. // Background
  38. void Environment::set_background(BGMode p_bg) {
  39. bg_mode = p_bg;
  40. RS::get_singleton()->environment_set_background(environment, RS::EnvironmentBG(p_bg));
  41. notify_property_list_changed();
  42. if (bg_mode != BG_SKY) {
  43. set_fog_aerial_perspective(0.0);
  44. }
  45. }
  46. Environment::BGMode Environment::get_background() const {
  47. return bg_mode;
  48. }
  49. void Environment::set_sky(const Ref<Sky> &p_sky) {
  50. bg_sky = p_sky;
  51. RID sb_rid;
  52. if (bg_sky.is_valid()) {
  53. sb_rid = bg_sky->get_rid();
  54. }
  55. RS::get_singleton()->environment_set_sky(environment, sb_rid);
  56. }
  57. Ref<Sky> Environment::get_sky() const {
  58. return bg_sky;
  59. }
  60. void Environment::set_sky_custom_fov(float p_scale) {
  61. bg_sky_custom_fov = p_scale;
  62. RS::get_singleton()->environment_set_sky_custom_fov(environment, p_scale);
  63. }
  64. float Environment::get_sky_custom_fov() const {
  65. return bg_sky_custom_fov;
  66. }
  67. void Environment::set_sky_rotation(const Vector3 &p_rotation) {
  68. bg_sky_rotation = p_rotation;
  69. RS::get_singleton()->environment_set_sky_orientation(environment, Basis::from_euler(p_rotation));
  70. }
  71. Vector3 Environment::get_sky_rotation() const {
  72. return bg_sky_rotation;
  73. }
  74. void Environment::set_bg_color(const Color &p_color) {
  75. bg_color = p_color;
  76. RS::get_singleton()->environment_set_bg_color(environment, p_color);
  77. }
  78. Color Environment::get_bg_color() const {
  79. return bg_color;
  80. }
  81. void Environment::set_bg_energy_multiplier(float p_multiplier) {
  82. bg_energy_multiplier = p_multiplier;
  83. _update_bg_energy();
  84. }
  85. float Environment::get_bg_energy_multiplier() const {
  86. return bg_energy_multiplier;
  87. }
  88. void Environment::set_bg_intensity(float p_exposure_value) {
  89. bg_intensity = p_exposure_value;
  90. _update_bg_energy();
  91. }
  92. float Environment::get_bg_intensity() const {
  93. return bg_intensity;
  94. }
  95. void Environment::_update_bg_energy() {
  96. if (GLOBAL_GET("rendering/lights_and_shadows/use_physical_light_units")) {
  97. RS::get_singleton()->environment_set_bg_energy(environment, bg_energy_multiplier, bg_intensity);
  98. } else {
  99. RS::get_singleton()->environment_set_bg_energy(environment, bg_energy_multiplier, 1.0);
  100. }
  101. }
  102. void Environment::set_canvas_max_layer(int p_max_layer) {
  103. bg_canvas_max_layer = p_max_layer;
  104. RS::get_singleton()->environment_set_canvas_max_layer(environment, p_max_layer);
  105. }
  106. int Environment::get_canvas_max_layer() const {
  107. return bg_canvas_max_layer;
  108. }
  109. void Environment::set_camera_feed_id(int p_id) {
  110. bg_camera_feed_id = p_id;
  111. RS::get_singleton()->environment_set_camera_feed_id(environment, bg_camera_feed_id);
  112. }
  113. int Environment::get_camera_feed_id() const {
  114. return bg_camera_feed_id;
  115. }
  116. // Ambient light
  117. void Environment::set_ambient_light_color(const Color &p_color) {
  118. ambient_color = p_color;
  119. _update_ambient_light();
  120. }
  121. Color Environment::get_ambient_light_color() const {
  122. return ambient_color;
  123. }
  124. void Environment::set_ambient_source(AmbientSource p_source) {
  125. ambient_source = p_source;
  126. _update_ambient_light();
  127. notify_property_list_changed();
  128. }
  129. Environment::AmbientSource Environment::get_ambient_source() const {
  130. return ambient_source;
  131. }
  132. void Environment::set_ambient_light_energy(float p_energy) {
  133. ambient_energy = p_energy;
  134. _update_ambient_light();
  135. }
  136. float Environment::get_ambient_light_energy() const {
  137. return ambient_energy;
  138. }
  139. void Environment::set_ambient_light_sky_contribution(float p_ratio) {
  140. // Sky contribution values outside the [0.0; 1.0] range don't make sense and
  141. // can result in negative colors.
  142. ambient_sky_contribution = CLAMP(p_ratio, 0.0, 1.0);
  143. _update_ambient_light();
  144. }
  145. float Environment::get_ambient_light_sky_contribution() const {
  146. return ambient_sky_contribution;
  147. }
  148. void Environment::set_reflection_source(ReflectionSource p_source) {
  149. reflection_source = p_source;
  150. _update_ambient_light();
  151. notify_property_list_changed();
  152. }
  153. Environment::ReflectionSource Environment::get_reflection_source() const {
  154. return reflection_source;
  155. }
  156. void Environment::_update_ambient_light() {
  157. RS::get_singleton()->environment_set_ambient_light(
  158. environment,
  159. ambient_color,
  160. RS::EnvironmentAmbientSource(ambient_source),
  161. ambient_energy,
  162. ambient_sky_contribution, RS::EnvironmentReflectionSource(reflection_source));
  163. }
  164. // Tonemap
  165. void Environment::set_tonemapper(ToneMapper p_tone_mapper) {
  166. tone_mapper = p_tone_mapper;
  167. _update_tonemap();
  168. notify_property_list_changed();
  169. }
  170. Environment::ToneMapper Environment::get_tonemapper() const {
  171. return tone_mapper;
  172. }
  173. void Environment::set_tonemap_exposure(float p_exposure) {
  174. tonemap_exposure = p_exposure;
  175. _update_tonemap();
  176. }
  177. float Environment::get_tonemap_exposure() const {
  178. return tonemap_exposure;
  179. }
  180. void Environment::set_tonemap_white(float p_white) {
  181. tonemap_white = p_white;
  182. _update_tonemap();
  183. }
  184. float Environment::get_tonemap_white() const {
  185. return tonemap_white;
  186. }
  187. void Environment::_update_tonemap() {
  188. RS::get_singleton()->environment_set_tonemap(
  189. environment,
  190. RS::EnvironmentToneMapper(tone_mapper),
  191. tonemap_exposure,
  192. tonemap_white);
  193. }
  194. // SSR
  195. void Environment::set_ssr_enabled(bool p_enabled) {
  196. ssr_enabled = p_enabled;
  197. _update_ssr();
  198. notify_property_list_changed();
  199. }
  200. bool Environment::is_ssr_enabled() const {
  201. return ssr_enabled;
  202. }
  203. void Environment::set_ssr_max_steps(int p_steps) {
  204. ssr_max_steps = p_steps;
  205. _update_ssr();
  206. }
  207. int Environment::get_ssr_max_steps() const {
  208. return ssr_max_steps;
  209. }
  210. void Environment::set_ssr_fade_in(float p_fade_in) {
  211. ssr_fade_in = MAX(p_fade_in, 0.0f);
  212. _update_ssr();
  213. }
  214. float Environment::get_ssr_fade_in() const {
  215. return ssr_fade_in;
  216. }
  217. void Environment::set_ssr_fade_out(float p_fade_out) {
  218. ssr_fade_out = MAX(p_fade_out, 0.0f);
  219. _update_ssr();
  220. }
  221. float Environment::get_ssr_fade_out() const {
  222. return ssr_fade_out;
  223. }
  224. void Environment::set_ssr_depth_tolerance(float p_depth_tolerance) {
  225. ssr_depth_tolerance = p_depth_tolerance;
  226. _update_ssr();
  227. }
  228. float Environment::get_ssr_depth_tolerance() const {
  229. return ssr_depth_tolerance;
  230. }
  231. void Environment::_update_ssr() {
  232. RS::get_singleton()->environment_set_ssr(
  233. environment,
  234. ssr_enabled,
  235. ssr_max_steps,
  236. ssr_fade_in,
  237. ssr_fade_out,
  238. ssr_depth_tolerance);
  239. }
  240. // SSAO
  241. void Environment::set_ssao_enabled(bool p_enabled) {
  242. ssao_enabled = p_enabled;
  243. _update_ssao();
  244. notify_property_list_changed();
  245. }
  246. bool Environment::is_ssao_enabled() const {
  247. return ssao_enabled;
  248. }
  249. void Environment::set_ssao_radius(float p_radius) {
  250. ssao_radius = p_radius;
  251. _update_ssao();
  252. }
  253. float Environment::get_ssao_radius() const {
  254. return ssao_radius;
  255. }
  256. void Environment::set_ssao_intensity(float p_intensity) {
  257. ssao_intensity = p_intensity;
  258. _update_ssao();
  259. }
  260. float Environment::get_ssao_intensity() const {
  261. return ssao_intensity;
  262. }
  263. void Environment::set_ssao_power(float p_power) {
  264. ssao_power = p_power;
  265. _update_ssao();
  266. }
  267. float Environment::get_ssao_power() const {
  268. return ssao_power;
  269. }
  270. void Environment::set_ssao_detail(float p_detail) {
  271. ssao_detail = p_detail;
  272. _update_ssao();
  273. }
  274. float Environment::get_ssao_detail() const {
  275. return ssao_detail;
  276. }
  277. void Environment::set_ssao_horizon(float p_horizon) {
  278. ssao_horizon = p_horizon;
  279. _update_ssao();
  280. }
  281. float Environment::get_ssao_horizon() const {
  282. return ssao_horizon;
  283. }
  284. void Environment::set_ssao_sharpness(float p_sharpness) {
  285. ssao_sharpness = p_sharpness;
  286. _update_ssao();
  287. }
  288. float Environment::get_ssao_sharpness() const {
  289. return ssao_sharpness;
  290. }
  291. void Environment::set_ssao_direct_light_affect(float p_direct_light_affect) {
  292. ssao_direct_light_affect = p_direct_light_affect;
  293. _update_ssao();
  294. }
  295. float Environment::get_ssao_direct_light_affect() const {
  296. return ssao_direct_light_affect;
  297. }
  298. void Environment::set_ssao_ao_channel_affect(float p_ao_channel_affect) {
  299. ssao_ao_channel_affect = p_ao_channel_affect;
  300. _update_ssao();
  301. }
  302. float Environment::get_ssao_ao_channel_affect() const {
  303. return ssao_ao_channel_affect;
  304. }
  305. void Environment::_update_ssao() {
  306. RS::get_singleton()->environment_set_ssao(
  307. environment,
  308. ssao_enabled,
  309. ssao_radius,
  310. ssao_intensity,
  311. ssao_power,
  312. ssao_detail,
  313. ssao_horizon,
  314. ssao_sharpness,
  315. ssao_direct_light_affect,
  316. ssao_ao_channel_affect);
  317. }
  318. // SSIL
  319. void Environment::set_ssil_enabled(bool p_enabled) {
  320. ssil_enabled = p_enabled;
  321. _update_ssil();
  322. notify_property_list_changed();
  323. }
  324. bool Environment::is_ssil_enabled() const {
  325. return ssil_enabled;
  326. }
  327. void Environment::set_ssil_radius(float p_radius) {
  328. ssil_radius = p_radius;
  329. _update_ssil();
  330. }
  331. float Environment::get_ssil_radius() const {
  332. return ssil_radius;
  333. }
  334. void Environment::set_ssil_intensity(float p_intensity) {
  335. ssil_intensity = p_intensity;
  336. _update_ssil();
  337. }
  338. float Environment::get_ssil_intensity() const {
  339. return ssil_intensity;
  340. }
  341. void Environment::set_ssil_sharpness(float p_sharpness) {
  342. ssil_sharpness = p_sharpness;
  343. _update_ssil();
  344. }
  345. float Environment::get_ssil_sharpness() const {
  346. return ssil_sharpness;
  347. }
  348. void Environment::set_ssil_normal_rejection(float p_normal_rejection) {
  349. ssil_normal_rejection = p_normal_rejection;
  350. _update_ssil();
  351. }
  352. float Environment::get_ssil_normal_rejection() const {
  353. return ssil_normal_rejection;
  354. }
  355. void Environment::_update_ssil() {
  356. RS::get_singleton()->environment_set_ssil(
  357. environment,
  358. ssil_enabled,
  359. ssil_radius,
  360. ssil_intensity,
  361. ssil_sharpness,
  362. ssil_normal_rejection);
  363. }
  364. // SDFGI
  365. void Environment::set_sdfgi_enabled(bool p_enabled) {
  366. sdfgi_enabled = p_enabled;
  367. _update_sdfgi();
  368. notify_property_list_changed();
  369. }
  370. bool Environment::is_sdfgi_enabled() const {
  371. return sdfgi_enabled;
  372. }
  373. void Environment::set_sdfgi_cascades(int p_cascades) {
  374. ERR_FAIL_COND_MSG(p_cascades < 1 || p_cascades > 8, "Invalid number of SDFGI cascades (must be between 1 and 8).");
  375. sdfgi_cascades = p_cascades;
  376. _update_sdfgi();
  377. }
  378. int Environment::get_sdfgi_cascades() const {
  379. return sdfgi_cascades;
  380. }
  381. void Environment::set_sdfgi_min_cell_size(float p_size) {
  382. sdfgi_min_cell_size = p_size;
  383. _update_sdfgi();
  384. }
  385. float Environment::get_sdfgi_min_cell_size() const {
  386. return sdfgi_min_cell_size;
  387. }
  388. void Environment::set_sdfgi_max_distance(float p_distance) {
  389. p_distance /= 64.0;
  390. for (int i = 0; i < sdfgi_cascades; i++) {
  391. p_distance *= 0.5; //halve for each cascade
  392. }
  393. sdfgi_min_cell_size = p_distance;
  394. _update_sdfgi();
  395. }
  396. float Environment::get_sdfgi_max_distance() const {
  397. float md = sdfgi_min_cell_size;
  398. md *= 64.0;
  399. for (int i = 0; i < sdfgi_cascades; i++) {
  400. md *= 2.0;
  401. }
  402. return md;
  403. }
  404. void Environment::set_sdfgi_cascade0_distance(float p_distance) {
  405. sdfgi_min_cell_size = p_distance / 64.0;
  406. _update_sdfgi();
  407. }
  408. float Environment::get_sdfgi_cascade0_distance() const {
  409. return sdfgi_min_cell_size * 64.0;
  410. }
  411. void Environment::set_sdfgi_y_scale(SDFGIYScale p_y_scale) {
  412. sdfgi_y_scale = p_y_scale;
  413. _update_sdfgi();
  414. }
  415. Environment::SDFGIYScale Environment::get_sdfgi_y_scale() const {
  416. return sdfgi_y_scale;
  417. }
  418. void Environment::set_sdfgi_use_occlusion(bool p_enabled) {
  419. sdfgi_use_occlusion = p_enabled;
  420. _update_sdfgi();
  421. }
  422. bool Environment::is_sdfgi_using_occlusion() const {
  423. return sdfgi_use_occlusion;
  424. }
  425. void Environment::set_sdfgi_bounce_feedback(float p_amount) {
  426. sdfgi_bounce_feedback = p_amount;
  427. _update_sdfgi();
  428. }
  429. float Environment::get_sdfgi_bounce_feedback() const {
  430. return sdfgi_bounce_feedback;
  431. }
  432. void Environment::set_sdfgi_read_sky_light(bool p_enabled) {
  433. sdfgi_read_sky_light = p_enabled;
  434. _update_sdfgi();
  435. }
  436. bool Environment::is_sdfgi_reading_sky_light() const {
  437. return sdfgi_read_sky_light;
  438. }
  439. void Environment::set_sdfgi_energy(float p_energy) {
  440. sdfgi_energy = p_energy;
  441. _update_sdfgi();
  442. }
  443. float Environment::get_sdfgi_energy() const {
  444. return sdfgi_energy;
  445. }
  446. void Environment::set_sdfgi_normal_bias(float p_bias) {
  447. sdfgi_normal_bias = p_bias;
  448. _update_sdfgi();
  449. }
  450. float Environment::get_sdfgi_normal_bias() const {
  451. return sdfgi_normal_bias;
  452. }
  453. void Environment::set_sdfgi_probe_bias(float p_bias) {
  454. sdfgi_probe_bias = p_bias;
  455. _update_sdfgi();
  456. }
  457. float Environment::get_sdfgi_probe_bias() const {
  458. return sdfgi_probe_bias;
  459. }
  460. void Environment::_update_sdfgi() {
  461. RS::get_singleton()->environment_set_sdfgi(
  462. environment,
  463. sdfgi_enabled,
  464. sdfgi_cascades,
  465. sdfgi_min_cell_size,
  466. RS::EnvironmentSDFGIYScale(sdfgi_y_scale),
  467. sdfgi_use_occlusion,
  468. sdfgi_bounce_feedback,
  469. sdfgi_read_sky_light,
  470. sdfgi_energy,
  471. sdfgi_normal_bias,
  472. sdfgi_probe_bias);
  473. }
  474. // Glow
  475. void Environment::set_glow_enabled(bool p_enabled) {
  476. glow_enabled = p_enabled;
  477. _update_glow();
  478. notify_property_list_changed();
  479. }
  480. bool Environment::is_glow_enabled() const {
  481. return glow_enabled;
  482. }
  483. void Environment::set_glow_level(int p_level, float p_intensity) {
  484. ERR_FAIL_INDEX(p_level, RS::MAX_GLOW_LEVELS);
  485. glow_levels.write[p_level] = p_intensity;
  486. _update_glow();
  487. }
  488. float Environment::get_glow_level(int p_level) const {
  489. ERR_FAIL_INDEX_V(p_level, RS::MAX_GLOW_LEVELS, 0.0);
  490. return glow_levels[p_level];
  491. }
  492. void Environment::set_glow_normalized(bool p_normalized) {
  493. glow_normalize_levels = p_normalized;
  494. _update_glow();
  495. }
  496. bool Environment::is_glow_normalized() const {
  497. return glow_normalize_levels;
  498. }
  499. void Environment::set_glow_intensity(float p_intensity) {
  500. glow_intensity = p_intensity;
  501. _update_glow();
  502. }
  503. float Environment::get_glow_intensity() const {
  504. return glow_intensity;
  505. }
  506. void Environment::set_glow_strength(float p_strength) {
  507. glow_strength = p_strength;
  508. _update_glow();
  509. }
  510. float Environment::get_glow_strength() const {
  511. return glow_strength;
  512. }
  513. void Environment::set_glow_mix(float p_mix) {
  514. glow_mix = p_mix;
  515. _update_glow();
  516. }
  517. float Environment::get_glow_mix() const {
  518. return glow_mix;
  519. }
  520. void Environment::set_glow_bloom(float p_threshold) {
  521. glow_bloom = p_threshold;
  522. _update_glow();
  523. }
  524. float Environment::get_glow_bloom() const {
  525. return glow_bloom;
  526. }
  527. void Environment::set_glow_blend_mode(GlowBlendMode p_mode) {
  528. glow_blend_mode = p_mode;
  529. _update_glow();
  530. notify_property_list_changed();
  531. }
  532. Environment::GlowBlendMode Environment::get_glow_blend_mode() const {
  533. return glow_blend_mode;
  534. }
  535. void Environment::set_glow_hdr_bleed_threshold(float p_threshold) {
  536. glow_hdr_bleed_threshold = p_threshold;
  537. _update_glow();
  538. }
  539. float Environment::get_glow_hdr_bleed_threshold() const {
  540. return glow_hdr_bleed_threshold;
  541. }
  542. void Environment::set_glow_hdr_bleed_scale(float p_scale) {
  543. glow_hdr_bleed_scale = p_scale;
  544. _update_glow();
  545. }
  546. float Environment::get_glow_hdr_bleed_scale() const {
  547. return glow_hdr_bleed_scale;
  548. }
  549. void Environment::set_glow_hdr_luminance_cap(float p_amount) {
  550. glow_hdr_luminance_cap = p_amount;
  551. _update_glow();
  552. }
  553. float Environment::get_glow_hdr_luminance_cap() const {
  554. return glow_hdr_luminance_cap;
  555. }
  556. void Environment::set_glow_map_strength(float p_strength) {
  557. glow_map_strength = p_strength;
  558. _update_glow();
  559. }
  560. float Environment::get_glow_map_strength() const {
  561. return glow_map_strength;
  562. }
  563. void Environment::set_glow_map(Ref<Texture> p_glow_map) {
  564. glow_map = p_glow_map;
  565. _update_glow();
  566. }
  567. Ref<Texture> Environment::get_glow_map() const {
  568. return glow_map;
  569. }
  570. void Environment::_update_glow() {
  571. Vector<float> normalized_levels;
  572. if (glow_normalize_levels) {
  573. normalized_levels.resize(7);
  574. float size = 0.0;
  575. for (int i = 0; i < glow_levels.size(); i++) {
  576. size += glow_levels[i];
  577. }
  578. for (int i = 0; i < glow_levels.size(); i++) {
  579. normalized_levels.write[i] = glow_levels[i] / size;
  580. }
  581. } else {
  582. normalized_levels = glow_levels;
  583. }
  584. float _glow_map_strength = 0.0f;
  585. RID glow_map_rid;
  586. if (glow_map.is_valid()) {
  587. glow_map_rid = glow_map->get_rid();
  588. _glow_map_strength = glow_map_strength;
  589. } else {
  590. glow_map_rid = RID();
  591. }
  592. RS::get_singleton()->environment_set_glow(
  593. environment,
  594. glow_enabled,
  595. normalized_levels,
  596. glow_intensity,
  597. glow_strength,
  598. glow_mix,
  599. glow_bloom,
  600. RS::EnvironmentGlowBlendMode(glow_blend_mode),
  601. glow_hdr_bleed_threshold,
  602. glow_hdr_bleed_scale,
  603. glow_hdr_luminance_cap,
  604. _glow_map_strength,
  605. glow_map_rid);
  606. }
  607. // Fog
  608. void Environment::set_fog_enabled(bool p_enabled) {
  609. fog_enabled = p_enabled;
  610. _update_fog();
  611. notify_property_list_changed();
  612. }
  613. bool Environment::is_fog_enabled() const {
  614. return fog_enabled;
  615. }
  616. void Environment::set_fog_mode(FogMode p_mode) {
  617. if (fog_mode != p_mode && p_mode == FogMode::FOG_MODE_EXPONENTIAL) {
  618. set_fog_density(0.01);
  619. } else {
  620. set_fog_density(1.0);
  621. }
  622. fog_mode = p_mode;
  623. _update_fog();
  624. notify_property_list_changed();
  625. }
  626. Environment::FogMode Environment::get_fog_mode() const {
  627. return fog_mode;
  628. }
  629. void Environment::set_fog_light_color(const Color &p_light_color) {
  630. fog_light_color = p_light_color;
  631. _update_fog();
  632. }
  633. Color Environment::get_fog_light_color() const {
  634. return fog_light_color;
  635. }
  636. void Environment::set_fog_light_energy(float p_amount) {
  637. fog_light_energy = p_amount;
  638. _update_fog();
  639. }
  640. float Environment::get_fog_light_energy() const {
  641. return fog_light_energy;
  642. }
  643. void Environment::set_fog_sun_scatter(float p_amount) {
  644. fog_sun_scatter = p_amount;
  645. _update_fog();
  646. }
  647. float Environment::get_fog_sun_scatter() const {
  648. return fog_sun_scatter;
  649. }
  650. void Environment::set_fog_density(float p_amount) {
  651. fog_density = p_amount;
  652. _update_fog();
  653. }
  654. float Environment::get_fog_density() const {
  655. return fog_density;
  656. }
  657. void Environment::set_fog_height(float p_amount) {
  658. fog_height = p_amount;
  659. _update_fog();
  660. }
  661. float Environment::get_fog_height() const {
  662. return fog_height;
  663. }
  664. void Environment::set_fog_height_density(float p_amount) {
  665. fog_height_density = p_amount;
  666. _update_fog();
  667. }
  668. float Environment::get_fog_height_density() const {
  669. return fog_height_density;
  670. }
  671. void Environment::set_fog_aerial_perspective(float p_aerial_perspective) {
  672. fog_aerial_perspective = p_aerial_perspective;
  673. _update_fog();
  674. }
  675. float Environment::get_fog_aerial_perspective() const {
  676. return fog_aerial_perspective;
  677. }
  678. void Environment::set_fog_sky_affect(float p_sky_affect) {
  679. fog_sky_affect = p_sky_affect;
  680. _update_fog();
  681. }
  682. float Environment::get_fog_sky_affect() const {
  683. return fog_sky_affect;
  684. }
  685. void Environment::_update_fog() {
  686. RS::get_singleton()->environment_set_fog(
  687. environment,
  688. fog_enabled,
  689. fog_light_color,
  690. fog_light_energy,
  691. fog_sun_scatter,
  692. fog_density,
  693. fog_height,
  694. fog_height_density,
  695. fog_aerial_perspective,
  696. fog_sky_affect,
  697. RS::EnvironmentFogMode(fog_mode));
  698. }
  699. // Depth Fog
  700. void Environment::set_fog_depth_curve(float p_curve) {
  701. fog_depth_curve = p_curve;
  702. _update_fog_depth();
  703. }
  704. float Environment::get_fog_depth_curve() const {
  705. return fog_depth_curve;
  706. }
  707. void Environment::set_fog_depth_begin(float p_begin) {
  708. fog_depth_begin = p_begin;
  709. if (fog_depth_begin > fog_depth_end) {
  710. set_fog_depth_end(fog_depth_begin);
  711. }
  712. _update_fog_depth();
  713. }
  714. float Environment::get_fog_depth_begin() const {
  715. return fog_depth_begin;
  716. }
  717. void Environment::set_fog_depth_end(float p_end) {
  718. fog_depth_end = p_end;
  719. if (fog_depth_end < fog_depth_begin) {
  720. set_fog_depth_begin(fog_depth_end);
  721. }
  722. _update_fog_depth();
  723. }
  724. float Environment::get_fog_depth_end() const {
  725. return fog_depth_end;
  726. }
  727. void Environment::_update_fog_depth() {
  728. RS::get_singleton()->environment_set_fog_depth(
  729. environment,
  730. fog_depth_curve,
  731. fog_depth_begin,
  732. fog_depth_end);
  733. }
  734. // Volumetric Fog
  735. void Environment::_update_volumetric_fog() {
  736. RS::get_singleton()->environment_set_volumetric_fog(
  737. environment,
  738. volumetric_fog_enabled,
  739. volumetric_fog_density,
  740. volumetric_fog_albedo,
  741. volumetric_fog_emission,
  742. volumetric_fog_emission_energy,
  743. volumetric_fog_anisotropy,
  744. volumetric_fog_length,
  745. volumetric_fog_detail_spread,
  746. volumetric_fog_gi_inject,
  747. volumetric_fog_temporal_reproject,
  748. volumetric_fog_temporal_reproject_amount,
  749. volumetric_fog_ambient_inject,
  750. volumetric_fog_sky_affect);
  751. }
  752. void Environment::set_volumetric_fog_enabled(bool p_enable) {
  753. volumetric_fog_enabled = p_enable;
  754. _update_volumetric_fog();
  755. notify_property_list_changed();
  756. }
  757. bool Environment::is_volumetric_fog_enabled() const {
  758. return volumetric_fog_enabled;
  759. }
  760. void Environment::set_volumetric_fog_density(float p_density) {
  761. volumetric_fog_density = p_density;
  762. _update_volumetric_fog();
  763. }
  764. float Environment::get_volumetric_fog_density() const {
  765. return volumetric_fog_density;
  766. }
  767. void Environment::set_volumetric_fog_albedo(Color p_color) {
  768. volumetric_fog_albedo = p_color;
  769. _update_volumetric_fog();
  770. }
  771. Color Environment::get_volumetric_fog_albedo() const {
  772. return volumetric_fog_albedo;
  773. }
  774. void Environment::set_volumetric_fog_emission(Color p_color) {
  775. volumetric_fog_emission = p_color;
  776. _update_volumetric_fog();
  777. }
  778. Color Environment::get_volumetric_fog_emission() const {
  779. return volumetric_fog_emission;
  780. }
  781. void Environment::set_volumetric_fog_emission_energy(float p_begin) {
  782. volumetric_fog_emission_energy = p_begin;
  783. _update_volumetric_fog();
  784. }
  785. float Environment::get_volumetric_fog_emission_energy() const {
  786. return volumetric_fog_emission_energy;
  787. }
  788. void Environment::set_volumetric_fog_anisotropy(float p_anisotropy) {
  789. volumetric_fog_anisotropy = p_anisotropy;
  790. _update_volumetric_fog();
  791. }
  792. float Environment::get_volumetric_fog_anisotropy() const {
  793. return volumetric_fog_anisotropy;
  794. }
  795. void Environment::set_volumetric_fog_length(float p_length) {
  796. volumetric_fog_length = p_length;
  797. _update_volumetric_fog();
  798. }
  799. float Environment::get_volumetric_fog_length() const {
  800. return volumetric_fog_length;
  801. }
  802. void Environment::set_volumetric_fog_detail_spread(float p_detail_spread) {
  803. p_detail_spread = CLAMP(p_detail_spread, 0.5, 6.0);
  804. volumetric_fog_detail_spread = p_detail_spread;
  805. _update_volumetric_fog();
  806. }
  807. float Environment::get_volumetric_fog_detail_spread() const {
  808. return volumetric_fog_detail_spread;
  809. }
  810. void Environment::set_volumetric_fog_gi_inject(float p_gi_inject) {
  811. volumetric_fog_gi_inject = p_gi_inject;
  812. _update_volumetric_fog();
  813. }
  814. float Environment::get_volumetric_fog_gi_inject() const {
  815. return volumetric_fog_gi_inject;
  816. }
  817. void Environment::set_volumetric_fog_ambient_inject(float p_ambient_inject) {
  818. volumetric_fog_ambient_inject = p_ambient_inject;
  819. _update_volumetric_fog();
  820. }
  821. float Environment::get_volumetric_fog_ambient_inject() const {
  822. return volumetric_fog_ambient_inject;
  823. }
  824. void Environment::set_volumetric_fog_sky_affect(float p_sky_affect) {
  825. volumetric_fog_sky_affect = p_sky_affect;
  826. _update_volumetric_fog();
  827. }
  828. float Environment::get_volumetric_fog_sky_affect() const {
  829. return volumetric_fog_sky_affect;
  830. }
  831. void Environment::set_volumetric_fog_temporal_reprojection_enabled(bool p_enable) {
  832. volumetric_fog_temporal_reproject = p_enable;
  833. _update_volumetric_fog();
  834. }
  835. bool Environment::is_volumetric_fog_temporal_reprojection_enabled() const {
  836. return volumetric_fog_temporal_reproject;
  837. }
  838. void Environment::set_volumetric_fog_temporal_reprojection_amount(float p_amount) {
  839. volumetric_fog_temporal_reproject_amount = p_amount;
  840. _update_volumetric_fog();
  841. }
  842. float Environment::get_volumetric_fog_temporal_reprojection_amount() const {
  843. return volumetric_fog_temporal_reproject_amount;
  844. }
  845. // Adjustment
  846. void Environment::set_adjustment_enabled(bool p_enabled) {
  847. adjustment_enabled = p_enabled;
  848. _update_adjustment();
  849. notify_property_list_changed();
  850. }
  851. bool Environment::is_adjustment_enabled() const {
  852. return adjustment_enabled;
  853. }
  854. void Environment::set_adjustment_brightness(float p_brightness) {
  855. adjustment_brightness = p_brightness;
  856. _update_adjustment();
  857. }
  858. float Environment::get_adjustment_brightness() const {
  859. return adjustment_brightness;
  860. }
  861. void Environment::set_adjustment_contrast(float p_contrast) {
  862. adjustment_contrast = p_contrast;
  863. _update_adjustment();
  864. }
  865. float Environment::get_adjustment_contrast() const {
  866. return adjustment_contrast;
  867. }
  868. void Environment::set_adjustment_saturation(float p_saturation) {
  869. adjustment_saturation = p_saturation;
  870. _update_adjustment();
  871. }
  872. float Environment::get_adjustment_saturation() const {
  873. return adjustment_saturation;
  874. }
  875. void Environment::set_adjustment_color_correction(Ref<Texture> p_color_correction) {
  876. adjustment_color_correction = p_color_correction;
  877. Ref<GradientTexture1D> grad_tex = p_color_correction;
  878. if (grad_tex.is_valid()) {
  879. grad_tex->connect_changed(callable_mp(this, &Environment::_update_adjustment));
  880. }
  881. Ref<Texture2D> adjustment_texture_2d = adjustment_color_correction;
  882. if (adjustment_texture_2d.is_valid()) {
  883. use_1d_color_correction = true;
  884. } else {
  885. use_1d_color_correction = false;
  886. }
  887. _update_adjustment();
  888. }
  889. Ref<Texture> Environment::get_adjustment_color_correction() const {
  890. return adjustment_color_correction;
  891. }
  892. void Environment::_update_adjustment() {
  893. RID color_correction = adjustment_color_correction.is_valid() ? adjustment_color_correction->get_rid() : RID();
  894. RS::get_singleton()->environment_set_adjustment(
  895. environment,
  896. adjustment_enabled,
  897. adjustment_brightness,
  898. adjustment_contrast,
  899. adjustment_saturation,
  900. use_1d_color_correction,
  901. color_correction);
  902. }
  903. // Private methods, constructor and destructor
  904. void Environment::_validate_property(PropertyInfo &p_property) const {
  905. if (p_property.name == "sky" || p_property.name == "sky_custom_fov" || p_property.name == "sky_rotation" || p_property.name == "ambient_light_sky_contribution") {
  906. if (bg_mode != BG_SKY && ambient_source != AMBIENT_SOURCE_SKY && reflection_source != REFLECTION_SOURCE_SKY) {
  907. p_property.usage = PROPERTY_USAGE_NO_EDITOR;
  908. }
  909. }
  910. if (p_property.name == "fog_depth_curve" || p_property.name == "fog_depth_begin" || p_property.name == "fog_depth_end") {
  911. if (fog_mode == FOG_MODE_EXPONENTIAL) {
  912. p_property.usage = PROPERTY_USAGE_NO_EDITOR;
  913. }
  914. }
  915. if (p_property.name == "ambient_light_color" || p_property.name == "ambient_light_energy") {
  916. if (ambient_source == AMBIENT_SOURCE_DISABLED) {
  917. p_property.usage = PROPERTY_USAGE_NO_EDITOR;
  918. }
  919. }
  920. if (p_property.name == "ambient_light_sky_contribution") {
  921. if (ambient_source == AMBIENT_SOURCE_DISABLED || ambient_source == AMBIENT_SOURCE_COLOR) {
  922. p_property.usage = PROPERTY_USAGE_NO_EDITOR;
  923. }
  924. }
  925. if (p_property.name == "fog_aerial_perspective") {
  926. if (bg_mode != BG_SKY) {
  927. p_property.usage = PROPERTY_USAGE_NO_EDITOR;
  928. }
  929. }
  930. if (p_property.name == "tonemap_white" && tone_mapper == TONE_MAPPER_LINEAR) {
  931. p_property.usage = PROPERTY_USAGE_NO_EDITOR;
  932. }
  933. if (p_property.name == "glow_intensity" && glow_blend_mode == GLOW_BLEND_MODE_MIX) {
  934. p_property.usage = PROPERTY_USAGE_NO_EDITOR;
  935. }
  936. if (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
  937. // Hide glow properties we do not support in GL Compatibility.
  938. if (p_property.name.begins_with("glow_levels") || p_property.name == "glow_normalized" || p_property.name == "glow_strength" || p_property.name == "glow_mix" || p_property.name == "glow_blend_mode" || p_property.name == "glow_map_strength" || p_property.name == "glow_map") {
  939. p_property.usage = PROPERTY_USAGE_NO_EDITOR;
  940. }
  941. } else {
  942. if (p_property.name == "glow_mix" && glow_blend_mode != GLOW_BLEND_MODE_MIX) {
  943. p_property.usage = PROPERTY_USAGE_NO_EDITOR;
  944. }
  945. }
  946. if (p_property.name == "background_color") {
  947. if (bg_mode != BG_COLOR && ambient_source != AMBIENT_SOURCE_COLOR) {
  948. p_property.usage = PROPERTY_USAGE_NO_EDITOR;
  949. }
  950. }
  951. if (p_property.name == "background_canvas_max_layer") {
  952. if (bg_mode != BG_CANVAS) {
  953. p_property.usage = PROPERTY_USAGE_NO_EDITOR;
  954. }
  955. }
  956. if (p_property.name == "background_camera_feed_id") {
  957. if (bg_mode != BG_CAMERA_FEED) {
  958. p_property.usage = PROPERTY_USAGE_NO_EDITOR;
  959. }
  960. }
  961. if (p_property.name == "background_intensity" && !GLOBAL_GET("rendering/lights_and_shadows/use_physical_light_units")) {
  962. p_property.usage = PROPERTY_USAGE_NO_EDITOR;
  963. }
  964. static const char *hide_prefixes[] = {
  965. "fog_",
  966. "volumetric_fog_",
  967. "ssr_",
  968. "ssao_",
  969. "ssil_",
  970. "sdfgi_",
  971. "glow_",
  972. "adjustment_",
  973. nullptr
  974. };
  975. const char **prefixes = hide_prefixes;
  976. while (*prefixes) {
  977. String prefix = String(*prefixes);
  978. String enabled = prefix + "enabled";
  979. if (p_property.name.begins_with(prefix) && p_property.name != enabled && !bool(get(enabled))) {
  980. p_property.usage = PROPERTY_USAGE_NO_EDITOR;
  981. return;
  982. }
  983. prefixes++;
  984. }
  985. }
  986. #ifndef DISABLE_DEPRECATED
  987. // Kept for compatibility from 3.x to 4.0.
  988. bool Environment::_set(const StringName &p_name, const Variant &p_value) {
  989. if (p_name == "background_sky") {
  990. set_sky(p_value);
  991. return true;
  992. } else if (p_name == "background_sky_custom_fov") {
  993. set_sky_custom_fov(p_value);
  994. return true;
  995. } else if (p_name == "background_sky_orientation") {
  996. Vector3 euler = p_value.operator Basis().get_euler();
  997. set_sky_rotation(euler);
  998. return true;
  999. } else {
  1000. return false;
  1001. }
  1002. }
  1003. #endif
  1004. void Environment::_bind_methods() {
  1005. // Background
  1006. ClassDB::bind_method(D_METHOD("set_background", "mode"), &Environment::set_background);
  1007. ClassDB::bind_method(D_METHOD("get_background"), &Environment::get_background);
  1008. ClassDB::bind_method(D_METHOD("set_sky", "sky"), &Environment::set_sky);
  1009. ClassDB::bind_method(D_METHOD("get_sky"), &Environment::get_sky);
  1010. ClassDB::bind_method(D_METHOD("set_sky_custom_fov", "scale"), &Environment::set_sky_custom_fov);
  1011. ClassDB::bind_method(D_METHOD("get_sky_custom_fov"), &Environment::get_sky_custom_fov);
  1012. ClassDB::bind_method(D_METHOD("set_sky_rotation", "euler_radians"), &Environment::set_sky_rotation);
  1013. ClassDB::bind_method(D_METHOD("get_sky_rotation"), &Environment::get_sky_rotation);
  1014. ClassDB::bind_method(D_METHOD("set_bg_color", "color"), &Environment::set_bg_color);
  1015. ClassDB::bind_method(D_METHOD("get_bg_color"), &Environment::get_bg_color);
  1016. ClassDB::bind_method(D_METHOD("set_bg_energy_multiplier", "energy"), &Environment::set_bg_energy_multiplier);
  1017. ClassDB::bind_method(D_METHOD("get_bg_energy_multiplier"), &Environment::get_bg_energy_multiplier);
  1018. ClassDB::bind_method(D_METHOD("set_bg_intensity", "energy"), &Environment::set_bg_intensity);
  1019. ClassDB::bind_method(D_METHOD("get_bg_intensity"), &Environment::get_bg_intensity);
  1020. ClassDB::bind_method(D_METHOD("set_canvas_max_layer", "layer"), &Environment::set_canvas_max_layer);
  1021. ClassDB::bind_method(D_METHOD("get_canvas_max_layer"), &Environment::get_canvas_max_layer);
  1022. ClassDB::bind_method(D_METHOD("set_camera_feed_id", "id"), &Environment::set_camera_feed_id);
  1023. ClassDB::bind_method(D_METHOD("get_camera_feed_id"), &Environment::get_camera_feed_id);
  1024. ADD_GROUP("Background", "background_");
  1025. ADD_PROPERTY(PropertyInfo(Variant::INT, "background_mode", PROPERTY_HINT_ENUM, "Clear Color,Custom Color,Sky,Canvas,Keep,Camera Feed"), "set_background", "get_background");
  1026. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "background_color"), "set_bg_color", "get_bg_color");
  1027. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "background_energy_multiplier", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_bg_energy_multiplier", "get_bg_energy_multiplier");
  1028. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "background_intensity", PROPERTY_HINT_RANGE, "0,100000,0.01,suffix:nt"), "set_bg_intensity", "get_bg_intensity");
  1029. ADD_PROPERTY(PropertyInfo(Variant::INT, "background_canvas_max_layer", PROPERTY_HINT_RANGE, "-1000,1000,1"), "set_canvas_max_layer", "get_canvas_max_layer");
  1030. ADD_PROPERTY(PropertyInfo(Variant::INT, "background_camera_feed_id", PROPERTY_HINT_RANGE, "1,10,1"), "set_camera_feed_id", "get_camera_feed_id");
  1031. ADD_GROUP("Sky", "sky_");
  1032. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "sky", PROPERTY_HINT_RESOURCE_TYPE, "Sky"), "set_sky", "get_sky");
  1033. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sky_custom_fov", PROPERTY_HINT_RANGE, "0,180,0.1,degrees"), "set_sky_custom_fov", "get_sky_custom_fov");
  1034. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "sky_rotation", PROPERTY_HINT_RANGE, "-360,360,0.1,or_less,or_greater,radians_as_degrees"), "set_sky_rotation", "get_sky_rotation");
  1035. // Ambient light
  1036. ClassDB::bind_method(D_METHOD("set_ambient_light_color", "color"), &Environment::set_ambient_light_color);
  1037. ClassDB::bind_method(D_METHOD("get_ambient_light_color"), &Environment::get_ambient_light_color);
  1038. ClassDB::bind_method(D_METHOD("set_ambient_source", "source"), &Environment::set_ambient_source);
  1039. ClassDB::bind_method(D_METHOD("get_ambient_source"), &Environment::get_ambient_source);
  1040. ClassDB::bind_method(D_METHOD("set_ambient_light_energy", "energy"), &Environment::set_ambient_light_energy);
  1041. ClassDB::bind_method(D_METHOD("get_ambient_light_energy"), &Environment::get_ambient_light_energy);
  1042. ClassDB::bind_method(D_METHOD("set_ambient_light_sky_contribution", "ratio"), &Environment::set_ambient_light_sky_contribution);
  1043. ClassDB::bind_method(D_METHOD("get_ambient_light_sky_contribution"), &Environment::get_ambient_light_sky_contribution);
  1044. ClassDB::bind_method(D_METHOD("set_reflection_source", "source"), &Environment::set_reflection_source);
  1045. ClassDB::bind_method(D_METHOD("get_reflection_source"), &Environment::get_reflection_source);
  1046. ADD_GROUP("Ambient Light", "ambient_light_");
  1047. ADD_PROPERTY(PropertyInfo(Variant::INT, "ambient_light_source", PROPERTY_HINT_ENUM, "Background,Disabled,Color,Sky"), "set_ambient_source", "get_ambient_source");
  1048. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "ambient_light_color"), "set_ambient_light_color", "get_ambient_light_color");
  1049. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ambient_light_sky_contribution", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_ambient_light_sky_contribution", "get_ambient_light_sky_contribution");
  1050. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ambient_light_energy", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_ambient_light_energy", "get_ambient_light_energy");
  1051. ADD_GROUP("Reflected Light", "reflected_light_");
  1052. ADD_PROPERTY(PropertyInfo(Variant::INT, "reflected_light_source", PROPERTY_HINT_ENUM, "Background,Disabled,Sky"), "set_reflection_source", "get_reflection_source");
  1053. // Tonemap
  1054. ClassDB::bind_method(D_METHOD("set_tonemapper", "mode"), &Environment::set_tonemapper);
  1055. ClassDB::bind_method(D_METHOD("get_tonemapper"), &Environment::get_tonemapper);
  1056. ClassDB::bind_method(D_METHOD("set_tonemap_exposure", "exposure"), &Environment::set_tonemap_exposure);
  1057. ClassDB::bind_method(D_METHOD("get_tonemap_exposure"), &Environment::get_tonemap_exposure);
  1058. ClassDB::bind_method(D_METHOD("set_tonemap_white", "white"), &Environment::set_tonemap_white);
  1059. ClassDB::bind_method(D_METHOD("get_tonemap_white"), &Environment::get_tonemap_white);
  1060. ADD_GROUP("Tonemap", "tonemap_");
  1061. ADD_PROPERTY(PropertyInfo(Variant::INT, "tonemap_mode", PROPERTY_HINT_ENUM, "Linear,Reinhard,Filmic,ACES"), "set_tonemapper", "get_tonemapper");
  1062. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "tonemap_exposure", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_tonemap_exposure", "get_tonemap_exposure");
  1063. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "tonemap_white", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_tonemap_white", "get_tonemap_white");
  1064. // SSR
  1065. ClassDB::bind_method(D_METHOD("set_ssr_enabled", "enabled"), &Environment::set_ssr_enabled);
  1066. ClassDB::bind_method(D_METHOD("is_ssr_enabled"), &Environment::is_ssr_enabled);
  1067. ClassDB::bind_method(D_METHOD("set_ssr_max_steps", "max_steps"), &Environment::set_ssr_max_steps);
  1068. ClassDB::bind_method(D_METHOD("get_ssr_max_steps"), &Environment::get_ssr_max_steps);
  1069. ClassDB::bind_method(D_METHOD("set_ssr_fade_in", "fade_in"), &Environment::set_ssr_fade_in);
  1070. ClassDB::bind_method(D_METHOD("get_ssr_fade_in"), &Environment::get_ssr_fade_in);
  1071. ClassDB::bind_method(D_METHOD("set_ssr_fade_out", "fade_out"), &Environment::set_ssr_fade_out);
  1072. ClassDB::bind_method(D_METHOD("get_ssr_fade_out"), &Environment::get_ssr_fade_out);
  1073. ClassDB::bind_method(D_METHOD("set_ssr_depth_tolerance", "depth_tolerance"), &Environment::set_ssr_depth_tolerance);
  1074. ClassDB::bind_method(D_METHOD("get_ssr_depth_tolerance"), &Environment::get_ssr_depth_tolerance);
  1075. ADD_GROUP("SSR", "ssr_");
  1076. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ssr_enabled"), "set_ssr_enabled", "is_ssr_enabled");
  1077. ADD_PROPERTY(PropertyInfo(Variant::INT, "ssr_max_steps", PROPERTY_HINT_RANGE, "1,512,1"), "set_ssr_max_steps", "get_ssr_max_steps");
  1078. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ssr_fade_in", PROPERTY_HINT_EXP_EASING, "positive_only"), "set_ssr_fade_in", "get_ssr_fade_in");
  1079. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ssr_fade_out", PROPERTY_HINT_EXP_EASING, "positive_only"), "set_ssr_fade_out", "get_ssr_fade_out");
  1080. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ssr_depth_tolerance", PROPERTY_HINT_RANGE, "0.01,128,0.1"), "set_ssr_depth_tolerance", "get_ssr_depth_tolerance");
  1081. // SSAO
  1082. ClassDB::bind_method(D_METHOD("set_ssao_enabled", "enabled"), &Environment::set_ssao_enabled);
  1083. ClassDB::bind_method(D_METHOD("is_ssao_enabled"), &Environment::is_ssao_enabled);
  1084. ClassDB::bind_method(D_METHOD("set_ssao_radius", "radius"), &Environment::set_ssao_radius);
  1085. ClassDB::bind_method(D_METHOD("get_ssao_radius"), &Environment::get_ssao_radius);
  1086. ClassDB::bind_method(D_METHOD("set_ssao_intensity", "intensity"), &Environment::set_ssao_intensity);
  1087. ClassDB::bind_method(D_METHOD("get_ssao_intensity"), &Environment::get_ssao_intensity);
  1088. ClassDB::bind_method(D_METHOD("set_ssao_power", "power"), &Environment::set_ssao_power);
  1089. ClassDB::bind_method(D_METHOD("get_ssao_power"), &Environment::get_ssao_power);
  1090. ClassDB::bind_method(D_METHOD("set_ssao_detail", "detail"), &Environment::set_ssao_detail);
  1091. ClassDB::bind_method(D_METHOD("get_ssao_detail"), &Environment::get_ssao_detail);
  1092. ClassDB::bind_method(D_METHOD("set_ssao_horizon", "horizon"), &Environment::set_ssao_horizon);
  1093. ClassDB::bind_method(D_METHOD("get_ssao_horizon"), &Environment::get_ssao_horizon);
  1094. ClassDB::bind_method(D_METHOD("set_ssao_sharpness", "sharpness"), &Environment::set_ssao_sharpness);
  1095. ClassDB::bind_method(D_METHOD("get_ssao_sharpness"), &Environment::get_ssao_sharpness);
  1096. ClassDB::bind_method(D_METHOD("set_ssao_direct_light_affect", "amount"), &Environment::set_ssao_direct_light_affect);
  1097. ClassDB::bind_method(D_METHOD("get_ssao_direct_light_affect"), &Environment::get_ssao_direct_light_affect);
  1098. ClassDB::bind_method(D_METHOD("set_ssao_ao_channel_affect", "amount"), &Environment::set_ssao_ao_channel_affect);
  1099. ClassDB::bind_method(D_METHOD("get_ssao_ao_channel_affect"), &Environment::get_ssao_ao_channel_affect);
  1100. ADD_GROUP("SSAO", "ssao_");
  1101. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ssao_enabled"), "set_ssao_enabled", "is_ssao_enabled");
  1102. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ssao_radius", PROPERTY_HINT_RANGE, "0.01,16,0.01,or_greater"), "set_ssao_radius", "get_ssao_radius");
  1103. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ssao_intensity", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_ssao_intensity", "get_ssao_intensity");
  1104. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ssao_power", PROPERTY_HINT_EXP_EASING, "positive_only"), "set_ssao_power", "get_ssao_power");
  1105. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ssao_detail", PROPERTY_HINT_RANGE, "0,5,0.01"), "set_ssao_detail", "get_ssao_detail");
  1106. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ssao_horizon", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_ssao_horizon", "get_ssao_horizon");
  1107. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ssao_sharpness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_ssao_sharpness", "get_ssao_sharpness");
  1108. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ssao_light_affect", PROPERTY_HINT_RANGE, "0.00,1,0.01"), "set_ssao_direct_light_affect", "get_ssao_direct_light_affect");
  1109. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ssao_ao_channel_affect", PROPERTY_HINT_RANGE, "0.00,1,0.01"), "set_ssao_ao_channel_affect", "get_ssao_ao_channel_affect");
  1110. // SSIL
  1111. ClassDB::bind_method(D_METHOD("set_ssil_enabled", "enabled"), &Environment::set_ssil_enabled);
  1112. ClassDB::bind_method(D_METHOD("is_ssil_enabled"), &Environment::is_ssil_enabled);
  1113. ClassDB::bind_method(D_METHOD("set_ssil_radius", "radius"), &Environment::set_ssil_radius);
  1114. ClassDB::bind_method(D_METHOD("get_ssil_radius"), &Environment::get_ssil_radius);
  1115. ClassDB::bind_method(D_METHOD("set_ssil_intensity", "intensity"), &Environment::set_ssil_intensity);
  1116. ClassDB::bind_method(D_METHOD("get_ssil_intensity"), &Environment::get_ssil_intensity);
  1117. ClassDB::bind_method(D_METHOD("set_ssil_sharpness", "sharpness"), &Environment::set_ssil_sharpness);
  1118. ClassDB::bind_method(D_METHOD("get_ssil_sharpness"), &Environment::get_ssil_sharpness);
  1119. ClassDB::bind_method(D_METHOD("set_ssil_normal_rejection", "normal_rejection"), &Environment::set_ssil_normal_rejection);
  1120. ClassDB::bind_method(D_METHOD("get_ssil_normal_rejection"), &Environment::get_ssil_normal_rejection);
  1121. ADD_GROUP("SSIL", "ssil_");
  1122. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ssil_enabled"), "set_ssil_enabled", "is_ssil_enabled");
  1123. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ssil_radius", PROPERTY_HINT_RANGE, "0.01,16,0.01,or_greater,suffix:m"), "set_ssil_radius", "get_ssil_radius");
  1124. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ssil_intensity", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_ssil_intensity", "get_ssil_intensity");
  1125. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ssil_sharpness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_ssil_sharpness", "get_ssil_sharpness");
  1126. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ssil_normal_rejection", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_ssil_normal_rejection", "get_ssil_normal_rejection");
  1127. // SDFGI
  1128. ClassDB::bind_method(D_METHOD("set_sdfgi_enabled", "enabled"), &Environment::set_sdfgi_enabled);
  1129. ClassDB::bind_method(D_METHOD("is_sdfgi_enabled"), &Environment::is_sdfgi_enabled);
  1130. ClassDB::bind_method(D_METHOD("set_sdfgi_cascades", "amount"), &Environment::set_sdfgi_cascades);
  1131. ClassDB::bind_method(D_METHOD("get_sdfgi_cascades"), &Environment::get_sdfgi_cascades);
  1132. ClassDB::bind_method(D_METHOD("set_sdfgi_min_cell_size", "size"), &Environment::set_sdfgi_min_cell_size);
  1133. ClassDB::bind_method(D_METHOD("get_sdfgi_min_cell_size"), &Environment::get_sdfgi_min_cell_size);
  1134. ClassDB::bind_method(D_METHOD("set_sdfgi_max_distance", "distance"), &Environment::set_sdfgi_max_distance);
  1135. ClassDB::bind_method(D_METHOD("get_sdfgi_max_distance"), &Environment::get_sdfgi_max_distance);
  1136. ClassDB::bind_method(D_METHOD("set_sdfgi_cascade0_distance", "distance"), &Environment::set_sdfgi_cascade0_distance);
  1137. ClassDB::bind_method(D_METHOD("get_sdfgi_cascade0_distance"), &Environment::get_sdfgi_cascade0_distance);
  1138. ClassDB::bind_method(D_METHOD("set_sdfgi_y_scale", "scale"), &Environment::set_sdfgi_y_scale);
  1139. ClassDB::bind_method(D_METHOD("get_sdfgi_y_scale"), &Environment::get_sdfgi_y_scale);
  1140. ClassDB::bind_method(D_METHOD("set_sdfgi_use_occlusion", "enable"), &Environment::set_sdfgi_use_occlusion);
  1141. ClassDB::bind_method(D_METHOD("is_sdfgi_using_occlusion"), &Environment::is_sdfgi_using_occlusion);
  1142. ClassDB::bind_method(D_METHOD("set_sdfgi_bounce_feedback", "amount"), &Environment::set_sdfgi_bounce_feedback);
  1143. ClassDB::bind_method(D_METHOD("get_sdfgi_bounce_feedback"), &Environment::get_sdfgi_bounce_feedback);
  1144. ClassDB::bind_method(D_METHOD("set_sdfgi_read_sky_light", "enable"), &Environment::set_sdfgi_read_sky_light);
  1145. ClassDB::bind_method(D_METHOD("is_sdfgi_reading_sky_light"), &Environment::is_sdfgi_reading_sky_light);
  1146. ClassDB::bind_method(D_METHOD("set_sdfgi_energy", "amount"), &Environment::set_sdfgi_energy);
  1147. ClassDB::bind_method(D_METHOD("get_sdfgi_energy"), &Environment::get_sdfgi_energy);
  1148. ClassDB::bind_method(D_METHOD("set_sdfgi_normal_bias", "bias"), &Environment::set_sdfgi_normal_bias);
  1149. ClassDB::bind_method(D_METHOD("get_sdfgi_normal_bias"), &Environment::get_sdfgi_normal_bias);
  1150. ClassDB::bind_method(D_METHOD("set_sdfgi_probe_bias", "bias"), &Environment::set_sdfgi_probe_bias);
  1151. ClassDB::bind_method(D_METHOD("get_sdfgi_probe_bias"), &Environment::get_sdfgi_probe_bias);
  1152. ADD_GROUP("SDFGI", "sdfgi_");
  1153. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sdfgi_enabled"), "set_sdfgi_enabled", "is_sdfgi_enabled");
  1154. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sdfgi_use_occlusion"), "set_sdfgi_use_occlusion", "is_sdfgi_using_occlusion");
  1155. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sdfgi_read_sky_light"), "set_sdfgi_read_sky_light", "is_sdfgi_reading_sky_light");
  1156. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sdfgi_bounce_feedback", PROPERTY_HINT_RANGE, "0,1.99,0.01"), "set_sdfgi_bounce_feedback", "get_sdfgi_bounce_feedback");
  1157. ADD_PROPERTY(PropertyInfo(Variant::INT, "sdfgi_cascades", PROPERTY_HINT_RANGE, "1,8,1"), "set_sdfgi_cascades", "get_sdfgi_cascades");
  1158. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sdfgi_min_cell_size", PROPERTY_HINT_RANGE, "0.01,64,0.01"), "set_sdfgi_min_cell_size", "get_sdfgi_min_cell_size");
  1159. // Don't store the values of `sdfgi_cascade0_distance` and `sdfgi_max_distance`
  1160. // as they're derived from `sdfgi_min_cell_size`.
  1161. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sdfgi_cascade0_distance", PROPERTY_HINT_RANGE, "0.1,16384,0.1,or_greater", PROPERTY_USAGE_EDITOR), "set_sdfgi_cascade0_distance", "get_sdfgi_cascade0_distance");
  1162. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sdfgi_max_distance", PROPERTY_HINT_RANGE, "0.1,16384,0.1,or_greater", PROPERTY_USAGE_EDITOR), "set_sdfgi_max_distance", "get_sdfgi_max_distance");
  1163. ADD_PROPERTY(PropertyInfo(Variant::INT, "sdfgi_y_scale", PROPERTY_HINT_ENUM, "50% (Compact),75% (Balanced),100% (Sparse)"), "set_sdfgi_y_scale", "get_sdfgi_y_scale");
  1164. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sdfgi_energy"), "set_sdfgi_energy", "get_sdfgi_energy");
  1165. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sdfgi_normal_bias"), "set_sdfgi_normal_bias", "get_sdfgi_normal_bias");
  1166. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sdfgi_probe_bias"), "set_sdfgi_probe_bias", "get_sdfgi_probe_bias");
  1167. // Glow
  1168. ClassDB::bind_method(D_METHOD("set_glow_enabled", "enabled"), &Environment::set_glow_enabled);
  1169. ClassDB::bind_method(D_METHOD("is_glow_enabled"), &Environment::is_glow_enabled);
  1170. ClassDB::bind_method(D_METHOD("set_glow_level", "idx", "intensity"), &Environment::set_glow_level);
  1171. ClassDB::bind_method(D_METHOD("get_glow_level", "idx"), &Environment::get_glow_level);
  1172. ClassDB::bind_method(D_METHOD("set_glow_normalized", "normalize"), &Environment::set_glow_normalized);
  1173. ClassDB::bind_method(D_METHOD("is_glow_normalized"), &Environment::is_glow_normalized);
  1174. ClassDB::bind_method(D_METHOD("set_glow_intensity", "intensity"), &Environment::set_glow_intensity);
  1175. ClassDB::bind_method(D_METHOD("get_glow_intensity"), &Environment::get_glow_intensity);
  1176. ClassDB::bind_method(D_METHOD("set_glow_strength", "strength"), &Environment::set_glow_strength);
  1177. ClassDB::bind_method(D_METHOD("get_glow_strength"), &Environment::get_glow_strength);
  1178. ClassDB::bind_method(D_METHOD("set_glow_mix", "mix"), &Environment::set_glow_mix);
  1179. ClassDB::bind_method(D_METHOD("get_glow_mix"), &Environment::get_glow_mix);
  1180. ClassDB::bind_method(D_METHOD("set_glow_bloom", "amount"), &Environment::set_glow_bloom);
  1181. ClassDB::bind_method(D_METHOD("get_glow_bloom"), &Environment::get_glow_bloom);
  1182. ClassDB::bind_method(D_METHOD("set_glow_blend_mode", "mode"), &Environment::set_glow_blend_mode);
  1183. ClassDB::bind_method(D_METHOD("get_glow_blend_mode"), &Environment::get_glow_blend_mode);
  1184. ClassDB::bind_method(D_METHOD("set_glow_hdr_bleed_threshold", "threshold"), &Environment::set_glow_hdr_bleed_threshold);
  1185. ClassDB::bind_method(D_METHOD("get_glow_hdr_bleed_threshold"), &Environment::get_glow_hdr_bleed_threshold);
  1186. ClassDB::bind_method(D_METHOD("set_glow_hdr_bleed_scale", "scale"), &Environment::set_glow_hdr_bleed_scale);
  1187. ClassDB::bind_method(D_METHOD("get_glow_hdr_bleed_scale"), &Environment::get_glow_hdr_bleed_scale);
  1188. ClassDB::bind_method(D_METHOD("set_glow_hdr_luminance_cap", "amount"), &Environment::set_glow_hdr_luminance_cap);
  1189. ClassDB::bind_method(D_METHOD("get_glow_hdr_luminance_cap"), &Environment::get_glow_hdr_luminance_cap);
  1190. ClassDB::bind_method(D_METHOD("set_glow_map_strength", "strength"), &Environment::set_glow_map_strength);
  1191. ClassDB::bind_method(D_METHOD("get_glow_map_strength"), &Environment::get_glow_map_strength);
  1192. ClassDB::bind_method(D_METHOD("set_glow_map", "mode"), &Environment::set_glow_map);
  1193. ClassDB::bind_method(D_METHOD("get_glow_map"), &Environment::get_glow_map);
  1194. ADD_GROUP("Glow", "glow_");
  1195. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "glow_enabled"), "set_glow_enabled", "is_glow_enabled");
  1196. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "glow_levels/1", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_glow_level", "get_glow_level", 0);
  1197. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "glow_levels/2", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_glow_level", "get_glow_level", 1);
  1198. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "glow_levels/3", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_glow_level", "get_glow_level", 2);
  1199. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "glow_levels/4", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_glow_level", "get_glow_level", 3);
  1200. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "glow_levels/5", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_glow_level", "get_glow_level", 4);
  1201. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "glow_levels/6", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_glow_level", "get_glow_level", 5);
  1202. ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "glow_levels/7", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_glow_level", "get_glow_level", 6);
  1203. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "glow_normalized"), "set_glow_normalized", "is_glow_normalized");
  1204. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "glow_intensity", PROPERTY_HINT_RANGE, "0.0,8.0,0.01"), "set_glow_intensity", "get_glow_intensity");
  1205. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "glow_strength", PROPERTY_HINT_RANGE, "0.0,2.0,0.01"), "set_glow_strength", "get_glow_strength");
  1206. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "glow_mix", PROPERTY_HINT_RANGE, "0.0,1.0,0.001"), "set_glow_mix", "get_glow_mix");
  1207. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "glow_bloom", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), "set_glow_bloom", "get_glow_bloom");
  1208. ADD_PROPERTY(PropertyInfo(Variant::INT, "glow_blend_mode", PROPERTY_HINT_ENUM, "Additive,Screen,Softlight,Replace,Mix"), "set_glow_blend_mode", "get_glow_blend_mode");
  1209. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "glow_hdr_threshold", PROPERTY_HINT_RANGE, "0.0,4.0,0.01"), "set_glow_hdr_bleed_threshold", "get_glow_hdr_bleed_threshold");
  1210. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "glow_hdr_scale", PROPERTY_HINT_RANGE, "0.0,4.0,0.01"), "set_glow_hdr_bleed_scale", "get_glow_hdr_bleed_scale");
  1211. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "glow_hdr_luminance_cap", PROPERTY_HINT_RANGE, "0.0,256.0,0.01"), "set_glow_hdr_luminance_cap", "get_glow_hdr_luminance_cap");
  1212. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "glow_map_strength", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), "set_glow_map_strength", "get_glow_map_strength");
  1213. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "glow_map", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_glow_map", "get_glow_map");
  1214. // Fog
  1215. ClassDB::bind_method(D_METHOD("set_fog_enabled", "enabled"), &Environment::set_fog_enabled);
  1216. ClassDB::bind_method(D_METHOD("is_fog_enabled"), &Environment::is_fog_enabled);
  1217. ClassDB::bind_method(D_METHOD("set_fog_mode", "mode"), &Environment::set_fog_mode);
  1218. ClassDB::bind_method(D_METHOD("get_fog_mode"), &Environment::get_fog_mode);
  1219. ClassDB::bind_method(D_METHOD("set_fog_light_color", "light_color"), &Environment::set_fog_light_color);
  1220. ClassDB::bind_method(D_METHOD("get_fog_light_color"), &Environment::get_fog_light_color);
  1221. ClassDB::bind_method(D_METHOD("set_fog_light_energy", "light_energy"), &Environment::set_fog_light_energy);
  1222. ClassDB::bind_method(D_METHOD("get_fog_light_energy"), &Environment::get_fog_light_energy);
  1223. ClassDB::bind_method(D_METHOD("set_fog_sun_scatter", "sun_scatter"), &Environment::set_fog_sun_scatter);
  1224. ClassDB::bind_method(D_METHOD("get_fog_sun_scatter"), &Environment::get_fog_sun_scatter);
  1225. ClassDB::bind_method(D_METHOD("set_fog_density", "density"), &Environment::set_fog_density);
  1226. ClassDB::bind_method(D_METHOD("get_fog_density"), &Environment::get_fog_density);
  1227. ClassDB::bind_method(D_METHOD("set_fog_height", "height"), &Environment::set_fog_height);
  1228. ClassDB::bind_method(D_METHOD("get_fog_height"), &Environment::get_fog_height);
  1229. ClassDB::bind_method(D_METHOD("set_fog_height_density", "height_density"), &Environment::set_fog_height_density);
  1230. ClassDB::bind_method(D_METHOD("get_fog_height_density"), &Environment::get_fog_height_density);
  1231. ClassDB::bind_method(D_METHOD("set_fog_aerial_perspective", "aerial_perspective"), &Environment::set_fog_aerial_perspective);
  1232. ClassDB::bind_method(D_METHOD("get_fog_aerial_perspective"), &Environment::get_fog_aerial_perspective);
  1233. ClassDB::bind_method(D_METHOD("set_fog_sky_affect", "sky_affect"), &Environment::set_fog_sky_affect);
  1234. ClassDB::bind_method(D_METHOD("get_fog_sky_affect"), &Environment::get_fog_sky_affect);
  1235. ClassDB::bind_method(D_METHOD("set_fog_depth_curve", "curve"), &Environment::set_fog_depth_curve);
  1236. ClassDB::bind_method(D_METHOD("get_fog_depth_curve"), &Environment::get_fog_depth_curve);
  1237. ClassDB::bind_method(D_METHOD("set_fog_depth_begin", "begin"), &Environment::set_fog_depth_begin);
  1238. ClassDB::bind_method(D_METHOD("get_fog_depth_begin"), &Environment::get_fog_depth_begin);
  1239. ClassDB::bind_method(D_METHOD("set_fog_depth_end", "end"), &Environment::set_fog_depth_end);
  1240. ClassDB::bind_method(D_METHOD("get_fog_depth_end"), &Environment::get_fog_depth_end);
  1241. ADD_GROUP("Fog", "fog_");
  1242. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "fog_enabled"), "set_fog_enabled", "is_fog_enabled");
  1243. ADD_PROPERTY(PropertyInfo(Variant::INT, "fog_mode", PROPERTY_HINT_ENUM, "Exponential,Depth"), "set_fog_mode", "get_fog_mode");
  1244. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "fog_light_color", PROPERTY_HINT_COLOR_NO_ALPHA), "set_fog_light_color", "get_fog_light_color");
  1245. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fog_light_energy", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_fog_light_energy", "get_fog_light_energy");
  1246. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fog_sun_scatter", PROPERTY_HINT_RANGE, "0,1,0.01,or_greater"), "set_fog_sun_scatter", "get_fog_sun_scatter");
  1247. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fog_density", PROPERTY_HINT_RANGE, "0,1,0.0001,or_greater"), "set_fog_density", "get_fog_density");
  1248. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fog_aerial_perspective", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_fog_aerial_perspective", "get_fog_aerial_perspective");
  1249. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fog_sky_affect", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_fog_sky_affect", "get_fog_sky_affect");
  1250. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fog_height", PROPERTY_HINT_RANGE, "-1024,1024,0.01,or_less,or_greater,suffix:m"), "set_fog_height", "get_fog_height");
  1251. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fog_height_density", PROPERTY_HINT_RANGE, "-16,16,0.0001,or_less,or_greater"), "set_fog_height_density", "get_fog_height_density");
  1252. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fog_depth_curve", PROPERTY_HINT_EXP_EASING), "set_fog_depth_curve", "get_fog_depth_curve");
  1253. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fog_depth_begin", PROPERTY_HINT_RANGE, "0,4000,0.1,or_greater,or_less,suffix:m"), "set_fog_depth_begin", "get_fog_depth_begin");
  1254. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fog_depth_end", PROPERTY_HINT_RANGE, "0,4000,0.1,or_greater,or_less,suffix:m"), "set_fog_depth_end", "get_fog_depth_end");
  1255. ClassDB::bind_method(D_METHOD("set_volumetric_fog_enabled", "enabled"), &Environment::set_volumetric_fog_enabled);
  1256. ClassDB::bind_method(D_METHOD("is_volumetric_fog_enabled"), &Environment::is_volumetric_fog_enabled);
  1257. ClassDB::bind_method(D_METHOD("set_volumetric_fog_emission", "color"), &Environment::set_volumetric_fog_emission);
  1258. ClassDB::bind_method(D_METHOD("get_volumetric_fog_emission"), &Environment::get_volumetric_fog_emission);
  1259. ClassDB::bind_method(D_METHOD("set_volumetric_fog_albedo", "color"), &Environment::set_volumetric_fog_albedo);
  1260. ClassDB::bind_method(D_METHOD("get_volumetric_fog_albedo"), &Environment::get_volumetric_fog_albedo);
  1261. ClassDB::bind_method(D_METHOD("set_volumetric_fog_density", "density"), &Environment::set_volumetric_fog_density);
  1262. ClassDB::bind_method(D_METHOD("get_volumetric_fog_density"), &Environment::get_volumetric_fog_density);
  1263. ClassDB::bind_method(D_METHOD("set_volumetric_fog_emission_energy", "begin"), &Environment::set_volumetric_fog_emission_energy);
  1264. ClassDB::bind_method(D_METHOD("get_volumetric_fog_emission_energy"), &Environment::get_volumetric_fog_emission_energy);
  1265. ClassDB::bind_method(D_METHOD("set_volumetric_fog_anisotropy", "anisotropy"), &Environment::set_volumetric_fog_anisotropy);
  1266. ClassDB::bind_method(D_METHOD("get_volumetric_fog_anisotropy"), &Environment::get_volumetric_fog_anisotropy);
  1267. ClassDB::bind_method(D_METHOD("set_volumetric_fog_length", "length"), &Environment::set_volumetric_fog_length);
  1268. ClassDB::bind_method(D_METHOD("get_volumetric_fog_length"), &Environment::get_volumetric_fog_length);
  1269. ClassDB::bind_method(D_METHOD("set_volumetric_fog_detail_spread", "detail_spread"), &Environment::set_volumetric_fog_detail_spread);
  1270. ClassDB::bind_method(D_METHOD("get_volumetric_fog_detail_spread"), &Environment::get_volumetric_fog_detail_spread);
  1271. ClassDB::bind_method(D_METHOD("set_volumetric_fog_gi_inject", "gi_inject"), &Environment::set_volumetric_fog_gi_inject);
  1272. ClassDB::bind_method(D_METHOD("get_volumetric_fog_gi_inject"), &Environment::get_volumetric_fog_gi_inject);
  1273. ClassDB::bind_method(D_METHOD("set_volumetric_fog_ambient_inject", "enabled"), &Environment::set_volumetric_fog_ambient_inject);
  1274. ClassDB::bind_method(D_METHOD("get_volumetric_fog_ambient_inject"), &Environment::get_volumetric_fog_ambient_inject);
  1275. ClassDB::bind_method(D_METHOD("set_volumetric_fog_sky_affect", "sky_affect"), &Environment::set_volumetric_fog_sky_affect);
  1276. ClassDB::bind_method(D_METHOD("get_volumetric_fog_sky_affect"), &Environment::get_volumetric_fog_sky_affect);
  1277. ClassDB::bind_method(D_METHOD("set_volumetric_fog_temporal_reprojection_enabled", "enabled"), &Environment::set_volumetric_fog_temporal_reprojection_enabled);
  1278. ClassDB::bind_method(D_METHOD("is_volumetric_fog_temporal_reprojection_enabled"), &Environment::is_volumetric_fog_temporal_reprojection_enabled);
  1279. ClassDB::bind_method(D_METHOD("set_volumetric_fog_temporal_reprojection_amount", "temporal_reprojection_amount"), &Environment::set_volumetric_fog_temporal_reprojection_amount);
  1280. ClassDB::bind_method(D_METHOD("get_volumetric_fog_temporal_reprojection_amount"), &Environment::get_volumetric_fog_temporal_reprojection_amount);
  1281. ADD_GROUP("Volumetric Fog", "volumetric_fog_");
  1282. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "volumetric_fog_enabled"), "set_volumetric_fog_enabled", "is_volumetric_fog_enabled");
  1283. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volumetric_fog_density", PROPERTY_HINT_RANGE, "0,1,0.0001,or_greater"), "set_volumetric_fog_density", "get_volumetric_fog_density");
  1284. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "volumetric_fog_albedo", PROPERTY_HINT_COLOR_NO_ALPHA), "set_volumetric_fog_albedo", "get_volumetric_fog_albedo");
  1285. ADD_PROPERTY(PropertyInfo(Variant::COLOR, "volumetric_fog_emission", PROPERTY_HINT_COLOR_NO_ALPHA), "set_volumetric_fog_emission", "get_volumetric_fog_emission");
  1286. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volumetric_fog_emission_energy", PROPERTY_HINT_RANGE, "0,1024,0.01,or_greater"), "set_volumetric_fog_emission_energy", "get_volumetric_fog_emission_energy");
  1287. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volumetric_fog_gi_inject", PROPERTY_HINT_RANGE, "0.0,16,0.01,exp"), "set_volumetric_fog_gi_inject", "get_volumetric_fog_gi_inject");
  1288. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volumetric_fog_anisotropy", PROPERTY_HINT_RANGE, "-0.9,0.9,0.01"), "set_volumetric_fog_anisotropy", "get_volumetric_fog_anisotropy");
  1289. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volumetric_fog_length", PROPERTY_HINT_RANGE, "0.01,1024,0.01,or_greater,suffix:m"), "set_volumetric_fog_length", "get_volumetric_fog_length");
  1290. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volumetric_fog_detail_spread", PROPERTY_HINT_EXP_EASING, "positive_only"), "set_volumetric_fog_detail_spread", "get_volumetric_fog_detail_spread");
  1291. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volumetric_fog_ambient_inject", PROPERTY_HINT_RANGE, "0.0,16,0.01,exp"), "set_volumetric_fog_ambient_inject", "get_volumetric_fog_ambient_inject");
  1292. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volumetric_fog_sky_affect", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_volumetric_fog_sky_affect", "get_volumetric_fog_sky_affect");
  1293. ADD_SUBGROUP("Temporal Reprojection", "volumetric_fog_temporal_reprojection_");
  1294. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "volumetric_fog_temporal_reprojection_enabled"), "set_volumetric_fog_temporal_reprojection_enabled", "is_volumetric_fog_temporal_reprojection_enabled");
  1295. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volumetric_fog_temporal_reprojection_amount", PROPERTY_HINT_RANGE, "0.5,0.99,0.001"), "set_volumetric_fog_temporal_reprojection_amount", "get_volumetric_fog_temporal_reprojection_amount");
  1296. // Adjustment
  1297. ClassDB::bind_method(D_METHOD("set_adjustment_enabled", "enabled"), &Environment::set_adjustment_enabled);
  1298. ClassDB::bind_method(D_METHOD("is_adjustment_enabled"), &Environment::is_adjustment_enabled);
  1299. ClassDB::bind_method(D_METHOD("set_adjustment_brightness", "brightness"), &Environment::set_adjustment_brightness);
  1300. ClassDB::bind_method(D_METHOD("get_adjustment_brightness"), &Environment::get_adjustment_brightness);
  1301. ClassDB::bind_method(D_METHOD("set_adjustment_contrast", "contrast"), &Environment::set_adjustment_contrast);
  1302. ClassDB::bind_method(D_METHOD("get_adjustment_contrast"), &Environment::get_adjustment_contrast);
  1303. ClassDB::bind_method(D_METHOD("set_adjustment_saturation", "saturation"), &Environment::set_adjustment_saturation);
  1304. ClassDB::bind_method(D_METHOD("get_adjustment_saturation"), &Environment::get_adjustment_saturation);
  1305. ClassDB::bind_method(D_METHOD("set_adjustment_color_correction", "color_correction"), &Environment::set_adjustment_color_correction);
  1306. ClassDB::bind_method(D_METHOD("get_adjustment_color_correction"), &Environment::get_adjustment_color_correction);
  1307. ADD_GROUP("Adjustments", "adjustment_");
  1308. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "adjustment_enabled"), "set_adjustment_enabled", "is_adjustment_enabled");
  1309. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "adjustment_brightness", PROPERTY_HINT_RANGE, "0.01,8,0.01"), "set_adjustment_brightness", "get_adjustment_brightness");
  1310. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "adjustment_contrast", PROPERTY_HINT_RANGE, "0.01,8,0.01"), "set_adjustment_contrast", "get_adjustment_contrast");
  1311. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "adjustment_saturation", PROPERTY_HINT_RANGE, "0.01,8,0.01"), "set_adjustment_saturation", "get_adjustment_saturation");
  1312. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "adjustment_color_correction", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D,Texture3D"), "set_adjustment_color_correction", "get_adjustment_color_correction");
  1313. // Constants
  1314. BIND_ENUM_CONSTANT(BG_CLEAR_COLOR);
  1315. BIND_ENUM_CONSTANT(BG_COLOR);
  1316. BIND_ENUM_CONSTANT(BG_SKY);
  1317. BIND_ENUM_CONSTANT(BG_CANVAS);
  1318. BIND_ENUM_CONSTANT(BG_KEEP);
  1319. BIND_ENUM_CONSTANT(BG_CAMERA_FEED);
  1320. BIND_ENUM_CONSTANT(BG_MAX);
  1321. BIND_ENUM_CONSTANT(AMBIENT_SOURCE_BG);
  1322. BIND_ENUM_CONSTANT(AMBIENT_SOURCE_DISABLED);
  1323. BIND_ENUM_CONSTANT(AMBIENT_SOURCE_COLOR);
  1324. BIND_ENUM_CONSTANT(AMBIENT_SOURCE_SKY);
  1325. BIND_ENUM_CONSTANT(REFLECTION_SOURCE_BG);
  1326. BIND_ENUM_CONSTANT(REFLECTION_SOURCE_DISABLED);
  1327. BIND_ENUM_CONSTANT(REFLECTION_SOURCE_SKY);
  1328. BIND_ENUM_CONSTANT(TONE_MAPPER_LINEAR);
  1329. BIND_ENUM_CONSTANT(TONE_MAPPER_REINHARDT);
  1330. BIND_ENUM_CONSTANT(TONE_MAPPER_FILMIC);
  1331. BIND_ENUM_CONSTANT(TONE_MAPPER_ACES);
  1332. BIND_ENUM_CONSTANT(GLOW_BLEND_MODE_ADDITIVE);
  1333. BIND_ENUM_CONSTANT(GLOW_BLEND_MODE_SCREEN);
  1334. BIND_ENUM_CONSTANT(GLOW_BLEND_MODE_SOFTLIGHT);
  1335. BIND_ENUM_CONSTANT(GLOW_BLEND_MODE_REPLACE);
  1336. BIND_ENUM_CONSTANT(GLOW_BLEND_MODE_MIX);
  1337. BIND_ENUM_CONSTANT(FOG_MODE_EXPONENTIAL);
  1338. BIND_ENUM_CONSTANT(FOG_MODE_DEPTH);
  1339. BIND_ENUM_CONSTANT(SDFGI_Y_SCALE_50_PERCENT);
  1340. BIND_ENUM_CONSTANT(SDFGI_Y_SCALE_75_PERCENT);
  1341. BIND_ENUM_CONSTANT(SDFGI_Y_SCALE_100_PERCENT);
  1342. }
  1343. Environment::Environment() {
  1344. environment = RS::get_singleton()->environment_create();
  1345. set_camera_feed_id(bg_camera_feed_id);
  1346. glow_levels.resize(7);
  1347. glow_levels.write[0] = 0.0;
  1348. glow_levels.write[1] = 0.0;
  1349. glow_levels.write[2] = 1.0;
  1350. glow_levels.write[3] = 0.0;
  1351. glow_levels.write[4] = 1.0;
  1352. glow_levels.write[5] = 0.0;
  1353. glow_levels.write[6] = 0.0;
  1354. _update_ambient_light();
  1355. _update_tonemap();
  1356. _update_ssr();
  1357. _update_ssao();
  1358. _update_ssil();
  1359. _update_sdfgi();
  1360. _update_glow();
  1361. _update_fog();
  1362. _update_adjustment();
  1363. _update_volumetric_fog();
  1364. _update_bg_energy();
  1365. notify_property_list_changed();
  1366. }
  1367. Environment::~Environment() {
  1368. ERR_FAIL_NULL(RenderingServer::get_singleton());
  1369. RS::get_singleton()->free(environment);
  1370. }