environment_storage.cpp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. /**************************************************************************/
  2. /* environment_storage.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_storage.h"
  31. RID RendererEnvironmentStorage::environment_allocate() {
  32. return environment_owner.allocate_rid();
  33. }
  34. void RendererEnvironmentStorage::environment_initialize(RID p_rid) {
  35. environment_owner.initialize_rid(p_rid, Environment());
  36. }
  37. void RendererEnvironmentStorage::environment_free(RID p_rid) {
  38. environment_owner.free(p_rid);
  39. }
  40. // Background
  41. void RendererEnvironmentStorage::environment_set_background(RID p_env, RS::EnvironmentBG p_bg) {
  42. Environment *env = environment_owner.get_or_null(p_env);
  43. ERR_FAIL_NULL(env);
  44. env->background = p_bg;
  45. }
  46. void RendererEnvironmentStorage::environment_set_sky(RID p_env, RID p_sky) {
  47. Environment *env = environment_owner.get_or_null(p_env);
  48. ERR_FAIL_NULL(env);
  49. env->sky = p_sky;
  50. }
  51. void RendererEnvironmentStorage::environment_set_sky_custom_fov(RID p_env, float p_scale) {
  52. Environment *env = environment_owner.get_or_null(p_env);
  53. ERR_FAIL_NULL(env);
  54. env->sky_custom_fov = p_scale;
  55. }
  56. void RendererEnvironmentStorage::environment_set_sky_orientation(RID p_env, const Basis &p_orientation) {
  57. Environment *env = environment_owner.get_or_null(p_env);
  58. ERR_FAIL_NULL(env);
  59. env->sky_orientation = p_orientation;
  60. }
  61. void RendererEnvironmentStorage::environment_set_bg_color(RID p_env, const Color &p_color) {
  62. Environment *env = environment_owner.get_or_null(p_env);
  63. ERR_FAIL_NULL(env);
  64. env->bg_color = p_color;
  65. }
  66. void RendererEnvironmentStorage::environment_set_bg_energy(RID p_env, float p_multiplier, float p_intensity) {
  67. Environment *env = environment_owner.get_or_null(p_env);
  68. ERR_FAIL_NULL(env);
  69. env->bg_energy_multiplier = p_multiplier;
  70. env->bg_intensity = p_intensity;
  71. }
  72. void RendererEnvironmentStorage::environment_set_canvas_max_layer(RID p_env, int p_max_layer) {
  73. Environment *env = environment_owner.get_or_null(p_env);
  74. ERR_FAIL_NULL(env);
  75. env->canvas_max_layer = p_max_layer;
  76. }
  77. void RendererEnvironmentStorage::environment_set_ambient_light(RID p_env, const Color &p_color, RS::EnvironmentAmbientSource p_ambient, float p_energy, float p_sky_contribution, RS::EnvironmentReflectionSource p_reflection_source) {
  78. Environment *env = environment_owner.get_or_null(p_env);
  79. ERR_FAIL_NULL(env);
  80. env->ambient_light = p_color;
  81. env->ambient_source = p_ambient;
  82. env->ambient_light_energy = p_energy;
  83. env->ambient_sky_contribution = p_sky_contribution;
  84. env->reflection_source = p_reflection_source;
  85. }
  86. RS::EnvironmentBG RendererEnvironmentStorage::environment_get_background(RID p_env) const {
  87. Environment *env = environment_owner.get_or_null(p_env);
  88. ERR_FAIL_NULL_V(env, RS::ENV_BG_CLEAR_COLOR);
  89. return env->background;
  90. }
  91. RID RendererEnvironmentStorage::environment_get_sky(RID p_env) const {
  92. Environment *env = environment_owner.get_or_null(p_env);
  93. ERR_FAIL_NULL_V(env, RID());
  94. return env->sky;
  95. }
  96. float RendererEnvironmentStorage::environment_get_sky_custom_fov(RID p_env) const {
  97. Environment *env = environment_owner.get_or_null(p_env);
  98. ERR_FAIL_NULL_V(env, 0.0);
  99. return env->sky_custom_fov;
  100. }
  101. Basis RendererEnvironmentStorage::environment_get_sky_orientation(RID p_env) const {
  102. Environment *env = environment_owner.get_or_null(p_env);
  103. ERR_FAIL_NULL_V(env, Basis());
  104. return env->sky_orientation;
  105. }
  106. Color RendererEnvironmentStorage::environment_get_bg_color(RID p_env) const {
  107. Environment *env = environment_owner.get_or_null(p_env);
  108. ERR_FAIL_NULL_V(env, Color());
  109. return env->bg_color;
  110. }
  111. float RendererEnvironmentStorage::environment_get_bg_energy_multiplier(RID p_env) const {
  112. Environment *env = environment_owner.get_or_null(p_env);
  113. ERR_FAIL_NULL_V(env, 1.0);
  114. return env->bg_energy_multiplier;
  115. }
  116. float RendererEnvironmentStorage::environment_get_bg_intensity(RID p_env) const {
  117. Environment *env = environment_owner.get_or_null(p_env);
  118. ERR_FAIL_NULL_V(env, 1.0);
  119. return env->bg_intensity;
  120. }
  121. int RendererEnvironmentStorage::environment_get_canvas_max_layer(RID p_env) const {
  122. Environment *env = environment_owner.get_or_null(p_env);
  123. ERR_FAIL_NULL_V(env, 0);
  124. return env->canvas_max_layer;
  125. }
  126. RS::EnvironmentAmbientSource RendererEnvironmentStorage::environment_get_ambient_source(RID p_env) const {
  127. Environment *env = environment_owner.get_or_null(p_env);
  128. ERR_FAIL_NULL_V(env, RS::ENV_AMBIENT_SOURCE_BG);
  129. return env->ambient_source;
  130. }
  131. Color RendererEnvironmentStorage::environment_get_ambient_light(RID p_env) const {
  132. Environment *env = environment_owner.get_or_null(p_env);
  133. ERR_FAIL_NULL_V(env, Color());
  134. return env->ambient_light;
  135. }
  136. float RendererEnvironmentStorage::environment_get_ambient_light_energy(RID p_env) const {
  137. Environment *env = environment_owner.get_or_null(p_env);
  138. ERR_FAIL_NULL_V(env, 1.0);
  139. return env->ambient_light_energy;
  140. }
  141. float RendererEnvironmentStorage::environment_get_ambient_sky_contribution(RID p_env) const {
  142. Environment *env = environment_owner.get_or_null(p_env);
  143. ERR_FAIL_NULL_V(env, 1.0);
  144. return env->ambient_sky_contribution;
  145. }
  146. RS::EnvironmentReflectionSource RendererEnvironmentStorage::environment_get_reflection_source(RID p_env) const {
  147. Environment *env = environment_owner.get_or_null(p_env);
  148. ERR_FAIL_NULL_V(env, RS::ENV_REFLECTION_SOURCE_BG);
  149. return env->reflection_source;
  150. }
  151. // Tonemap
  152. void RendererEnvironmentStorage::environment_set_tonemap(RID p_env, RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white) {
  153. Environment *env = environment_owner.get_or_null(p_env);
  154. ERR_FAIL_NULL(env);
  155. env->exposure = p_exposure;
  156. env->tone_mapper = p_tone_mapper;
  157. env->white = p_white;
  158. }
  159. RS::EnvironmentToneMapper RendererEnvironmentStorage::environment_get_tone_mapper(RID p_env) const {
  160. Environment *env = environment_owner.get_or_null(p_env);
  161. ERR_FAIL_NULL_V(env, RS::ENV_TONE_MAPPER_LINEAR);
  162. return env->tone_mapper;
  163. }
  164. float RendererEnvironmentStorage::environment_get_exposure(RID p_env) const {
  165. Environment *env = environment_owner.get_or_null(p_env);
  166. ERR_FAIL_NULL_V(env, 1.0);
  167. return env->exposure;
  168. }
  169. float RendererEnvironmentStorage::environment_get_white(RID p_env) const {
  170. Environment *env = environment_owner.get_or_null(p_env);
  171. ERR_FAIL_NULL_V(env, 1.0);
  172. return env->white;
  173. }
  174. // Fog
  175. void RendererEnvironmentStorage::environment_set_fog(RID p_env, bool p_enable, const Color &p_light_color, float p_light_energy, float p_sun_scatter, float p_density, float p_height, float p_height_density, float p_fog_aerial_perspective, float p_sky_affect) {
  176. Environment *env = environment_owner.get_or_null(p_env);
  177. ERR_FAIL_NULL(env);
  178. env->fog_enabled = p_enable;
  179. env->fog_light_color = p_light_color;
  180. env->fog_light_energy = p_light_energy;
  181. env->fog_sun_scatter = p_sun_scatter;
  182. env->fog_density = p_density;
  183. env->fog_height = p_height;
  184. env->fog_height_density = p_height_density;
  185. env->fog_aerial_perspective = p_fog_aerial_perspective;
  186. env->fog_sky_affect = p_sky_affect;
  187. }
  188. bool RendererEnvironmentStorage::environment_get_fog_enabled(RID p_env) const {
  189. Environment *env = environment_owner.get_or_null(p_env);
  190. ERR_FAIL_NULL_V(env, false);
  191. return env->fog_enabled;
  192. }
  193. Color RendererEnvironmentStorage::environment_get_fog_light_color(RID p_env) const {
  194. Environment *env = environment_owner.get_or_null(p_env);
  195. ERR_FAIL_NULL_V(env, Color(0.5, 0.6, 0.7));
  196. return env->fog_light_color;
  197. }
  198. float RendererEnvironmentStorage::environment_get_fog_light_energy(RID p_env) const {
  199. Environment *env = environment_owner.get_or_null(p_env);
  200. ERR_FAIL_NULL_V(env, 1.0);
  201. return env->fog_light_energy;
  202. }
  203. float RendererEnvironmentStorage::environment_get_fog_sun_scatter(RID p_env) const {
  204. Environment *env = environment_owner.get_or_null(p_env);
  205. ERR_FAIL_NULL_V(env, 0.0);
  206. return env->fog_sun_scatter;
  207. }
  208. float RendererEnvironmentStorage::environment_get_fog_density(RID p_env) const {
  209. Environment *env = environment_owner.get_or_null(p_env);
  210. ERR_FAIL_NULL_V(env, 0.001);
  211. return env->fog_density;
  212. }
  213. float RendererEnvironmentStorage::environment_get_fog_height(RID p_env) const {
  214. Environment *env = environment_owner.get_or_null(p_env);
  215. ERR_FAIL_NULL_V(env, 0.0);
  216. return env->fog_height;
  217. }
  218. float RendererEnvironmentStorage::environment_get_fog_height_density(RID p_env) const {
  219. Environment *env = environment_owner.get_or_null(p_env);
  220. ERR_FAIL_NULL_V(env, 0.0);
  221. return env->fog_height_density;
  222. }
  223. float RendererEnvironmentStorage::environment_get_fog_aerial_perspective(RID p_env) const {
  224. Environment *env = environment_owner.get_or_null(p_env);
  225. ERR_FAIL_NULL_V(env, 0.0);
  226. return env->fog_aerial_perspective;
  227. }
  228. float RendererEnvironmentStorage::environment_get_fog_sky_affect(RID p_env) const {
  229. Environment *env = environment_owner.get_or_null(p_env);
  230. ERR_FAIL_NULL_V(env, 0.0);
  231. return env->fog_sky_affect;
  232. }
  233. // Volumetric Fog
  234. void RendererEnvironmentStorage::environment_set_volumetric_fog(RID p_env, bool p_enable, float p_density, const Color &p_albedo, const Color &p_emission, float p_emission_energy, float p_anisotropy, float p_length, float p_detail_spread, float p_gi_inject, bool p_temporal_reprojection, float p_temporal_reprojection_amount, float p_ambient_inject, float p_sky_affect) {
  235. Environment *env = environment_owner.get_or_null(p_env);
  236. ERR_FAIL_NULL(env);
  237. #ifdef DEBUG_ENABLED
  238. if (OS::get_singleton()->get_current_rendering_method() != "forward_plus" && p_enable) {
  239. WARN_PRINT_ONCE_ED("Volumetric fog can only be enabled when using the Forward+ rendering backend.");
  240. }
  241. #endif
  242. env->volumetric_fog_enabled = p_enable;
  243. env->volumetric_fog_density = p_density;
  244. env->volumetric_fog_scattering = p_albedo;
  245. env->volumetric_fog_emission = p_emission;
  246. env->volumetric_fog_emission_energy = p_emission_energy;
  247. env->volumetric_fog_anisotropy = p_anisotropy;
  248. env->volumetric_fog_length = p_length;
  249. env->volumetric_fog_detail_spread = p_detail_spread;
  250. env->volumetric_fog_gi_inject = p_gi_inject;
  251. env->volumetric_fog_temporal_reprojection = p_temporal_reprojection;
  252. env->volumetric_fog_temporal_reprojection_amount = p_temporal_reprojection_amount;
  253. env->volumetric_fog_ambient_inject = p_ambient_inject;
  254. env->volumetric_fog_sky_affect = p_sky_affect;
  255. }
  256. bool RendererEnvironmentStorage::environment_get_volumetric_fog_enabled(RID p_env) const {
  257. Environment *env = environment_owner.get_or_null(p_env);
  258. ERR_FAIL_NULL_V(env, false);
  259. return env->volumetric_fog_enabled;
  260. }
  261. float RendererEnvironmentStorage::environment_get_volumetric_fog_density(RID p_env) const {
  262. Environment *env = environment_owner.get_or_null(p_env);
  263. ERR_FAIL_NULL_V(env, 0.01);
  264. return env->volumetric_fog_density;
  265. }
  266. Color RendererEnvironmentStorage::environment_get_volumetric_fog_scattering(RID p_env) const {
  267. Environment *env = environment_owner.get_or_null(p_env);
  268. ERR_FAIL_NULL_V(env, Color(1, 1, 1));
  269. return env->volumetric_fog_scattering;
  270. }
  271. Color RendererEnvironmentStorage::environment_get_volumetric_fog_emission(RID p_env) const {
  272. Environment *env = environment_owner.get_or_null(p_env);
  273. ERR_FAIL_NULL_V(env, Color(0, 0, 0));
  274. return env->volumetric_fog_emission;
  275. }
  276. float RendererEnvironmentStorage::environment_get_volumetric_fog_emission_energy(RID p_env) const {
  277. Environment *env = environment_owner.get_or_null(p_env);
  278. ERR_FAIL_NULL_V(env, 0.0);
  279. return env->volumetric_fog_emission_energy;
  280. }
  281. float RendererEnvironmentStorage::environment_get_volumetric_fog_anisotropy(RID p_env) const {
  282. Environment *env = environment_owner.get_or_null(p_env);
  283. ERR_FAIL_NULL_V(env, 0.2);
  284. return env->volumetric_fog_anisotropy;
  285. }
  286. float RendererEnvironmentStorage::environment_get_volumetric_fog_length(RID p_env) const {
  287. Environment *env = environment_owner.get_or_null(p_env);
  288. ERR_FAIL_NULL_V(env, 64.0);
  289. return env->volumetric_fog_length;
  290. }
  291. float RendererEnvironmentStorage::environment_get_volumetric_fog_detail_spread(RID p_env) const {
  292. Environment *env = environment_owner.get_or_null(p_env);
  293. ERR_FAIL_NULL_V(env, 2.0);
  294. return env->volumetric_fog_detail_spread;
  295. }
  296. float RendererEnvironmentStorage::environment_get_volumetric_fog_gi_inject(RID p_env) const {
  297. Environment *env = environment_owner.get_or_null(p_env);
  298. ERR_FAIL_NULL_V(env, 0.0);
  299. return env->volumetric_fog_gi_inject;
  300. }
  301. float RendererEnvironmentStorage::environment_get_volumetric_fog_sky_affect(RID p_env) const {
  302. Environment *env = environment_owner.get_or_null(p_env);
  303. ERR_FAIL_NULL_V(env, 0.0);
  304. return env->volumetric_fog_sky_affect;
  305. }
  306. bool RendererEnvironmentStorage::environment_get_volumetric_fog_temporal_reprojection(RID p_env) const {
  307. Environment *env = environment_owner.get_or_null(p_env);
  308. ERR_FAIL_NULL_V(env, true);
  309. return env->volumetric_fog_temporal_reprojection;
  310. }
  311. float RendererEnvironmentStorage::environment_get_volumetric_fog_temporal_reprojection_amount(RID p_env) const {
  312. Environment *env = environment_owner.get_or_null(p_env);
  313. ERR_FAIL_NULL_V(env, 0.9);
  314. return env->volumetric_fog_temporal_reprojection_amount;
  315. }
  316. float RendererEnvironmentStorage::environment_get_volumetric_fog_ambient_inject(RID p_env) const {
  317. Environment *env = environment_owner.get_or_null(p_env);
  318. ERR_FAIL_NULL_V(env, 0.0);
  319. return env->volumetric_fog_ambient_inject;
  320. }
  321. // GLOW
  322. void RendererEnvironmentStorage::environment_set_glow(RID p_env, bool p_enable, Vector<float> p_levels, float p_intensity, float p_strength, float p_mix, float p_bloom_threshold, RS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap, float p_glow_map_strength, RID p_glow_map) {
  323. Environment *env = environment_owner.get_or_null(p_env);
  324. ERR_FAIL_NULL(env);
  325. ERR_FAIL_COND_MSG(p_levels.size() != 7, "Size of array of glow levels must be 7");
  326. #ifdef DEBUG_ENABLED
  327. if (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility" && p_enable) {
  328. WARN_PRINT_ONCE_ED("Glow is not supported when using the GL Compatibility backend yet. Support will be added in a future release.");
  329. }
  330. #endif
  331. env->glow_enabled = p_enable;
  332. env->glow_levels = p_levels;
  333. env->glow_intensity = p_intensity;
  334. env->glow_strength = p_strength;
  335. env->glow_mix = p_mix;
  336. env->glow_bloom = p_bloom_threshold;
  337. env->glow_blend_mode = p_blend_mode;
  338. env->glow_hdr_bleed_threshold = p_hdr_bleed_threshold;
  339. env->glow_hdr_bleed_scale = p_hdr_bleed_scale;
  340. env->glow_hdr_luminance_cap = p_hdr_luminance_cap;
  341. env->glow_map_strength = p_glow_map_strength;
  342. env->glow_map = p_glow_map;
  343. }
  344. bool RendererEnvironmentStorage::environment_get_glow_enabled(RID p_env) const {
  345. Environment *env = environment_owner.get_or_null(p_env);
  346. ERR_FAIL_NULL_V(env, false);
  347. return env->glow_enabled;
  348. }
  349. Vector<float> RendererEnvironmentStorage::environment_get_glow_levels(RID p_env) const {
  350. Environment *env = environment_owner.get_or_null(p_env);
  351. ERR_FAIL_NULL_V(env, Vector<float>());
  352. return env->glow_levels;
  353. }
  354. float RendererEnvironmentStorage::environment_get_glow_intensity(RID p_env) const {
  355. Environment *env = environment_owner.get_or_null(p_env);
  356. ERR_FAIL_NULL_V(env, 0.8);
  357. return env->glow_intensity;
  358. }
  359. float RendererEnvironmentStorage::environment_get_glow_strength(RID p_env) const {
  360. Environment *env = environment_owner.get_or_null(p_env);
  361. ERR_FAIL_NULL_V(env, 1.0);
  362. return env->glow_strength;
  363. }
  364. float RendererEnvironmentStorage::environment_get_glow_bloom(RID p_env) const {
  365. Environment *env = environment_owner.get_or_null(p_env);
  366. ERR_FAIL_NULL_V(env, 0.0);
  367. return env->glow_bloom;
  368. }
  369. float RendererEnvironmentStorage::environment_get_glow_mix(RID p_env) const {
  370. Environment *env = environment_owner.get_or_null(p_env);
  371. ERR_FAIL_NULL_V(env, 0.01);
  372. return env->glow_mix;
  373. }
  374. RS::EnvironmentGlowBlendMode RendererEnvironmentStorage::environment_get_glow_blend_mode(RID p_env) const {
  375. Environment *env = environment_owner.get_or_null(p_env);
  376. ERR_FAIL_NULL_V(env, RS::ENV_GLOW_BLEND_MODE_SOFTLIGHT);
  377. return env->glow_blend_mode;
  378. }
  379. float RendererEnvironmentStorage::environment_get_glow_hdr_bleed_threshold(RID p_env) const {
  380. Environment *env = environment_owner.get_or_null(p_env);
  381. ERR_FAIL_NULL_V(env, 1.0);
  382. return env->glow_hdr_bleed_threshold;
  383. }
  384. float RendererEnvironmentStorage::environment_get_glow_hdr_luminance_cap(RID p_env) const {
  385. Environment *env = environment_owner.get_or_null(p_env);
  386. ERR_FAIL_NULL_V(env, 12.0);
  387. return env->glow_hdr_luminance_cap;
  388. }
  389. float RendererEnvironmentStorage::environment_get_glow_hdr_bleed_scale(RID p_env) const {
  390. Environment *env = environment_owner.get_or_null(p_env);
  391. ERR_FAIL_NULL_V(env, 2.0);
  392. return env->glow_hdr_bleed_scale;
  393. }
  394. float RendererEnvironmentStorage::environment_get_glow_map_strength(RID p_env) const {
  395. Environment *env = environment_owner.get_or_null(p_env);
  396. ERR_FAIL_NULL_V(env, 0.0);
  397. return env->glow_map_strength;
  398. }
  399. RID RendererEnvironmentStorage::environment_get_glow_map(RID p_env) const {
  400. Environment *env = environment_owner.get_or_null(p_env);
  401. ERR_FAIL_NULL_V(env, RID());
  402. return env->glow_map;
  403. }
  404. // SSR
  405. void RendererEnvironmentStorage::environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_int, float p_fade_out, float p_depth_tolerance) {
  406. Environment *env = environment_owner.get_or_null(p_env);
  407. ERR_FAIL_NULL(env);
  408. #ifdef DEBUG_ENABLED
  409. if (OS::get_singleton()->get_current_rendering_method() != "forward_plus" && p_enable) {
  410. WARN_PRINT_ONCE_ED("Screen-space reflections (SSR) can only be enabled when using the Forward+ rendering backend.");
  411. }
  412. #endif
  413. env->ssr_enabled = p_enable;
  414. env->ssr_max_steps = p_max_steps;
  415. env->ssr_fade_in = p_fade_int;
  416. env->ssr_fade_out = p_fade_out;
  417. env->ssr_depth_tolerance = p_depth_tolerance;
  418. }
  419. bool RendererEnvironmentStorage::environment_get_ssr_enabled(RID p_env) const {
  420. Environment *env = environment_owner.get_or_null(p_env);
  421. ERR_FAIL_NULL_V(env, false);
  422. return env->ssr_enabled;
  423. }
  424. int RendererEnvironmentStorage::environment_get_ssr_max_steps(RID p_env) const {
  425. Environment *env = environment_owner.get_or_null(p_env);
  426. ERR_FAIL_NULL_V(env, 64);
  427. return env->ssr_max_steps;
  428. }
  429. float RendererEnvironmentStorage::environment_get_ssr_fade_in(RID p_env) const {
  430. Environment *env = environment_owner.get_or_null(p_env);
  431. ERR_FAIL_NULL_V(env, 0.15);
  432. return env->ssr_fade_in;
  433. }
  434. float RendererEnvironmentStorage::environment_get_ssr_fade_out(RID p_env) const {
  435. Environment *env = environment_owner.get_or_null(p_env);
  436. ERR_FAIL_NULL_V(env, 2.0);
  437. return env->ssr_fade_out;
  438. }
  439. float RendererEnvironmentStorage::environment_get_ssr_depth_tolerance(RID p_env) const {
  440. Environment *env = environment_owner.get_or_null(p_env);
  441. ERR_FAIL_NULL_V(env, 0.2);
  442. return env->ssr_depth_tolerance;
  443. }
  444. // SSAO
  445. void RendererEnvironmentStorage::environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_power, float p_detail, float p_horizon, float p_sharpness, float p_light_affect, float p_ao_channel_affect) {
  446. Environment *env = environment_owner.get_or_null(p_env);
  447. ERR_FAIL_NULL(env);
  448. #ifdef DEBUG_ENABLED
  449. if (OS::get_singleton()->get_current_rendering_method() != "forward_plus" && p_enable) {
  450. WARN_PRINT_ONCE_ED("Screen-space ambient occlusion (SSAO) can only be enabled when using the Forward+ rendering backend.");
  451. }
  452. #endif
  453. env->ssao_enabled = p_enable;
  454. env->ssao_radius = p_radius;
  455. env->ssao_intensity = p_intensity;
  456. env->ssao_power = p_power;
  457. env->ssao_detail = p_detail;
  458. env->ssao_horizon = p_horizon;
  459. env->ssao_sharpness = p_sharpness;
  460. env->ssao_direct_light_affect = p_light_affect;
  461. env->ssao_ao_channel_affect = p_ao_channel_affect;
  462. }
  463. bool RendererEnvironmentStorage::environment_get_ssao_enabled(RID p_env) const {
  464. Environment *env = environment_owner.get_or_null(p_env);
  465. ERR_FAIL_NULL_V(env, false);
  466. return env->ssao_enabled;
  467. }
  468. float RendererEnvironmentStorage::environment_get_ssao_radius(RID p_env) const {
  469. Environment *env = environment_owner.get_or_null(p_env);
  470. ERR_FAIL_NULL_V(env, 1.0);
  471. return env->ssao_radius;
  472. }
  473. float RendererEnvironmentStorage::environment_get_ssao_intensity(RID p_env) const {
  474. Environment *env = environment_owner.get_or_null(p_env);
  475. ERR_FAIL_NULL_V(env, 2.0);
  476. return env->ssao_intensity;
  477. }
  478. float RendererEnvironmentStorage::environment_get_ssao_power(RID p_env) const {
  479. Environment *env = environment_owner.get_or_null(p_env);
  480. ERR_FAIL_NULL_V(env, 1.5);
  481. return env->ssao_power;
  482. }
  483. float RendererEnvironmentStorage::environment_get_ssao_detail(RID p_env) const {
  484. Environment *env = environment_owner.get_or_null(p_env);
  485. ERR_FAIL_NULL_V(env, 0.5);
  486. return env->ssao_detail;
  487. }
  488. float RendererEnvironmentStorage::environment_get_ssao_horizon(RID p_env) const {
  489. Environment *env = environment_owner.get_or_null(p_env);
  490. ERR_FAIL_NULL_V(env, 0.06);
  491. return env->ssao_horizon;
  492. }
  493. float RendererEnvironmentStorage::environment_get_ssao_sharpness(RID p_env) const {
  494. Environment *env = environment_owner.get_or_null(p_env);
  495. ERR_FAIL_NULL_V(env, 0.98);
  496. return env->ssao_sharpness;
  497. }
  498. float RendererEnvironmentStorage::environment_get_ssao_direct_light_affect(RID p_env) const {
  499. Environment *env = environment_owner.get_or_null(p_env);
  500. ERR_FAIL_NULL_V(env, 0.0);
  501. return env->ssao_direct_light_affect;
  502. }
  503. float RendererEnvironmentStorage::environment_get_ssao_ao_channel_affect(RID p_env) const {
  504. Environment *env = environment_owner.get_or_null(p_env);
  505. ERR_FAIL_NULL_V(env, 0.0);
  506. return env->ssao_ao_channel_affect;
  507. }
  508. // SSIL
  509. void RendererEnvironmentStorage::environment_set_ssil(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_sharpness, float p_normal_rejection) {
  510. Environment *env = environment_owner.get_or_null(p_env);
  511. ERR_FAIL_NULL(env);
  512. #ifdef DEBUG_ENABLED
  513. if (OS::get_singleton()->get_current_rendering_method() != "forward_plus" && p_enable) {
  514. WARN_PRINT_ONCE_ED("Screen-space indirect lighting (SSIL) can only be enabled when using the Forward+ rendering backend.");
  515. }
  516. #endif
  517. env->ssil_enabled = p_enable;
  518. env->ssil_radius = p_radius;
  519. env->ssil_intensity = p_intensity;
  520. env->ssil_sharpness = p_sharpness;
  521. env->ssil_normal_rejection = p_normal_rejection;
  522. }
  523. bool RendererEnvironmentStorage::environment_get_ssil_enabled(RID p_env) const {
  524. Environment *env = environment_owner.get_or_null(p_env);
  525. ERR_FAIL_NULL_V(env, false);
  526. return env->ssil_enabled;
  527. }
  528. float RendererEnvironmentStorage::environment_get_ssil_radius(RID p_env) const {
  529. Environment *env = environment_owner.get_or_null(p_env);
  530. ERR_FAIL_NULL_V(env, 5.0);
  531. return env->ssil_radius;
  532. }
  533. float RendererEnvironmentStorage::environment_get_ssil_intensity(RID p_env) const {
  534. Environment *env = environment_owner.get_or_null(p_env);
  535. ERR_FAIL_NULL_V(env, 1.0);
  536. return env->ssil_intensity;
  537. }
  538. float RendererEnvironmentStorage::environment_get_ssil_sharpness(RID p_env) const {
  539. Environment *env = environment_owner.get_or_null(p_env);
  540. ERR_FAIL_NULL_V(env, 0.98);
  541. return env->ssil_sharpness;
  542. }
  543. float RendererEnvironmentStorage::environment_get_ssil_normal_rejection(RID p_env) const {
  544. Environment *env = environment_owner.get_or_null(p_env);
  545. ERR_FAIL_NULL_V(env, 1.0);
  546. return env->ssil_normal_rejection;
  547. }
  548. // SDFGI
  549. void RendererEnvironmentStorage::environment_set_sdfgi(RID p_env, bool p_enable, int p_cascades, float p_min_cell_size, RS::EnvironmentSDFGIYScale p_y_scale, bool p_use_occlusion, float p_bounce_feedback, bool p_read_sky, float p_energy, float p_normal_bias, float p_probe_bias) {
  550. Environment *env = environment_owner.get_or_null(p_env);
  551. ERR_FAIL_NULL(env);
  552. #ifdef DEBUG_ENABLED
  553. if (OS::get_singleton()->get_current_rendering_method() != "forward_plus" && p_enable) {
  554. WARN_PRINT_ONCE_ED("SDFGI can only be enabled when using the Forward+ rendering backend.");
  555. }
  556. #endif
  557. env->sdfgi_enabled = p_enable;
  558. env->sdfgi_cascades = p_cascades;
  559. env->sdfgi_min_cell_size = p_min_cell_size;
  560. env->sdfgi_use_occlusion = p_use_occlusion;
  561. env->sdfgi_bounce_feedback = p_bounce_feedback;
  562. env->sdfgi_read_sky_light = p_read_sky;
  563. env->sdfgi_energy = p_energy;
  564. env->sdfgi_normal_bias = p_normal_bias;
  565. env->sdfgi_probe_bias = p_probe_bias;
  566. env->sdfgi_y_scale = p_y_scale;
  567. }
  568. bool RendererEnvironmentStorage::environment_get_sdfgi_enabled(RID p_env) const {
  569. Environment *env = environment_owner.get_or_null(p_env);
  570. ERR_FAIL_NULL_V(env, false);
  571. return env->sdfgi_enabled;
  572. }
  573. int RendererEnvironmentStorage::environment_get_sdfgi_cascades(RID p_env) const {
  574. Environment *env = environment_owner.get_or_null(p_env);
  575. ERR_FAIL_NULL_V(env, 4);
  576. return env->sdfgi_cascades;
  577. }
  578. float RendererEnvironmentStorage::environment_get_sdfgi_min_cell_size(RID p_env) const {
  579. Environment *env = environment_owner.get_or_null(p_env);
  580. ERR_FAIL_NULL_V(env, 0.2);
  581. return env->sdfgi_min_cell_size;
  582. }
  583. bool RendererEnvironmentStorage::environment_get_sdfgi_use_occlusion(RID p_env) const {
  584. Environment *env = environment_owner.get_or_null(p_env);
  585. ERR_FAIL_NULL_V(env, false);
  586. return env->sdfgi_use_occlusion;
  587. }
  588. float RendererEnvironmentStorage::environment_get_sdfgi_bounce_feedback(RID p_env) const {
  589. Environment *env = environment_owner.get_or_null(p_env);
  590. ERR_FAIL_NULL_V(env, 0.5);
  591. return env->sdfgi_bounce_feedback;
  592. }
  593. bool RendererEnvironmentStorage::environment_get_sdfgi_read_sky_light(RID p_env) const {
  594. Environment *env = environment_owner.get_or_null(p_env);
  595. ERR_FAIL_NULL_V(env, true);
  596. return env->sdfgi_read_sky_light;
  597. }
  598. float RendererEnvironmentStorage::environment_get_sdfgi_energy(RID p_env) const {
  599. Environment *env = environment_owner.get_or_null(p_env);
  600. ERR_FAIL_NULL_V(env, 1.0);
  601. return env->sdfgi_energy;
  602. }
  603. float RendererEnvironmentStorage::environment_get_sdfgi_normal_bias(RID p_env) const {
  604. Environment *env = environment_owner.get_or_null(p_env);
  605. ERR_FAIL_NULL_V(env, 1.1);
  606. return env->sdfgi_normal_bias;
  607. }
  608. float RendererEnvironmentStorage::environment_get_sdfgi_probe_bias(RID p_env) const {
  609. Environment *env = environment_owner.get_or_null(p_env);
  610. ERR_FAIL_NULL_V(env, 1.1);
  611. return env->sdfgi_probe_bias;
  612. }
  613. RS::EnvironmentSDFGIYScale RendererEnvironmentStorage::environment_get_sdfgi_y_scale(RID p_env) const {
  614. Environment *env = environment_owner.get_or_null(p_env);
  615. ERR_FAIL_NULL_V(env, RS::ENV_SDFGI_Y_SCALE_75_PERCENT);
  616. return env->sdfgi_y_scale;
  617. }
  618. // Adjustments
  619. void RendererEnvironmentStorage::environment_set_adjustment(RID p_env, bool p_enable, float p_brightness, float p_contrast, float p_saturation, bool p_use_1d_color_correction, RID p_color_correction) {
  620. Environment *env = environment_owner.get_or_null(p_env);
  621. ERR_FAIL_NULL(env);
  622. #ifdef DEBUG_ENABLED
  623. if (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility" && p_enable) {
  624. WARN_PRINT_ONCE_ED("Adjustments are not supported when using the GL Compatibility backend yet. Support will be added in a future release.");
  625. }
  626. #endif
  627. env->adjustments_enabled = p_enable;
  628. env->adjustments_brightness = p_brightness;
  629. env->adjustments_contrast = p_contrast;
  630. env->adjustments_saturation = p_saturation;
  631. env->use_1d_color_correction = p_use_1d_color_correction;
  632. env->color_correction = p_color_correction;
  633. }
  634. bool RendererEnvironmentStorage::environment_get_adjustments_enabled(RID p_env) const {
  635. Environment *env = environment_owner.get_or_null(p_env);
  636. ERR_FAIL_NULL_V(env, false);
  637. return env->adjustments_enabled;
  638. }
  639. float RendererEnvironmentStorage::environment_get_adjustments_brightness(RID p_env) const {
  640. Environment *env = environment_owner.get_or_null(p_env);
  641. ERR_FAIL_NULL_V(env, 1.0);
  642. return env->adjustments_brightness;
  643. }
  644. float RendererEnvironmentStorage::environment_get_adjustments_contrast(RID p_env) const {
  645. Environment *env = environment_owner.get_or_null(p_env);
  646. ERR_FAIL_NULL_V(env, 1.0);
  647. return env->adjustments_contrast;
  648. }
  649. float RendererEnvironmentStorage::environment_get_adjustments_saturation(RID p_env) const {
  650. Environment *env = environment_owner.get_or_null(p_env);
  651. ERR_FAIL_NULL_V(env, 1.0);
  652. return env->adjustments_saturation;
  653. }
  654. bool RendererEnvironmentStorage::environment_get_use_1d_color_correction(RID p_env) const {
  655. Environment *env = environment_owner.get_or_null(p_env);
  656. ERR_FAIL_NULL_V(env, false);
  657. return env->use_1d_color_correction;
  658. }
  659. RID RendererEnvironmentStorage::environment_get_color_correction(RID p_env) const {
  660. Environment *env = environment_owner.get_or_null(p_env);
  661. ERR_FAIL_NULL_V(env, RID());
  662. return env->color_correction;
  663. }