environment.cpp 62 KB

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