environment.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. /*************************************************************************/
  2. /* environment.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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/resource.h"
  33. #include "scene/resources/sky.h"
  34. #include "scene/resources/texture.h"
  35. #include "servers/rendering_server.h"
  36. class Environment : public Resource {
  37. GDCLASS(Environment, Resource);
  38. public:
  39. enum BGMode {
  40. BG_CLEAR_COLOR,
  41. BG_COLOR,
  42. BG_SKY,
  43. BG_CANVAS,
  44. BG_KEEP,
  45. BG_CAMERA_FEED,
  46. BG_MAX
  47. };
  48. enum AmbientSource {
  49. AMBIENT_SOURCE_BG,
  50. AMBIENT_SOURCE_DISABLED,
  51. AMBIENT_SOURCE_COLOR,
  52. AMBIENT_SOURCE_SKY,
  53. };
  54. enum ReflectionSource {
  55. REFLECTION_SOURCE_BG,
  56. REFLECTION_SOURCE_DISABLED,
  57. REFLECTION_SOURCE_SKY,
  58. };
  59. enum ToneMapper {
  60. TONE_MAPPER_LINEAR,
  61. TONE_MAPPER_REINHARDT,
  62. TONE_MAPPER_FILMIC,
  63. TONE_MAPPER_ACES
  64. };
  65. enum GlowBlendMode {
  66. GLOW_BLEND_MODE_ADDITIVE,
  67. GLOW_BLEND_MODE_SCREEN,
  68. GLOW_BLEND_MODE_SOFTLIGHT,
  69. GLOW_BLEND_MODE_REPLACE,
  70. GLOW_BLEND_MODE_MIX,
  71. };
  72. enum SSAOBlur {
  73. SSAO_BLUR_DISABLED,
  74. SSAO_BLUR_1x1,
  75. SSAO_BLUR_2x2,
  76. SSAO_BLUR_3x3
  77. };
  78. private:
  79. RID environment;
  80. BGMode bg_mode = BG_CLEAR_COLOR;
  81. Ref<Sky> bg_sky;
  82. float bg_sky_custom_fov;
  83. Vector3 sky_rotation;
  84. Color bg_color;
  85. float bg_energy;
  86. int bg_canvas_max_layer;
  87. Color ambient_color;
  88. float ambient_energy;
  89. Color ao_color;
  90. float ambient_sky_contribution;
  91. int camera_feed_id;
  92. AmbientSource ambient_source;
  93. ReflectionSource reflection_source;
  94. ToneMapper tone_mapper = TONE_MAPPER_LINEAR;
  95. float tonemap_exposure;
  96. float tonemap_white;
  97. bool tonemap_auto_exposure;
  98. float tonemap_auto_exposure_max;
  99. float tonemap_auto_exposure_min;
  100. float tonemap_auto_exposure_speed;
  101. float tonemap_auto_exposure_grey;
  102. bool adjustment_enabled;
  103. float adjustment_contrast;
  104. float adjustment_saturation;
  105. float adjustment_brightness;
  106. Ref<Texture2D> adjustment_color_correction;
  107. bool ssr_enabled;
  108. int ssr_max_steps;
  109. float ssr_fade_in;
  110. float ssr_fade_out;
  111. float ssr_depth_tolerance;
  112. bool ssao_enabled;
  113. float ssao_radius;
  114. float ssao_intensity;
  115. float ssao_bias;
  116. float ssao_direct_light_affect;
  117. float ssao_ao_channel_affect;
  118. SSAOBlur ssao_blur = SSAO_BLUR_3x3;
  119. float ssao_edge_sharpness;
  120. bool glow_enabled;
  121. int glow_levels;
  122. float glow_intensity;
  123. float glow_strength;
  124. float glow_mix;
  125. float glow_bloom;
  126. GlowBlendMode glow_blend_mode = GLOW_BLEND_MODE_ADDITIVE;
  127. float glow_hdr_bleed_threshold;
  128. float glow_hdr_bleed_scale;
  129. float glow_hdr_luminance_cap;
  130. bool fog_enabled;
  131. Color fog_color;
  132. Color fog_sun_color;
  133. float fog_sun_amount;
  134. bool fog_depth_enabled;
  135. float fog_depth_begin;
  136. float fog_depth_end;
  137. float fog_depth_curve;
  138. bool fog_transmit_enabled;
  139. float fog_transmit_curve;
  140. bool fog_height_enabled;
  141. float fog_height_min;
  142. float fog_height_max;
  143. float fog_height_curve;
  144. protected:
  145. static void _bind_methods();
  146. virtual void _validate_property(PropertyInfo &property) const;
  147. #ifndef DISABLE_DEPRECATED
  148. // Kept for compatibility from 3.x to 4.0.
  149. bool _set(const StringName &p_name, const Variant &p_value);
  150. #endif
  151. public:
  152. void set_background(BGMode p_bg);
  153. void set_sky(const Ref<Sky> &p_sky);
  154. void set_sky_custom_fov(float p_scale);
  155. void set_sky_rotation(const Vector3 &p_rotation);
  156. void set_bg_color(const Color &p_color);
  157. void set_bg_energy(float p_energy);
  158. void set_canvas_max_layer(int p_max_layer);
  159. void set_ambient_light_color(const Color &p_color);
  160. void set_ambient_light_energy(float p_energy);
  161. void set_ambient_light_sky_contribution(float p_energy);
  162. void set_camera_feed_id(int p_camera_feed_id);
  163. void set_ambient_source(AmbientSource p_source);
  164. AmbientSource get_ambient_source() const;
  165. void set_reflection_source(ReflectionSource p_source);
  166. ReflectionSource get_reflection_source() const;
  167. BGMode get_background() const;
  168. Ref<Sky> get_sky() const;
  169. float get_sky_custom_fov() const;
  170. Vector3 get_sky_rotation() const;
  171. Color get_bg_color() const;
  172. float get_bg_energy() const;
  173. int get_canvas_max_layer() const;
  174. Color get_ambient_light_color() const;
  175. float get_ambient_light_energy() const;
  176. float get_ambient_light_sky_contribution() const;
  177. int get_camera_feed_id() const;
  178. void set_tonemapper(ToneMapper p_tone_mapper);
  179. ToneMapper get_tonemapper() const;
  180. void set_tonemap_exposure(float p_exposure);
  181. float get_tonemap_exposure() const;
  182. void set_tonemap_white(float p_white);
  183. float get_tonemap_white() const;
  184. void set_tonemap_auto_exposure(bool p_enabled);
  185. bool get_tonemap_auto_exposure() const;
  186. void set_tonemap_auto_exposure_max(float p_auto_exposure_max);
  187. float get_tonemap_auto_exposure_max() const;
  188. void set_tonemap_auto_exposure_min(float p_auto_exposure_min);
  189. float get_tonemap_auto_exposure_min() const;
  190. void set_tonemap_auto_exposure_speed(float p_auto_exposure_speed);
  191. float get_tonemap_auto_exposure_speed() const;
  192. void set_tonemap_auto_exposure_grey(float p_auto_exposure_grey);
  193. float get_tonemap_auto_exposure_grey() const;
  194. void set_adjustment_enable(bool p_enable);
  195. bool is_adjustment_enabled() const;
  196. void set_adjustment_brightness(float p_brightness);
  197. float get_adjustment_brightness() const;
  198. void set_adjustment_contrast(float p_contrast);
  199. float get_adjustment_contrast() const;
  200. void set_adjustment_saturation(float p_saturation);
  201. float get_adjustment_saturation() const;
  202. void set_adjustment_color_correction(const Ref<Texture2D> &p_ramp);
  203. Ref<Texture2D> get_adjustment_color_correction() const;
  204. void set_ssr_enabled(bool p_enable);
  205. bool is_ssr_enabled() const;
  206. void set_ssr_max_steps(int p_steps);
  207. int get_ssr_max_steps() const;
  208. void set_ssr_fade_in(float p_fade_in);
  209. float get_ssr_fade_in() const;
  210. void set_ssr_fade_out(float p_fade_out);
  211. float get_ssr_fade_out() const;
  212. void set_ssr_depth_tolerance(float p_depth_tolerance);
  213. float get_ssr_depth_tolerance() const;
  214. void set_ssao_enabled(bool p_enable);
  215. bool is_ssao_enabled() const;
  216. void set_ssao_radius(float p_radius);
  217. float get_ssao_radius() const;
  218. void set_ssao_intensity(float p_intensity);
  219. float get_ssao_intensity() const;
  220. void set_ssao_bias(float p_bias);
  221. float get_ssao_bias() const;
  222. void set_ssao_direct_light_affect(float p_direct_light_affect);
  223. float get_ssao_direct_light_affect() const;
  224. void set_ssao_ao_channel_affect(float p_ao_channel_affect);
  225. float get_ssao_ao_channel_affect() const;
  226. void set_ao_color(const Color &p_color);
  227. Color get_ao_color() const;
  228. void set_ssao_blur(SSAOBlur p_blur);
  229. SSAOBlur get_ssao_blur() const;
  230. void set_ssao_edge_sharpness(float p_edge_sharpness);
  231. float get_ssao_edge_sharpness() const;
  232. void set_glow_enabled(bool p_enabled);
  233. bool is_glow_enabled() const;
  234. void set_glow_level(int p_level, bool p_enabled);
  235. bool is_glow_level_enabled(int p_level) const;
  236. void set_glow_intensity(float p_intensity);
  237. float get_glow_intensity() const;
  238. void set_glow_strength(float p_strength);
  239. float get_glow_strength() const;
  240. void set_glow_mix(float p_mix);
  241. float get_glow_mix() const;
  242. void set_glow_bloom(float p_threshold);
  243. float get_glow_bloom() const;
  244. void set_glow_blend_mode(GlowBlendMode p_mode);
  245. GlowBlendMode get_glow_blend_mode() const;
  246. void set_glow_hdr_bleed_threshold(float p_threshold);
  247. float get_glow_hdr_bleed_threshold() const;
  248. void set_glow_hdr_luminance_cap(float p_amount);
  249. float get_glow_hdr_luminance_cap() const;
  250. void set_glow_hdr_bleed_scale(float p_scale);
  251. float get_glow_hdr_bleed_scale() const;
  252. void set_fog_enabled(bool p_enabled);
  253. bool is_fog_enabled() const;
  254. void set_fog_color(const Color &p_color);
  255. Color get_fog_color() const;
  256. void set_fog_sun_color(const Color &p_color);
  257. Color get_fog_sun_color() const;
  258. void set_fog_sun_amount(float p_amount);
  259. float get_fog_sun_amount() const;
  260. void set_fog_depth_enabled(bool p_enabled);
  261. bool is_fog_depth_enabled() const;
  262. void set_fog_depth_begin(float p_distance);
  263. float get_fog_depth_begin() const;
  264. void set_fog_depth_end(float p_distance);
  265. float get_fog_depth_end() const;
  266. void set_fog_depth_curve(float p_curve);
  267. float get_fog_depth_curve() const;
  268. void set_fog_transmit_enabled(bool p_enabled);
  269. bool is_fog_transmit_enabled() const;
  270. void set_fog_transmit_curve(float p_curve);
  271. float get_fog_transmit_curve() const;
  272. void set_fog_height_enabled(bool p_enabled);
  273. bool is_fog_height_enabled() const;
  274. void set_fog_height_min(float p_distance);
  275. float get_fog_height_min() const;
  276. void set_fog_height_max(float p_distance);
  277. float get_fog_height_max() const;
  278. void set_fog_height_curve(float p_distance);
  279. float get_fog_height_curve() const;
  280. virtual RID get_rid() const;
  281. Environment();
  282. ~Environment();
  283. };
  284. VARIANT_ENUM_CAST(Environment::BGMode)
  285. VARIANT_ENUM_CAST(Environment::AmbientSource)
  286. VARIANT_ENUM_CAST(Environment::ReflectionSource)
  287. VARIANT_ENUM_CAST(Environment::ToneMapper)
  288. VARIANT_ENUM_CAST(Environment::GlowBlendMode)
  289. VARIANT_ENUM_CAST(Environment::SSAOBlur)
  290. class CameraEffects : public Resource {
  291. GDCLASS(CameraEffects, Resource);
  292. private:
  293. RID camera_effects;
  294. bool dof_blur_far_enabled;
  295. float dof_blur_far_distance;
  296. float dof_blur_far_transition;
  297. bool dof_blur_near_enabled;
  298. float dof_blur_near_distance;
  299. float dof_blur_near_transition;
  300. float dof_blur_amount;
  301. bool override_exposure_enabled;
  302. float override_exposure;
  303. protected:
  304. static void _bind_methods();
  305. public:
  306. void set_dof_blur_far_enabled(bool p_enable);
  307. bool is_dof_blur_far_enabled() const;
  308. void set_dof_blur_far_distance(float p_distance);
  309. float get_dof_blur_far_distance() const;
  310. void set_dof_blur_far_transition(float p_distance);
  311. float get_dof_blur_far_transition() const;
  312. void set_dof_blur_near_enabled(bool p_enable);
  313. bool is_dof_blur_near_enabled() const;
  314. void set_dof_blur_near_distance(float p_distance);
  315. float get_dof_blur_near_distance() const;
  316. void set_dof_blur_near_transition(float p_distance);
  317. float get_dof_blur_near_transition() const;
  318. void set_dof_blur_amount(float p_amount);
  319. float get_dof_blur_amount() const;
  320. void set_override_exposure_enabled(bool p_enabled);
  321. bool is_override_exposure_enabled() const;
  322. void set_override_exposure(float p_exposure);
  323. float get_override_exposure() const;
  324. virtual RID get_rid() const;
  325. CameraEffects();
  326. ~CameraEffects();
  327. };
  328. #endif // ENVIRONMENT_H