environment.h 14 KB

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