environment.h 15 KB

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