environment.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. /**************************************************************************/
  2. /* environment.h */
  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. #ifndef ENVIRONMENT_H
  31. #define ENVIRONMENT_H
  32. #include "core/io/resource.h"
  33. #include "scene/resources/sky.h"
  34. #include "scene/resources/texture.h"
  35. class Environment : public Resource {
  36. GDCLASS(Environment, Resource);
  37. public:
  38. enum BGMode {
  39. BG_CLEAR_COLOR,
  40. BG_COLOR,
  41. BG_SKY,
  42. BG_CANVAS,
  43. BG_KEEP,
  44. BG_CAMERA_FEED,
  45. BG_MAX
  46. };
  47. enum AmbientSource {
  48. AMBIENT_SOURCE_BG,
  49. AMBIENT_SOURCE_DISABLED,
  50. AMBIENT_SOURCE_COLOR,
  51. AMBIENT_SOURCE_SKY,
  52. };
  53. enum ReflectionSource {
  54. REFLECTION_SOURCE_BG,
  55. REFLECTION_SOURCE_DISABLED,
  56. REFLECTION_SOURCE_SKY,
  57. };
  58. enum ToneMapper {
  59. TONE_MAPPER_LINEAR,
  60. TONE_MAPPER_REINHARDT,
  61. TONE_MAPPER_FILMIC,
  62. TONE_MAPPER_ACES,
  63. };
  64. enum SDFGIYScale {
  65. SDFGI_Y_SCALE_50_PERCENT,
  66. SDFGI_Y_SCALE_75_PERCENT,
  67. SDFGI_Y_SCALE_100_PERCENT,
  68. };
  69. enum FogMode {
  70. FOG_MODE_EXPONENTIAL,
  71. FOG_MODE_DEPTH,
  72. };
  73. enum GlowBlendMode {
  74. GLOW_BLEND_MODE_ADDITIVE,
  75. GLOW_BLEND_MODE_SCREEN,
  76. GLOW_BLEND_MODE_SOFTLIGHT,
  77. GLOW_BLEND_MODE_REPLACE,
  78. GLOW_BLEND_MODE_MIX,
  79. };
  80. private:
  81. RID environment;
  82. // Background
  83. BGMode bg_mode = BG_CLEAR_COLOR;
  84. Ref<Sky> bg_sky;
  85. float bg_sky_custom_fov = 0.0;
  86. Vector3 bg_sky_rotation;
  87. Color bg_color;
  88. int bg_canvas_max_layer = 0;
  89. int bg_camera_feed_id = 1;
  90. float bg_energy_multiplier = 1.0;
  91. float bg_intensity = 30000.0; // Measured in nits or candela/m^2
  92. void _update_bg_energy();
  93. // Ambient light
  94. Color ambient_color;
  95. AmbientSource ambient_source = AMBIENT_SOURCE_BG;
  96. float ambient_energy = 1.0;
  97. float ambient_sky_contribution = 1.0;
  98. ReflectionSource reflection_source = REFLECTION_SOURCE_BG;
  99. void _update_ambient_light();
  100. // Tonemap
  101. ToneMapper tone_mapper = TONE_MAPPER_LINEAR;
  102. float tonemap_exposure = 1.0;
  103. float tonemap_white = 1.0;
  104. void _update_tonemap();
  105. // SSR
  106. bool ssr_enabled = false;
  107. int ssr_max_steps = 64;
  108. float ssr_fade_in = 0.15;
  109. float ssr_fade_out = 2.0;
  110. float ssr_depth_tolerance = 0.2;
  111. void _update_ssr();
  112. // SSAO
  113. bool ssao_enabled = false;
  114. float ssao_radius = 1.0;
  115. float ssao_intensity = 2.0;
  116. float ssao_power = 1.5;
  117. float ssao_detail = 0.5;
  118. float ssao_horizon = 0.06;
  119. float ssao_sharpness = 0.98;
  120. float ssao_direct_light_affect = 0.0;
  121. float ssao_ao_channel_affect = 0.0;
  122. void _update_ssao();
  123. // SSIL
  124. bool ssil_enabled = false;
  125. float ssil_radius = 5.0;
  126. float ssil_intensity = 1.0;
  127. float ssil_sharpness = 0.98;
  128. float ssil_normal_rejection = 1.0;
  129. void _update_ssil();
  130. // SDFGI
  131. bool sdfgi_enabled = false;
  132. int sdfgi_cascades = 4;
  133. float sdfgi_min_cell_size = 0.2;
  134. SDFGIYScale sdfgi_y_scale = SDFGI_Y_SCALE_75_PERCENT;
  135. bool sdfgi_use_occlusion = false;
  136. float sdfgi_bounce_feedback = 0.5;
  137. bool sdfgi_read_sky_light = true;
  138. float sdfgi_energy = 1.0;
  139. float sdfgi_normal_bias = 1.1;
  140. float sdfgi_probe_bias = 1.1;
  141. void _update_sdfgi();
  142. // Glow
  143. bool glow_enabled = false;
  144. Vector<float> glow_levels;
  145. bool glow_normalize_levels = false;
  146. float glow_intensity = 0.8;
  147. float glow_strength = 1.0;
  148. float glow_mix = 0.05;
  149. float glow_bloom = 0.0;
  150. GlowBlendMode glow_blend_mode = GLOW_BLEND_MODE_SOFTLIGHT;
  151. float glow_hdr_bleed_threshold = 1.0;
  152. float glow_hdr_bleed_scale = 2.0;
  153. float glow_hdr_luminance_cap = 12.0;
  154. float glow_map_strength = 0.8f;
  155. Ref<Texture> glow_map;
  156. void _update_glow();
  157. // Fog
  158. bool fog_enabled = false;
  159. FogMode fog_mode = FOG_MODE_EXPONENTIAL;
  160. Color fog_light_color = Color(0.518, 0.553, 0.608);
  161. float fog_light_energy = 1.0;
  162. float fog_sun_scatter = 0.0;
  163. float fog_density = 0.01;
  164. float fog_height = 0.0;
  165. float fog_height_density = 0.0; //can be negative to invert effect
  166. float fog_aerial_perspective = 0.0;
  167. float fog_sky_affect = 1.0;
  168. void _update_fog();
  169. // Depth Fog
  170. float fog_depth_curve = 1.0;
  171. float fog_depth_begin = 10.0;
  172. float fog_depth_end = 100.0;
  173. void _update_fog_depth();
  174. // Volumetric Fog
  175. bool volumetric_fog_enabled = false;
  176. float volumetric_fog_density = 0.05;
  177. Color volumetric_fog_albedo = Color(1.0, 1.0, 1.0);
  178. Color volumetric_fog_emission = Color(0.0, 0.0, 0.0);
  179. float volumetric_fog_emission_energy = 1.0;
  180. float volumetric_fog_anisotropy = 0.2;
  181. float volumetric_fog_length = 64.0;
  182. float volumetric_fog_detail_spread = 2.0;
  183. float volumetric_fog_gi_inject = 1.0;
  184. float volumetric_fog_ambient_inject = 0.0;
  185. float volumetric_fog_sky_affect = 1.0;
  186. bool volumetric_fog_temporal_reproject = true;
  187. float volumetric_fog_temporal_reproject_amount = 0.9;
  188. void _update_volumetric_fog();
  189. // Adjustment
  190. bool adjustment_enabled = false;
  191. float adjustment_brightness = 1.0;
  192. float adjustment_contrast = 1.0;
  193. float adjustment_saturation = 1.0;
  194. bool use_1d_color_correction = true;
  195. Ref<Texture> adjustment_color_correction;
  196. void _update_adjustment();
  197. protected:
  198. static void _bind_methods();
  199. void _validate_property(PropertyInfo &p_property) const;
  200. #ifndef DISABLE_DEPRECATED
  201. // Kept for compatibility from 3.x to 4.0.
  202. bool _set(const StringName &p_name, const Variant &p_value);
  203. #endif
  204. public:
  205. virtual RID get_rid() const override;
  206. // Background
  207. void set_background(BGMode p_bg);
  208. BGMode get_background() const;
  209. void set_sky(const Ref<Sky> &p_sky);
  210. Ref<Sky> get_sky() const;
  211. void set_sky_custom_fov(float p_scale);
  212. float get_sky_custom_fov() const;
  213. void set_sky_rotation(const Vector3 &p_rotation);
  214. Vector3 get_sky_rotation() const;
  215. void set_bg_color(const Color &p_color);
  216. Color get_bg_color() const;
  217. void set_bg_energy_multiplier(float p_energy);
  218. float get_bg_energy_multiplier() const;
  219. void set_bg_intensity(float p_energy);
  220. float get_bg_intensity() const;
  221. void set_canvas_max_layer(int p_max_layer);
  222. int get_canvas_max_layer() const;
  223. void set_camera_feed_id(int p_id);
  224. int get_camera_feed_id() const;
  225. // Ambient light
  226. void set_ambient_light_color(const Color &p_color);
  227. Color get_ambient_light_color() const;
  228. void set_ambient_source(AmbientSource p_source);
  229. AmbientSource get_ambient_source() const;
  230. void set_ambient_light_energy(float p_energy);
  231. float get_ambient_light_energy() const;
  232. void set_ambient_light_sky_contribution(float p_ratio);
  233. float get_ambient_light_sky_contribution() const;
  234. void set_reflection_source(ReflectionSource p_source);
  235. ReflectionSource get_reflection_source() const;
  236. // Tonemap
  237. void set_tonemapper(ToneMapper p_tone_mapper);
  238. ToneMapper get_tonemapper() const;
  239. void set_tonemap_exposure(float p_exposure);
  240. float get_tonemap_exposure() const;
  241. void set_tonemap_white(float p_white);
  242. float get_tonemap_white() const;
  243. // SSR
  244. void set_ssr_enabled(bool p_enabled);
  245. bool is_ssr_enabled() const;
  246. void set_ssr_max_steps(int p_steps);
  247. int get_ssr_max_steps() const;
  248. void set_ssr_fade_in(float p_fade_in);
  249. float get_ssr_fade_in() const;
  250. void set_ssr_fade_out(float p_fade_out);
  251. float get_ssr_fade_out() const;
  252. void set_ssr_depth_tolerance(float p_depth_tolerance);
  253. float get_ssr_depth_tolerance() const;
  254. // SSAO
  255. void set_ssao_enabled(bool p_enabled);
  256. bool is_ssao_enabled() const;
  257. void set_ssao_radius(float p_radius);
  258. float get_ssao_radius() const;
  259. void set_ssao_intensity(float p_intensity);
  260. float get_ssao_intensity() const;
  261. void set_ssao_power(float p_power);
  262. float get_ssao_power() const;
  263. void set_ssao_detail(float p_detail);
  264. float get_ssao_detail() const;
  265. void set_ssao_horizon(float p_horizon);
  266. float get_ssao_horizon() const;
  267. void set_ssao_sharpness(float p_sharpness);
  268. float get_ssao_sharpness() const;
  269. void set_ssao_direct_light_affect(float p_direct_light_affect);
  270. float get_ssao_direct_light_affect() const;
  271. void set_ssao_ao_channel_affect(float p_ao_channel_affect);
  272. float get_ssao_ao_channel_affect() const;
  273. // SSIL
  274. void set_ssil_enabled(bool p_enabled);
  275. bool is_ssil_enabled() const;
  276. void set_ssil_radius(float p_radius);
  277. float get_ssil_radius() const;
  278. void set_ssil_intensity(float p_intensity);
  279. float get_ssil_intensity() const;
  280. void set_ssil_sharpness(float p_sharpness);
  281. float get_ssil_sharpness() const;
  282. void set_ssil_normal_rejection(float p_normal_rejection);
  283. float get_ssil_normal_rejection() const;
  284. // SDFGI
  285. void set_sdfgi_enabled(bool p_enabled);
  286. bool is_sdfgi_enabled() const;
  287. void set_sdfgi_cascades(int p_cascades);
  288. int get_sdfgi_cascades() const;
  289. void set_sdfgi_min_cell_size(float p_size);
  290. float get_sdfgi_min_cell_size() const;
  291. void set_sdfgi_max_distance(float p_distance);
  292. float get_sdfgi_max_distance() const;
  293. void set_sdfgi_cascade0_distance(float p_distance);
  294. float get_sdfgi_cascade0_distance() const;
  295. void set_sdfgi_y_scale(SDFGIYScale p_y_scale);
  296. SDFGIYScale get_sdfgi_y_scale() const;
  297. void set_sdfgi_use_occlusion(bool p_enabled);
  298. bool is_sdfgi_using_occlusion() const;
  299. void set_sdfgi_bounce_feedback(float p_amount);
  300. float get_sdfgi_bounce_feedback() const;
  301. void set_sdfgi_read_sky_light(bool p_enabled);
  302. bool is_sdfgi_reading_sky_light() const;
  303. void set_sdfgi_energy(float p_energy);
  304. float get_sdfgi_energy() const;
  305. void set_sdfgi_normal_bias(float p_bias);
  306. float get_sdfgi_normal_bias() const;
  307. void set_sdfgi_probe_bias(float p_bias);
  308. float get_sdfgi_probe_bias() const;
  309. // Glow
  310. void set_glow_enabled(bool p_enabled);
  311. bool is_glow_enabled() const;
  312. void set_glow_level(int p_level, float p_intensity);
  313. float get_glow_level(int p_level) const;
  314. void set_glow_normalized(bool p_normalized);
  315. bool is_glow_normalized() const;
  316. void set_glow_intensity(float p_intensity);
  317. float get_glow_intensity() const;
  318. void set_glow_strength(float p_strength);
  319. float get_glow_strength() const;
  320. void set_glow_mix(float p_mix);
  321. float get_glow_mix() const;
  322. void set_glow_bloom(float p_threshold);
  323. float get_glow_bloom() const;
  324. void set_glow_blend_mode(GlowBlendMode p_mode);
  325. GlowBlendMode get_glow_blend_mode() const;
  326. void set_glow_hdr_bleed_threshold(float p_threshold);
  327. float get_glow_hdr_bleed_threshold() const;
  328. void set_glow_hdr_bleed_scale(float p_scale);
  329. float get_glow_hdr_bleed_scale() const;
  330. void set_glow_hdr_luminance_cap(float p_amount);
  331. float get_glow_hdr_luminance_cap() const;
  332. void set_glow_map_strength(float p_strength);
  333. float get_glow_map_strength() const;
  334. void set_glow_map(Ref<Texture> p_glow_map);
  335. Ref<Texture> get_glow_map() const;
  336. // Fog
  337. void set_fog_enabled(bool p_enabled);
  338. bool is_fog_enabled() const;
  339. void set_fog_mode(FogMode p_mode);
  340. FogMode get_fog_mode() const;
  341. void set_fog_light_color(const Color &p_light_color);
  342. Color get_fog_light_color() const;
  343. void set_fog_light_energy(float p_amount);
  344. float get_fog_light_energy() const;
  345. void set_fog_sun_scatter(float p_amount);
  346. float get_fog_sun_scatter() const;
  347. void set_fog_density(float p_amount);
  348. float get_fog_density() const;
  349. void set_fog_height(float p_amount);
  350. float get_fog_height() const;
  351. void set_fog_height_density(float p_amount);
  352. float get_fog_height_density() const;
  353. void set_fog_aerial_perspective(float p_aerial_perspective);
  354. float get_fog_aerial_perspective() const;
  355. void set_fog_sky_affect(float p_sky_affect);
  356. float get_fog_sky_affect() const;
  357. // Depth Fog
  358. void set_fog_depth_curve(float p_curve);
  359. float get_fog_depth_curve() const;
  360. void set_fog_depth_begin(float p_begin);
  361. float get_fog_depth_begin() const;
  362. void set_fog_depth_end(float p_end);
  363. float get_fog_depth_end() const;
  364. // Volumetric Fog
  365. void set_volumetric_fog_enabled(bool p_enable);
  366. bool is_volumetric_fog_enabled() const;
  367. void set_volumetric_fog_density(float p_density);
  368. float get_volumetric_fog_density() const;
  369. void set_volumetric_fog_albedo(Color p_color);
  370. Color get_volumetric_fog_albedo() const;
  371. void set_volumetric_fog_emission(Color p_color);
  372. Color get_volumetric_fog_emission() const;
  373. void set_volumetric_fog_emission_energy(float p_begin);
  374. float get_volumetric_fog_emission_energy() const;
  375. void set_volumetric_fog_anisotropy(float p_anisotropy);
  376. float get_volumetric_fog_anisotropy() const;
  377. void set_volumetric_fog_length(float p_length);
  378. float get_volumetric_fog_length() const;
  379. void set_volumetric_fog_detail_spread(float p_detail_spread);
  380. float get_volumetric_fog_detail_spread() const;
  381. void set_volumetric_fog_gi_inject(float p_gi_inject);
  382. float get_volumetric_fog_gi_inject() const;
  383. void set_volumetric_fog_ambient_inject(float p_ambient_inject);
  384. float get_volumetric_fog_ambient_inject() const;
  385. void set_volumetric_fog_sky_affect(float p_sky_affect);
  386. float get_volumetric_fog_sky_affect() const;
  387. void set_volumetric_fog_temporal_reprojection_enabled(bool p_enable);
  388. bool is_volumetric_fog_temporal_reprojection_enabled() const;
  389. void set_volumetric_fog_temporal_reprojection_amount(float p_amount);
  390. float get_volumetric_fog_temporal_reprojection_amount() const;
  391. // Adjustment
  392. void set_adjustment_enabled(bool p_enabled);
  393. bool is_adjustment_enabled() const;
  394. void set_adjustment_brightness(float p_brightness);
  395. float get_adjustment_brightness() const;
  396. void set_adjustment_contrast(float p_contrast);
  397. float get_adjustment_contrast() const;
  398. void set_adjustment_saturation(float p_saturation);
  399. float get_adjustment_saturation() const;
  400. void set_adjustment_color_correction(Ref<Texture> p_color_correction);
  401. Ref<Texture> get_adjustment_color_correction() const;
  402. Environment();
  403. ~Environment();
  404. };
  405. VARIANT_ENUM_CAST(Environment::BGMode)
  406. VARIANT_ENUM_CAST(Environment::AmbientSource)
  407. VARIANT_ENUM_CAST(Environment::ReflectionSource)
  408. VARIANT_ENUM_CAST(Environment::ToneMapper)
  409. VARIANT_ENUM_CAST(Environment::SDFGIYScale)
  410. VARIANT_ENUM_CAST(Environment::GlowBlendMode)
  411. VARIANT_ENUM_CAST(Environment::FogMode)
  412. #endif // ENVIRONMENT_H